]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/AliHLTITSAgent.cxx
MC labels added for ITS tracks ?\127 ?\127?\127
[u/mrichter/AliRoot.git] / HLT / ITS / AliHLTITSAgent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 //  @file   AliHLTITSAgent.cxx
20 //  @author Matthias Richter
21 //  @date   25.08.2008
22 //  @brief  Agent of the libAliHLTITS library
23 //  @note
24
25 #include <cassert>
26 #include "AliHLTITSAgent.h"
27 #include "AliHLTConfiguration.h"
28 #include "AliHLTOUT.h"
29 #include "AliHLTDAQ.h"
30
31 // header files of library components
32 #include "AliHLTITSCompressRawDataSDDComponent.h"
33 #include "AliHLTITSSSDQARecPointsComponent.h"
34 #include "AliHLTITSQAComponent.h"
35 #include "AliHLTITSClusterFinderComponent.h"
36 #include "AliHLTITSClusterHistoComponent.h"
37 #include "AliHLTITSTrackerComponent.h"
38 #include "AliHLTITSVertexerSPDComponent.h"
39 #include "AliHLTITSDigitPublisherComponent.h"
40
41 // header file of the module preprocessor
42 // none at the moment
43
44 /** global instance for agent registration */
45 AliHLTITSAgent gAliHLTITSAgent;
46
47 /** ROOT macro for the implementation of ROOT specific class methods */
48 ClassImp(AliHLTITSAgent)
49
50 AliHLTITSAgent::AliHLTITSAgent()
51   :
52   AliHLTModuleAgent("ITS"),
53   fRawDataHandler(NULL)
54 {
55   // see header file for class documentation
56   // or
57   // refer to README to build package
58   // or
59   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 }
61
62 AliHLTITSAgent::~AliHLTITSAgent()
63 {
64   // see header file for class documentation
65 }
66
67 int AliHLTITSAgent::CreateConfigurations(AliHLTConfigurationHandler* handler,
68                                          AliRawReader* rawReader,
69                                          AliRunLoader* runloader) const
70 {
71   // see header file for class documentation
72   int iResult=0;
73   if (!handler) return -EINVAL;
74
75   ///////////////////////////////////////////////////////////////////////////////////////////////////
76   ///////////////////////////////////////////////////////////////////////////////////////////////////
77   //
78   // ITS tracking is currently only working on raw data
79   // to run on digits, a digit publisher needs to be implemented
80
81   TString trackerInput="";
82   TString vertexerSPDInput="";
83   if (rawReader || !runloader) {
84     // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
85     // Alireconstruction: indicated by runloader==NULL, run always on raw data
86
87     ///////////////////////////////////////////////////////////////////////////////////////////////////
88     //
89     // define the ITS cluster finder configurations
90     //
91
92     TString spdCF;
93     TString ssdCF;
94     TString sddCF;
95     
96     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSPD"), spdCF);
97     handler->CreateConfiguration("ITS-SPD-CF","BlockFilter",spdCF.Data(),"");
98
99     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSDD"), sddCF);
100     handler->CreateConfiguration("ITS-SDD-CF","BlockFilter",sddCF.Data(),"");
101
102     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSSD"), ssdCF);
103     handler->CreateConfiguration("ITS-SSD-CF","BlockFilter",ssdCF.Data(),"");
104
105
106     ///////////////////////////////////////////////////////////////////////////////////////////////////
107     //
108     // define the SPD vertexer Z input
109     //
110     vertexerSPDInput="ITS-SPD-CF";
111
112     ///////////////////////////////////////////////////////////////////////////////////////////////////
113     //
114     // define the ITS tracker input
115     //
116     trackerInput="ITS-SPD-CF ITS-SDD-CF ITS-SSD-CF";
117   }
118   else if (runloader && !rawReader) {
119     // indicates AliSimulation with no RawReader available -> run on digits
120
121     ///////////////////////////////////////////////////////////////////////////////////////////////////
122     //
123     // define the Digit Publisher and ITS cluster finder configuration
124     //
125     handler->CreateConfiguration("DigitPublisher","AliLoaderPublisher",NULL,"-loader ITSLoader -datatype 'ALITREED' 'ITS '");
126     handler->CreateConfiguration("DigitClusterFinder","ITSClusterFinderDigits","DigitPublisher","");
127     
128     ///////////////////////////////////////////////////////////////////////////////////////////////////
129     //
130     // define the SPD vertexer Z input.
131     //
132     // Can not run on Digit ClusterFinder. Wrong inputtype. And wrong input data.
133     // If this is fixed in the VertexerSPD it needs to implement the data type
134     // handling for the ITS digits and ignore the input from the SDD and SSD
135     //vertexerSPDInput="DigitClusterFinder";
136     
137     ///////////////////////////////////////////////////////////////////////////////////////////////////
138     //
139     // define the ITS tracker input
140     //
141     // Currently there is a seg fault in the TTree access from the DigitClusterFinder
142     // needs first to be investigated
143     trackerInput="DigitClusterFinder";
144   }
145
146   ///////////////////////////////////////////////////////////////////////////////////////////////////
147   //
148   // define the SPD vertexer Z configuration
149   //
150   if (!vertexerSPDInput.IsNull()) {
151     handler->CreateConfiguration("ITS-SPD-vertexer","ITSVertexerSPD", vertexerSPDInput, "");
152   }
153
154   ///////////////////////////////////////////////////////////////////////////////////////////////////
155   //
156   // define the ITS tracker configuration
157   //
158   if (!trackerInput.IsNull()) {
159     if (handler->FindConfiguration("TPC-globalmerger")) {
160       // add the TPC tracking if available
161       trackerInput+=" TPC-globalmerger";
162     }
163     if (handler->FindConfiguration("TPC-mcTrackMarker")) {
164       // add the TPC tracking if available
165       trackerInput+=" TPC-mcTrackMarker";
166     }
167     handler->CreateConfiguration("ITS-tracker","ITSTracker",trackerInput.Data(),"");
168   }
169
170   return 0;
171 }
172
173 const char* AliHLTITSAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
174                                                        AliRunLoader* runloader) const
175 {
176   // see header file for class documentation
177   if (runloader) {
178     // reconstruction chains for AliRoot simulation
179     // Note: run loader is only available while running embedded into
180     // AliRoot simulation
181
182     // the chain is just defined and can be used as input for subsequent
183     // components
184     //return "ITS-tracker";
185   }
186
187   return "";
188 }
189
190 const char* AliHLTITSAgent::GetRequiredComponentLibraries() const
191 {
192   // see header file for class documentation
193   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so";
194 }
195
196 int AliHLTITSAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
197 {
198   // see header file for class documentation
199   assert(pHandler);
200   if (!pHandler) return -EINVAL;
201   pHandler->AddComponent(new AliHLTITSCompressRawDataSDDComponent);
202   pHandler->AddComponent(new AliHLTITSSSDQARecPointsComponent);
203   pHandler->AddComponent(new AliHLTITSQAComponent);
204   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSPD));
205   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSDD));
206   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSSD));
207   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderDigits));
208   pHandler->AddComponent(new AliHLTITSClusterHistoComponent);
209   pHandler->AddComponent(new AliHLTITSTrackerComponent);
210   pHandler->AddComponent(new AliHLTITSVertexerSPDComponent);
211   pHandler->AddComponent(new AliHLTITSDigitPublisherComponent);
212
213   return 0;
214 }
215
216 AliHLTModulePreprocessor* AliHLTITSAgent::GetPreprocessor()
217 {
218   // see header file for class documentation
219   return NULL;
220 }
221
222 int AliHLTITSAgent::GetHandlerDescription(AliHLTComponentDataType dt,
223                                              AliHLTUInt32_t spec,
224                                              AliHLTOUTHandlerDesc& desc) const
225 {
226   // see header file for class documentation
227
228   // Handlers for ITS raw data. Even though there are 3 detectors
229   // everything is handled in one module library and one HLTOUT handler.
230   // This assumes that the data blocks are sent with data type
231   // {DDL_RAW :ISDD} and the bit set in the specification corresponding.
232   // to detector DDL id.
233   // An HLTOUT handler is implemented to extract the equipment id from
234   // the specification.
235   // Note: Future versions of the framework will provide a default handler
236   // class with that functionality.
237   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
238       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
239       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
240               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
241       return 1;
242   }
243   return 0;
244 }
245
246 AliHLTOUTHandler* AliHLTITSAgent::GetOutputHandler(AliHLTComponentDataType dt,
247                                                    AliHLTUInt32_t /*spec*/)
248 {
249   // see header file for class documentation
250   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
251     // use the default handler
252     if (!fRawDataHandler) {
253       fRawDataHandler=new AliHLTOUTSDDRawDataHandler;
254     }
255     return fRawDataHandler;
256   }
257   return NULL;
258 }
259
260 int AliHLTITSAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
261 {
262   // see header file for class documentation
263   if (pInstance==NULL) return -EINVAL;
264
265   if (pInstance==fRawDataHandler) {
266     delete fRawDataHandler;
267     fRawDataHandler=NULL;
268     return 0;
269   }
270
271   delete pInstance;
272   return 0;
273 }
274
275 int AliHLTITSAgent::AliHLTOUTSDDRawDataHandler::ProcessData(AliHLTOUT* pData)
276 {
277   // see header file for class documentation
278   if (!pData) return -EINVAL;
279   static int errorCount=0;
280   const int maxErrorCount=10;
281   AliHLTComponentDataType dt=kAliHLTVoidDataType;
282   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
283   int iResult=pData->GetDataBlockDescription(dt, spec);
284   if (iResult>=0) {
285     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
286       int ddlOffset=256;//AliDAQ::DdlIDOffset("ITSSDD");
287       int numberOfDDLs=24;//AliDAQ::NumberOfDdls("ITSSDD");
288       int ddlNo=0;
289       for (;ddlNo<32 && ddlNo<numberOfDDLs; ddlNo++) {
290         if (spec&(0x1<<ddlNo)) break;
291       }
292       if (ddlNo>=32 || ddlNo>=numberOfDDLs) {
293         HLTError("invalid specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
294         iResult=-ENODEV;
295       } else if (spec^(0x1<<ddlNo)) {
296         iResult=-EEXIST;
297         HLTError("multiple links set in specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
298       } else {
299         iResult=ddlOffset+ddlNo;
300       }
301     } else {
302       if (errorCount++<10) {
303         HLTError("wrong data type: expecting %s, got %s; %s",
304                  AliHLTComponent::DataType2Text(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD).c_str(),
305                  AliHLTComponent::DataType2Text(dt).c_str(),
306                    errorCount==maxErrorCount?"suppressing further error messages":"");
307       }
308       iResult=-EFAULT;
309     }
310   }
311   return iResult;
312 }
313
314 int AliHLTITSAgent::CreateCFConfigurations(AliHLTConfigurationHandler* pHandler, int detectorId, TString& output) const
315 {
316   // see header file for class documentation
317   if (!pHandler) return -EINVAL;
318
319   ///////////////////////////////////////////////////////////////////////////////////////////////////
320   //
321   // define the ITS cluster finder components
322   //
323     
324   //The spec starts from 0x1 in SPD, SDD and SSD. So 0x1 is ddl 0 for SPD, 0x10 is ddl 1, and so on
325   //in SDD 0x1 is ddl 256, 0x10 is ddl 257, and so on. This means that the spec has to be set to 0x1 
326   //before the loops over the clusterfinder
327
328   TString idString=AliHLTDAQ::DetectorName(detectorId);
329   if (idString.CompareTo("ITSSPD") &&
330       idString.CompareTo("ITSSDD") &&
331       idString.CompareTo("ITSSSD")) {
332     HLTError("invalid detector id %d does not describe any ITS detector", detectorId);
333     return -ENOENT;
334   }
335
336   int minddl=AliHLTDAQ::DdlIDOffset(detectorId);
337   int maxddl=minddl+AliHLTDAQ::NumberOfDdls(detectorId)-1;
338   int spec=0x1;
339   int ddlno=0;
340
341   bool bOneCFperDDL=false;
342   TString origin=idString; origin.ReplaceAll("ITS", "I");
343   TString cfBase=idString; cfBase+="_CF";
344   TString componentId=idString; componentId.ReplaceAll("ITS", "ITSClusterFinder");
345   TString cfinput, cf;
346   for(ddlno=minddl;ddlno<=maxddl;ddlno++){  
347     TString arg, publisher;
348  
349     // the HLT origin defines are 4 chars: ISPD, ISSD, ISDD respectively
350     arg.Form("-minid %d -datatype 'DDL_RAW ' '%s' -dataspec 0x%08x",ddlno, origin.Data(), spec);
351     if (CheckFilter(kHLTLogDebug)) arg+=" -verbose";
352     publisher.Form("ITS-DP_%d", ddlno);
353     pHandler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
354
355     if (cfinput.Length()>0) cfinput+=" ";
356     cfinput+=publisher;
357
358     if (bOneCFperDDL) {
359     cf.Form("%s_%d",cfBase.Data(), ddlno);
360     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), publisher.Data(), "");
361
362     if (output.Length()>0) output+=" ";
363     output+=cf;
364     }
365
366     spec=spec<<1;
367   }
368
369   if (!bOneCFperDDL) {
370     cf.Form("%s",cfBase.Data());
371     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), cfinput.Data(), "");
372
373     if (output.Length()>0) output+=" ";
374     output+=cf;
375   }
376   
377   return 0;
378 }