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