]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/AliHLTITSAgent.cxx
integration of ITS SAP tracker to HLT chain
[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 "AliHLTOUT.h"
28 #include "AliHLTDAQ.h"
29
30 // header files of library components
31 #include "AliHLTITSCompressRawDataSDDComponent.h"
32 #include "AliHLTITSSSDQARecPointsComponent.h"
33 #include "AliHLTITSQAComponent.h"
34 #include "AliHLTITSClusterFinderComponent.h"
35 #include "AliHLTITSClusterHistoComponent.h"
36 #include "AliHLTITSTrackerComponent.h"
37 #include "AliHLTITSSAPTrackerComponent.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 trackerSAPInput="";
83   TString vertexerSPDInput="";
84   if (rawReader || !runloader) {
85     // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
86     // Alireconstruction: indicated by runloader==NULL, run always on raw data
87
88     ///////////////////////////////////////////////////////////////////////////////////////////////////
89     //
90     // define the ITS cluster finder configurations
91     //
92
93     TString spdCF;
94     TString ssdCF;
95     TString sddCF;
96     
97     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSPD"), spdCF);
98     handler->CreateConfiguration("ITS-SPD-CF","BlockFilter",spdCF.Data(),"");
99
100     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSDD"), sddCF);
101     handler->CreateConfiguration("ITS-SDD-CF","BlockFilter",sddCF.Data(),"");
102
103     iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSSD"), ssdCF);
104     handler->CreateConfiguration("ITS-SSD-CF","BlockFilter",ssdCF.Data(),"");
105
106
107     ///////////////////////////////////////////////////////////////////////////////////////////////////
108     //
109     // define the SPD vertexer Z input
110     //
111     vertexerSPDInput="ITS-SPD-CF";
112
113     ///////////////////////////////////////////////////////////////////////////////////////////////////
114     //
115     // define the ITS tracker input
116     //
117     trackerInput="ITS-SPD-CF ITS-SDD-CF ITS-SSD-CF";
118     trackerSAPInput="ITS-SPD-CF ITS-SDD-CF ITS-SSD-CF";
119   }
120   else if (runloader && !rawReader) {
121     // indicates AliSimulation with no RawReader available -> run on digits
122
123     ///////////////////////////////////////////////////////////////////////////////////////////////////
124     //
125     // define the Digit Publisher and ITS cluster finder configuration
126     //
127     handler->CreateConfiguration("DigitPublisher","AliLoaderPublisher",NULL,"-loader ITSLoader -datatype 'ALITREED' 'ITS '");
128     handler->CreateConfiguration("DigitClusterFinder","ITSClusterFinderDigits","DigitPublisher","");
129     
130     ///////////////////////////////////////////////////////////////////////////////////////////////////
131     //
132     // define the SPD vertexer Z input.
133     //
134     // Can not run on Digit ClusterFinder. Wrong inputtype. And wrong input data.
135     // If this is fixed in the VertexerSPD it needs to implement the data type
136     // handling for the ITS digits and ignore the input from the SDD and SSD
137     //vertexerSPDInput="DigitClusterFinder";
138     
139     ///////////////////////////////////////////////////////////////////////////////////////////////////
140     //
141     // define the ITS tracker input
142     //
143     // Currently there is a seg fault in the TTree access from the DigitClusterFinder
144     // needs first to be investigated
145     trackerInput="DigitClusterFinder";
146     trackerSAPInput="DigitClusterFinder";
147     vertexerSPDInput="DigitClusterFinder";
148   }
149
150   ///////////////////////////////////////////////////////////////////////////////////////////////////
151   //
152   // define the SPD vertexer Z configuration
153   //
154   if (!vertexerSPDInput.IsNull()) {
155     handler->CreateConfiguration("ITS-SPD-vertexer","ITSVertexerSPD", vertexerSPDInput, "");
156   }
157
158   ///////////////////////////////////////////////////////////////////////////////////////////////////
159   //
160   // define the ITS tracker configuration
161   //
162   if (!trackerInput.IsNull()) {
163     if (handler->FindConfiguration("TPC-globalmerger")) {
164       // add the TPC tracking if available
165       trackerInput+=" TPC-globalmerger";
166     }
167     if (handler->FindConfiguration("TPC-mcTrackMarker")) {
168       // add the TPC tracking if available
169       trackerInput+=" TPC-mcTrackMarker";
170     }
171     handler->CreateConfiguration("ITS-tracker","ITSTracker",trackerInput.Data(),"");
172   }
173   
174   if( !trackerSAPInput.IsNull() ) trackerSAPInput+=" ";
175   trackerSAPInput+="ITS-SPD-vertexer";
176
177   handler->CreateConfiguration("ITS-SAPtracker","ITSSAPTracker",trackerSAPInput.Data(),"");
178
179   return iResult;
180 }
181
182 const char* AliHLTITSAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
183                                                        AliRunLoader* runloader) const
184 {
185   // see header file for class documentation
186   if (runloader) {
187     // reconstruction chains for AliRoot simulation
188     // Note: run loader is only available while running embedded into
189     // AliRoot simulation
190
191     // the chain is just defined and can be used as input for subsequent
192     // components
193     //return "ITS-tracker";
194   }
195
196   return "";
197 }
198
199 const char* AliHLTITSAgent::GetRequiredComponentLibraries() const
200 {
201   // see header file for class documentation
202   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so";
203 }
204
205 int AliHLTITSAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
206 {
207   // see header file for class documentation
208   assert(pHandler);
209   if (!pHandler) return -EINVAL;
210   pHandler->AddComponent(new AliHLTITSCompressRawDataSDDComponent);
211   pHandler->AddComponent(new AliHLTITSSSDQARecPointsComponent);
212   pHandler->AddComponent(new AliHLTITSQAComponent);
213   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSPD));
214   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSDD));
215   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSSD));
216   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderDigits));
217   pHandler->AddComponent(new AliHLTITSClusterHistoComponent);
218   pHandler->AddComponent(new AliHLTITSTrackerComponent);
219   pHandler->AddComponent(new AliHLTITSSAPTrackerComponent);
220   pHandler->AddComponent(new AliHLTITSVertexerSPDComponent);
221   pHandler->AddComponent(new AliHLTITSDigitPublisherComponent);
222
223   return 0;
224 }
225
226 AliHLTModulePreprocessor* AliHLTITSAgent::GetPreprocessor()
227 {
228   // see header file for class documentation
229   return NULL;
230 }
231
232 int AliHLTITSAgent::GetHandlerDescription(AliHLTComponentDataType dt,
233                                              AliHLTUInt32_t spec,
234                                              AliHLTOUTHandlerDesc& desc) const
235 {
236   // see header file for class documentation
237
238   // Handlers for ITS raw data. Even though there are 3 detectors
239   // everything is handled in one module library and one HLTOUT handler.
240   // This assumes that the data blocks are sent with data type
241   // {DDL_RAW :ISDD} and the bit set in the specification corresponding.
242   // to detector DDL id.
243   // An HLTOUT handler is implemented to extract the equipment id from
244   // the specification.
245   // Note: Future versions of the framework will provide a default handler
246   // class with that functionality.
247   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
248       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
249       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
250               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
251       return 1;
252   }
253   return 0;
254 }
255
256 AliHLTOUTHandler* AliHLTITSAgent::GetOutputHandler(AliHLTComponentDataType dt,
257                                                    AliHLTUInt32_t /*spec*/)
258 {
259   // see header file for class documentation
260   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
261     // use the default handler
262     if (!fRawDataHandler) {
263       fRawDataHandler=new AliHLTOUTSDDRawDataHandler;
264     }
265     return fRawDataHandler;
266   }
267   return NULL;
268 }
269
270 int AliHLTITSAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
271 {
272   // see header file for class documentation
273   if (pInstance==NULL) return -EINVAL;
274
275   if (pInstance==fRawDataHandler) {
276     delete fRawDataHandler;
277     fRawDataHandler=NULL;
278     return 0;
279   }
280
281   delete pInstance;
282   return 0;
283 }
284
285 int AliHLTITSAgent::AliHLTOUTSDDRawDataHandler::ProcessData(AliHLTOUT* pData)
286 {
287   // see header file for class documentation
288   if (!pData) return -EINVAL;
289   static int errorCount=0;
290   const int maxErrorCount=10;
291   AliHLTComponentDataType dt=kAliHLTVoidDataType;
292   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
293   int iResult=pData->GetDataBlockDescription(dt, spec);
294   if (iResult>=0) {
295     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
296       int ddlOffset=256;//AliDAQ::DdlIDOffset("ITSSDD");
297       int numberOfDDLs=24;//AliDAQ::NumberOfDdls("ITSSDD");
298       int ddlNo=0;
299       for (;ddlNo<32 && ddlNo<numberOfDDLs; ddlNo++) {
300         if (spec&(0x1<<ddlNo)) break;
301       }
302       if (ddlNo>=32 || ddlNo>=numberOfDDLs) {
303         HLTError("invalid specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
304         iResult=-ENODEV;
305       } else if (spec^(0x1<<ddlNo)) {
306         iResult=-EEXIST;
307         HLTError("multiple links set in specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
308       } else {
309         iResult=ddlOffset+ddlNo;
310       }
311     } else {
312       if (errorCount++<10) {
313         HLTError("wrong data type: expecting %s, got %s; %s",
314                  AliHLTComponent::DataType2Text(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD).c_str(),
315                  AliHLTComponent::DataType2Text(dt).c_str(),
316                    errorCount==maxErrorCount?"suppressing further error messages":"");
317       }
318       iResult=-EFAULT;
319     }
320   }
321   return iResult;
322 }
323
324 int AliHLTITSAgent::CreateCFConfigurations(AliHLTConfigurationHandler* pHandler, int detectorId, TString& output) const
325 {
326   // see header file for class documentation
327   if (!pHandler) return -EINVAL;
328
329   ///////////////////////////////////////////////////////////////////////////////////////////////////
330   //
331   // define the ITS cluster finder components
332   //
333     
334   //The spec starts from 0x1 in SPD, SDD and SSD. So 0x1 is ddl 0 for SPD, 0x10 is ddl 1, and so on
335   //in SDD 0x1 is ddl 256, 0x10 is ddl 257, and so on. This means that the spec has to be set to 0x1 
336   //before the loops over the clusterfinder
337
338   TString idString=AliHLTDAQ::DetectorName(detectorId);
339   if (idString.CompareTo("ITSSPD") &&
340       idString.CompareTo("ITSSDD") &&
341       idString.CompareTo("ITSSSD")) {
342     HLTError("invalid detector id %d does not describe any ITS detector", detectorId);
343     return -ENOENT;
344   }
345
346   int minddl=AliHLTDAQ::DdlIDOffset(detectorId);
347   int maxddl=minddl+AliHLTDAQ::NumberOfDdls(detectorId)-1;
348   int spec=0x1;
349   int ddlno=0;
350
351   // this is a simple switch for experimenting with different configurations
352   // it's supposed to be false for normal compilation
353   bool bOneCFperDDL=false;
354   TString origin=idString; origin.ReplaceAll("ITS", "I");
355   TString cfBase=idString; cfBase+="_CF";
356   TString componentId=idString; componentId.ReplaceAll("ITS", "ITSClusterFinder");
357   TString cfinput, cf;
358   for(ddlno=minddl;ddlno<=maxddl;ddlno++){  
359     TString arg, publisher;
360  
361     // the HLT origin defines are 4 chars: ISPD, ISSD, ISDD respectively
362     arg.Form("-minid %d -datatype 'DDL_RAW ' '%s' -dataspec 0x%08x",ddlno, origin.Data(), spec);
363     if (CheckFilter(kHLTLogDebug)) arg+=" -verbose";
364     publisher.Form("ITS-DP_%d", ddlno);
365     pHandler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
366
367     if (cfinput.Length()>0) cfinput+=" ";
368     cfinput+=publisher;
369
370     if (bOneCFperDDL) {
371     cf.Form("%s_%d",cfBase.Data(), ddlno);
372     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), publisher.Data(), "");
373
374     if (output.Length()>0) output+=" ";
375     output+=cf;
376     }
377
378     spec=spec<<1;
379   }
380
381   if (!bOneCFperDDL) {
382     cf.Form("%s",cfBase.Data());
383     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), cfinput.Data(), "");
384
385     if (output.Length()>0) output+=" ";
386     output+=cf;
387   }
388   
389   return 0;
390 }