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