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