]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
TPCdEdx component has been created.
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCAgent.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   AliHLTTPCAgent.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Agent of the libAliHLTTPC library
23 */
24
25 #include "AliHLTTPCAgent.h"
26 #include "AliHLTConfiguration.h"
27 #include "AliHLTTPCDefinitions.h"
28 #include "AliHLTOUT.h"
29 #include "AliHLTOUTHandlerChain.h"
30 #include "AliRunLoader.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBEntry.h"
33 #include "AliTPCParam.h"
34
35 /** global instance for agent registration */
36 AliHLTTPCAgent gAliHLTTPCAgent;
37
38 // component headers
39 #include "AliHLTTPCRunStatisticsProducerComponent.h"
40 #include "AliHLTTPCEventStatisticsProducerComponent.h"
41 #include "AliHLTTPCCompModelInflaterComponent.h"
42 #include "AliHLTTPCCompModelDeflaterComponent.h"
43 #include "AliHLTTPCCompModelDeconverterComponent.h"
44 #include "AliHLTTPCCompModelConverterComponent.h"
45 #include "AliHLTTPCCompDumpComponent.h"
46 //#include "AliHLTTPCCalibCEComponent.h"
47 //#include "AliHLTTPCCalibPulserComponent.h"
48 //#include "AliHLTTPCCalibPedestalComponent.h"
49 #include "AliHLTTPCCAInputDataCompressorComponent.h"
50 #include "AliHLTTPCCATrackerComponent.h"
51 #include "AliHLTTPCTrackMCMarkerComponent.h"
52 #include "AliHLTTPCCAGlobalMergerComponent.h"
53 #include "AliHLTTPCdEdxComponent.h"
54 #include "AliHLTTPCGlobalMergerComponent.h"
55 #include "AliHLTTPCSliceTrackerComponent.h"
56 #include "AliHLTTPCVertexFinderComponent.h"
57 #include "AliHLTTPCClusterFinderComponent.h"
58 #include "AliHLTTPCRawDataUnpackerComponent.h"
59 #include "AliHLTTPCDigitPublisherComponent.h"
60 #include "AliHLTTPCZeroSuppressionComponent.h"
61 #include "AliHLTTPCDigitDumpComponent.h"
62 #include "AliHLTTPCClusterDumpComponent.h"
63 #include "AliHLTTPCEsdWriterComponent.h"
64 #include "AliHLTTPCOfflineClustererComponent.h"
65 #include "AliHLTTPCOfflineTrackerComponent.h"
66 #include "AliHLTTPCOfflineTrackerCalibComponent.h"
67 #include "AliHLTTPCOfflineCalibrationComponent.h" // to be added to the calibration library agent
68 #include "AliHLTTPCClusterHistoComponent.h"
69 #include "AliHLTTPCNoiseMapComponent.h"
70 #include "AliHLTTPCHistogramHandlerComponent.h"
71 //#include "AliHLTTPCCalibTracksComponent.h"
72 #include "AliHLTTPCTrackHistoComponent.h"
73 #include "AliHLTTPCTrackDumpComponent.h"
74 #include "AliHLTTPCHWCFDataReverterComponent.h"
75 #include "AliHLTTPCHWClusterTransformComponent.h"
76 // #include "AliHLTTPCCalibSeedMakerComponent.h"
77 // #include "AliHLTTPCCalibTimeComponent.h"
78 // #include "AliHLTTPCCalibTimeGainComponent.h"
79 // #include "AliHLTTPCCalibrationComponent.h"
80
81 /** ROOT macro for the implementation of ROOT specific class methods */
82 ClassImp(AliHLTTPCAgent)
83
84 AliHLTTPCAgent::AliHLTTPCAgent()
85   :
86   AliHLTModuleAgent("TPC"),
87   fRawDataHandler(NULL),
88   fTracksegsDataHandler(NULL)
89 {
90   // see header file for class documentation
91   // or
92   // refer to README to build package
93   // or
94   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
95 }
96
97 AliHLTTPCAgent::~AliHLTTPCAgent()
98 {
99   // see header file for class documentation
100 }
101
102 int AliHLTTPCAgent::CreateConfigurations(AliHLTConfigurationHandler* handler,
103                                          AliRawReader* rawReader,
104                                          AliRunLoader* runloader) const
105 {
106   // see header file for class documentation
107   if (handler) {
108     const char* cdbEntry="TPC/Calib/Parameters";
109     AliCDBManager* pMan=AliCDBManager::Instance();
110     AliTPCParam* pTPCParam=NULL;
111     if (pMan) {
112       AliCDBEntry *pEntry = pMan->Get(cdbEntry);
113       if (pEntry && 
114           pEntry->GetObject() &&
115           (pTPCParam=dynamic_cast<AliTPCParam*>(pEntry->GetObject()))) {
116       } else {
117         HLTWarning("can not load AliTPCParam from CDB entry %s", cdbEntry);
118       }
119     }
120
121     // This the tracking configuration for the full TPC
122     // - 216 clusterfinders (1 per partition)
123     // - 36 slice trackers
124     // - one global merger
125     // - the esd converter
126     // The ESD is shipped embedded into a TTree
127     int iMinSlice=0; 
128     int iMaxSlice=35;
129     int iMinPart=0;
130     int iMaxPart=5;
131     TString mergerInput;
132     TString sinkClusterInput;
133     for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
134       TString trackerInput;
135       for (int part=iMinPart; part<=iMaxPart; part++) {
136         TString arg, publisher, cf;
137
138         // digit publisher components
139         publisher.Form("TPC-DP_%02d_%d", slice, part);
140         if (rawReader || !runloader) {
141           // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
142           // Alireconstruction: indicated by runloader==NULL, run always on raw data
143           int ddlno=768;
144           if (part>1) ddlno+=72+4*slice+(part-2);
145           else ddlno+=2*slice+part;
146           arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -silent", ddlno, slice, slice, part, part);
147           handler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
148         } else {
149           arg.Form("-slice %d -partition %d", slice, part);
150           handler->CreateConfiguration(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());
151         }
152
153         // cluster finder components
154         cf.Form("TPC-CF_%02d_%d", slice, part);
155         arg="";
156         if (pTPCParam) {
157           arg+=" -timebins "; arg+=pTPCParam->GetMaxTBin()+1;
158         }
159         if (!rawReader && runloader) {
160           arg+=" -do-mc";
161           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
162         } else {
163 #ifndef HAVE_NOT_ALTRORAWSTREAMV3
164           handler->CreateConfiguration(cf.Data(), "TPCClusterFinder32Bit", publisher.Data(), arg.Data());
165 #else
166           // using the AltroDecoder if the official V3 decoder is not
167           // available in the offline code
168           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderDecoder", publisher.Data(), arg.Data());
169 #endif 
170         }
171         if (trackerInput.Length()>0) trackerInput+=" ";
172         trackerInput+=cf;
173         if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
174         sinkClusterInput+=cf;
175       }
176       TString tracker;
177       // tracker finder components
178       tracker.Form("TPC-TR_%02d", slice);
179       handler->CreateConfiguration(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
180
181       if (mergerInput.Length()>0) mergerInput+=" ";
182       mergerInput+=tracker;
183
184     }
185
186     // GlobalMerger component
187     handler->CreateConfiguration("TPC-globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
188
189     // the esd converter configuration
190     TString converterInput="TPC-globalmerger";
191     if (!rawReader && runloader) {
192       // propagate cluster info to the esd converter in order to fill the MC information
193       handler->CreateConfiguration("TPC-clustermc-info", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");  
194       handler->CreateConfiguration("TPC-mcTrackMarker","TPCTrackMCMarker","TPC-globalmerger TPC-clustermc-info","" );
195       converterInput+=" ";
196       converterInput+="TPC-mcTrackMarker";
197     }
198     handler->CreateConfiguration("TPC-esd-converter", "TPCEsdConverter"   , converterInput.Data(), "");
199
200     // cluster dump collection
201     handler->CreateConfiguration("TPC-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");
202
203     /////////////////////////////////////////////////////////////////////////////////////
204     //
205     // a kChain HLTOUT configuration for processing of {'TRAKSEGS':'TPC '} data blocks
206     // collects the data blocks, merges the tracks and produces an ESD object
207
208     // publisher component
209     handler->CreateConfiguration("TPC-hltout-tracksegs-publisher", "AliHLTOUTPublisher"   , NULL, "");
210
211     // GlobalMerger component
212     handler->CreateConfiguration("TPC-hltout-tracksegs-merger", "TPCGlobalMerger", "TPC-hltout-tracksegs-publisher", "");
213
214     // the esd converter configuration
215     handler->CreateConfiguration("TPC-hltout-tracksegs-esd-converter", "TPCEsdConverter", "TPC-hltout-tracksegs-merger", "");
216
217     /////////////////////////////////////////////////////////////////////////////////////
218     //
219     // a kChain HLTOUT configuration for processing of {'TRACKS  ':'TPC '} data blocks
220     // produces an ESD object from the track structure
221
222     // publisher component
223     handler->CreateConfiguration("TPC-hltout-tracks-publisher", "AliHLTOUTPublisher"   , NULL, "");
224
225     // the esd converter configuration
226     handler->CreateConfiguration("TPC-hltout-tracks-esd-converter", "TPCEsdConverter", "TPC-hltout-tracks-publisher", "");
227   }
228   return 0;
229 }
230
231 const char* AliHLTTPCAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
232                                                     AliRunLoader* runloader) const
233 {
234   // see header file for class documentation
235   if (runloader) {
236     // reconstruction chains for AliRoot simulation
237     // Note: run loader is only available while running embedded into
238     // AliRoot simulation
239     //if (runloader->GetLoader("TPCLoader") != NULL)
240       //return "TPC-esd-converter TPC-clusters";
241       return "TPC-clusters";
242   }
243   return NULL;
244 }
245
246 const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
247 {
248   // see header file for class documentation
249
250   // actually, the TPC library has dependencies to Util and RCU
251   // so the two has to be loaded anyhow before we get here
252   //return "libAliHLTUtil.so libAliHLTRCU.so";
253   return "libAliHLTUtil.so";
254 }
255
256 int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
257 {
258   // see header file for class documentation
259   if (!pHandler) return -EINVAL;
260
261   pHandler->AddComponent(new AliHLTTPCRunStatisticsProducerComponent);
262   pHandler->AddComponent(new AliHLTTPCEventStatisticsProducerComponent);
263 //   pHandler->AddComponent(new AliHLTTPCCalibCEComponent);
264 //   pHandler->AddComponent(new AliHLTTPCCalibPulserComponent);
265 //   pHandler->AddComponent(new AliHLTTPCCalibPedestalComponent);
266   pHandler->AddComponent(new AliHLTTPCCompModelInflaterComponent);
267   pHandler->AddComponent(new AliHLTTPCCompModelDeflaterComponent);
268   pHandler->AddComponent(new AliHLTTPCCompModelDeconverterComponent);
269   pHandler->AddComponent(new AliHLTTPCCompModelConverterComponent);
270   pHandler->AddComponent(new AliHLTTPCCompDumpComponent);
271   pHandler->AddComponent(new AliHLTTPCCAInputDataCompressorComponent);
272   pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
273   pHandler->AddComponent(new AliHLTTPCCAGlobalMergerComponent);
274   pHandler->AddComponent(new AliHLTTPCTrackMCMarkerComponent);
275   pHandler->AddComponent(new AliHLTTPCGlobalMergerComponent);
276   pHandler->AddComponent(new AliHLTTPCdEdxComponent);
277   pHandler->AddComponent(new AliHLTTPCSliceTrackerComponent);
278   pHandler->AddComponent(new AliHLTTPCVertexFinderComponent);
279   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderPacked));
280   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderUnpacked));
281   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderDecoder));
282   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinder32Bit));
283   pHandler->AddComponent(new AliHLTTPCRawDataUnpackerComponent);
284   pHandler->AddComponent(new AliHLTTPCDigitPublisherComponent);
285   pHandler->AddComponent(new AliHLTTPCZeroSuppressionComponent);
286   pHandler->AddComponent(new AliHLTTPCDigitDumpComponent);
287   pHandler->AddComponent(new AliHLTTPCClusterDumpComponent);
288   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliWriter);
289   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliConverter);
290   pHandler->AddComponent(new AliHLTTPCOfflineClustererComponent);
291   pHandler->AddComponent(new AliHLTTPCOfflineTrackerComponent);
292   pHandler->AddComponent(new AliHLTTPCOfflineTrackerCalibComponent);
293   pHandler->AddComponent(new AliHLTTPCOfflineCalibrationComponent);
294   pHandler->AddComponent(new AliHLTTPCClusterHistoComponent);
295   pHandler->AddComponent(new AliHLTTPCNoiseMapComponent);
296   pHandler->AddComponent(new AliHLTTPCHistogramHandlerComponent);
297   //pHandler->AddComponent(new AliHLTTPCCalibTracksComponent);
298   pHandler->AddComponent(new AliHLTTPCTrackHistoComponent);
299   pHandler->AddComponent(new AliHLTTPCTrackDumpComponent);
300   pHandler->AddComponent(new AliHLTTPCHWCFDataReverterComponent);
301   pHandler->AddComponent(new AliHLTTPCHWClusterTransformComponent);
302 //   pHandler->AddComponent(new AliHLTTPCCalibSeedMakerComponent);
303 //   pHandler->AddComponent(new AliHLTTPCCalibTimeComponent);
304 //   pHandler->AddComponent(new AliHLTTPCCalibTimeGainComponent);
305 //   pHandler->AddComponent(new AliHLTTPCCalibrationComponent);
306
307   return 0;
308 }
309
310 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
311                                           AliHLTUInt32_t spec,
312                                           AliHLTOUTHandlerDesc& desc) const
313 {
314   // see header file for class documentation
315
316   // raw data blocks to be fed into offline reconstruction
317   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
318     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
319     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
320     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
321         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
322       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
323       return 1;
324     } else {
325       HLTWarning("handler can not process merged data from multiple ddls:"
326                  " min slice %d, max slice %d, min part %d, max part %d",
327                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
328                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
329       return 0;
330     }
331   }
332
333   // dump for {'CLUSTERS':'TPC '} currently not used any more
334   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
335       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
336       return 1;
337   }
338
339   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
340   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
341       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
342       return 1;
343   }
344
345   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
346   // there is only one data block
347   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
348       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
349       return 1;
350   }
351   return 0;
352 }
353
354 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
355                                                    AliHLTUInt32_t /*spec*/)
356 {
357   // see header file for class documentation
358
359   // raw data blocks to be fed into offline reconstruction
360   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
361     if (!fRawDataHandler) {
362       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
363     }
364     return fRawDataHandler;
365   }
366
367   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
368   // in a kChain HLTOUT handler
369   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
370     if (fTracksegsDataHandler==NULL)
371       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
372     return fTracksegsDataHandler;
373   }
374
375   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
376   // there is only one data block
377   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
378     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
379   }
380
381   return NULL;
382 }
383
384 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
385 {
386   // see header file for class documentation
387   if (pInstance==NULL) return -EINVAL;
388
389   if (pInstance==fRawDataHandler) {
390     delete fRawDataHandler;
391     fRawDataHandler=NULL;
392   }
393
394   if (pInstance==fTracksegsDataHandler) {
395     delete fTracksegsDataHandler;
396     fTracksegsDataHandler=NULL;
397   }
398   return 0;
399 }
400
401 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
402 {
403   // see header file for class documentation
404 }
405
406 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
407 {
408   // see header file for class documentation
409 }
410
411 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
412 {
413   // see header file for class documentation
414   if (!pData) return -EINVAL;
415   AliHLTComponentDataType dt=kAliHLTVoidDataType;
416   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
417   int iResult=pData->GetDataBlockDescription(dt, spec);
418   if (iResult>=0) {
419     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
420     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
421     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
422         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
423       iResult=768;
424       if (part>1) iResult+=72+4*slice+(part-2);
425       else iResult+=2*slice+part;
426     } else {
427       HLTError("handler can not process merged data from multiple ddls:"
428                " min slice %d, max slice %d, min part %d, max part %d",
429                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
430                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
431       iResult=-EBADMSG;
432     }
433   }
434   return iResult;
435 }