]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/AliHLTITSAgent.cxx
19d4dd2c2580cecc7599df626252dc9e7ac10487
[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     handler->CreateConfiguration("ITS-tracker","ITSTracker",trackerInput.Data(),"");
164   }
165
166   return 0;
167 }
168
169 const char* AliHLTITSAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
170                                                        AliRunLoader* runloader) const
171 {
172   // see header file for class documentation
173   if (runloader) {
174     // reconstruction chains for AliRoot simulation
175     // Note: run loader is only available while running embedded into
176     // AliRoot simulation
177
178     // the chain is just defined and can be used as input for subsequent
179     // components
180     //return "ITS-tracker";
181   }
182
183   return "";
184 }
185
186 const char* AliHLTITSAgent::GetRequiredComponentLibraries() const
187 {
188   // see header file for class documentation
189   return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so";
190 }
191
192 int AliHLTITSAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
193 {
194   // see header file for class documentation
195   assert(pHandler);
196   if (!pHandler) return -EINVAL;
197   pHandler->AddComponent(new AliHLTITSCompressRawDataSDDComponent);
198   pHandler->AddComponent(new AliHLTITSSSDQARecPointsComponent);
199   pHandler->AddComponent(new AliHLTITSQAComponent);
200   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSPD));
201   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSDD));
202   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSSD));
203   pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderDigits));
204   pHandler->AddComponent(new AliHLTITSClusterHistoComponent);
205   pHandler->AddComponent(new AliHLTITSTrackerComponent);
206   pHandler->AddComponent(new AliHLTITSVertexerSPDComponent);
207   pHandler->AddComponent(new AliHLTITSDigitPublisherComponent);
208
209   return 0;
210 }
211
212 AliHLTModulePreprocessor* AliHLTITSAgent::GetPreprocessor()
213 {
214   // see header file for class documentation
215   return NULL;
216 }
217
218 int AliHLTITSAgent::GetHandlerDescription(AliHLTComponentDataType dt,
219                                              AliHLTUInt32_t spec,
220                                              AliHLTOUTHandlerDesc& desc) const
221 {
222   // see header file for class documentation
223
224   // Handlers for ITS raw data. Even though there are 3 detectors
225   // everything is handled in one module library and one HLTOUT handler.
226   // This assumes that the data blocks are sent with data type
227   // {DDL_RAW :ISDD} and the bit set in the specification corresponding.
228   // to detector DDL id.
229   // An HLTOUT handler is implemented to extract the equipment id from
230   // the specification.
231   // Note: Future versions of the framework will provide a default handler
232   // class with that functionality.
233   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
234       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
235       HLTInfo("module %s handles data block type %s specification %d (0x%x)", 
236               GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
237       return 1;
238   }
239   return 0;
240 }
241
242 AliHLTOUTHandler* AliHLTITSAgent::GetOutputHandler(AliHLTComponentDataType dt,
243                                                    AliHLTUInt32_t /*spec*/)
244 {
245   // see header file for class documentation
246   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
247     // use the default handler
248     if (!fRawDataHandler) {
249       fRawDataHandler=new AliHLTOUTSDDRawDataHandler;
250     }
251     return fRawDataHandler;
252   }
253   return NULL;
254 }
255
256 int AliHLTITSAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
257 {
258   // see header file for class documentation
259   if (pInstance==NULL) return -EINVAL;
260
261   if (pInstance==fRawDataHandler) {
262     delete fRawDataHandler;
263     fRawDataHandler=NULL;
264     return 0;
265   }
266
267   delete pInstance;
268   return 0;
269 }
270
271 int AliHLTITSAgent::AliHLTOUTSDDRawDataHandler::ProcessData(AliHLTOUT* pData)
272 {
273   // see header file for class documentation
274   if (!pData) return -EINVAL;
275   static int errorCount=0;
276   const int maxErrorCount=10;
277   AliHLTComponentDataType dt=kAliHLTVoidDataType;
278   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
279   int iResult=pData->GetDataBlockDescription(dt, spec);
280   if (iResult>=0) {
281     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
282       int ddlOffset=256;//AliDAQ::DdlIDOffset("ITSSDD");
283       int numberOfDDLs=24;//AliDAQ::NumberOfDdls("ITSSDD");
284       int ddlNo=0;
285       for (;ddlNo<32 && ddlNo<numberOfDDLs; ddlNo++) {
286         if (spec&(0x1<<ddlNo)) break;
287       }
288       if (ddlNo>=32 || ddlNo>=numberOfDDLs) {
289         HLTError("invalid specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
290         iResult=-ENODEV;
291       } else if (spec^(0x1<<ddlNo)) {
292         iResult=-EEXIST;
293         HLTError("multiple links set in specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
294       } else {
295         iResult=ddlOffset+ddlNo;
296       }
297     } else {
298       if (errorCount++<10) {
299         HLTError("wrong data type: expecting %s, got %s; %s",
300                  AliHLTComponent::DataType2Text(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD).c_str(),
301                  AliHLTComponent::DataType2Text(dt).c_str(),
302                    errorCount==maxErrorCount?"suppressing further error messages":"");
303       }
304       iResult=-EFAULT;
305     }
306   }
307   return iResult;
308 }
309
310 int AliHLTITSAgent::CreateCFConfigurations(AliHLTConfigurationHandler* pHandler, int detectorId, TString& output) const
311 {
312   // see header file for class documentation
313   if (!pHandler) return -EINVAL;
314
315   ///////////////////////////////////////////////////////////////////////////////////////////////////
316   //
317   // define the ITS cluster finder components
318   //
319     
320   //The spec starts from 0x1 in SPD, SDD and SSD. So 0x1 is ddl 0 for SPD, 0x10 is ddl 1, and so on
321   //in SDD 0x1 is ddl 256, 0x10 is ddl 257, and so on. This means that the spec has to be set to 0x1 
322   //before the loops over the clusterfinder
323
324   TString idString=AliHLTDAQ::DetectorName(detectorId);
325   if (idString.CompareTo("ITSSPD") &&
326       idString.CompareTo("ITSSDD") &&
327       idString.CompareTo("ITSSSD")) {
328     HLTError("invalid detector id %d does not describe any ITS detector", detectorId);
329     return -ENOENT;
330   }
331
332   int minddl=AliHLTDAQ::DdlIDOffset(detectorId);
333   int maxddl=minddl+AliHLTDAQ::NumberOfDdls(detectorId)-1;
334   int spec=0x1;
335   int ddlno=0;
336
337   bool bOneCFperDDL=false;
338   TString origin=idString; origin.ReplaceAll("ITS", "I");
339   TString cfBase=idString; cfBase+="_CF";
340   TString componentId=idString; componentId.ReplaceAll("ITS", "ITSClusterFinder");
341   TString cfinput, cf;
342   for(ddlno=minddl;ddlno<=maxddl;ddlno++){  
343     TString arg, publisher;
344  
345     // the HLT origin defines are 4 chars: ISPD, ISSD, ISDD respectively
346     arg.Form("-minid %d -datatype 'DDL_RAW ' '%s' -dataspec 0x%08x",ddlno, origin.Data(), spec);
347     if (CheckFilter(kHLTLogDebug)) arg+=" -verbose";
348     publisher.Form("ITS-DP_%d", ddlno);
349     pHandler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
350
351     if (cfinput.Length()>0) cfinput+=" ";
352     cfinput+=publisher;
353
354     if (bOneCFperDDL) {
355     cf.Form("%s_%d",cfBase.Data(), ddlno);
356     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), publisher.Data(), "");
357
358     if (output.Length()>0) output+=" ";
359     output+=cf;
360     }
361
362     spec=spec<<1;
363   }
364
365   if (!bOneCFperDDL) {
366     cf.Form("%s",cfBase.Data());
367     pHandler->CreateConfiguration(cf.Data(), componentId.Data(), cfinput.Data(), "");
368
369     if (output.Length()>0) output+=" ";
370     output+=cf;
371   }
372   
373   return 0;
374 }