]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
0150a7fc696dba6e79105ea0e1503bf0581dd969
[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 "AliHLTTPCDefinitions.h"
27 #include "AliHLTOUT.h"
28 #include "AliHLTOUTHandlerChain.h"
29 #include "AliRunLoader.h"
30 #include "AliCDBManager.h"
31 #include "AliCDBEntry.h"
32 #include "AliTPCParam.h"
33
34 /** global instance for agent registration */
35 AliHLTTPCAgent gAliHLTTPCAgent;
36
37 // component headers
38 #include "AliHLTTPCRunStatisticsProducerComponent.h"
39 #include "AliHLTTPCEventStatisticsProducerComponent.h"
40 #include "AliHLTTPCCompModelInflaterComponent.h"
41 #include "AliHLTTPCCompModelDeflaterComponent.h"
42 #include "AliHLTTPCCompModelDeconverterComponent.h"
43 #include "AliHLTTPCCompModelConverterComponent.h"
44 #include "AliHLTTPCCompDumpComponent.h"
45 //#include "AliHLTTPCCalibCEComponent.h"
46 //#include "AliHLTTPCCalibPulserComponent.h"
47 //#include "AliHLTTPCCalibPedestalComponent.h"
48 #include "AliHLTTPCCAInputDataCompressorComponent.h"
49 #include "AliHLTTPCCATrackerComponent.h"
50 #include "AliHLTTPCCATrackerOutputConverter.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 "AliHLTTPCCFComparisonComponent.h"
77 // #include "AliHLTTPCCalibSeedMakerComponent.h"
78 // #include "AliHLTTPCCalibTimeComponent.h"
79 // #include "AliHLTTPCCalibTimeGainComponent.h"
80 // #include "AliHLTTPCCalibrationComponent.h"
81 #include "AliHLTTPCDataCheckerComponent.h"
82
83 /** ROOT macro for the implementation of ROOT specific class methods */
84 ClassImp(AliHLTTPCAgent)
85
86 AliHLTTPCAgent::AliHLTTPCAgent()
87   : AliHLTModuleAgent("TPC")
88   , fRawDataHandler(NULL)
89   , fTracksegsDataHandler(NULL)
90   , fClustersDataHandler(NULL)
91 {
92   // see header file for class documentation
93   // or
94   // refer to README to build package
95   // or
96   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
97 }
98
99 AliHLTTPCAgent::~AliHLTTPCAgent()
100 {
101   // see header file for class documentation
102 }
103
104 int AliHLTTPCAgent::CreateConfigurations(AliHLTConfigurationHandler* handler,
105                                          AliRawReader* rawReader,
106                                          AliRunLoader* runloader) const
107 {
108   // see header file for class documentation
109   if (handler) {
110
111     // This the tracking configuration for the full TPC
112     // - 216 clusterfinders (1 per partition)
113     // - 36 slice trackers
114     // - one global merger
115     // - the esd converter
116     // The ESD is shipped embedded into a TTree
117     int iMinSlice=0; 
118     int iMaxSlice=35;
119     int iMinPart=0;
120     int iMaxPart=5;
121     TString mergerInput;
122     TString sinkClusterInput;
123     for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
124       TString trackerInput;
125       for (int part=iMinPart; part<=iMaxPart; part++) {
126         TString arg, publisher, cf;
127
128         // digit publisher components
129         publisher.Form("TPC-DP_%02d_%d", slice, part);
130         if (rawReader || !runloader) {
131           // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
132           // Alireconstruction: indicated by runloader==NULL, run always on raw data
133           int ddlno=768;
134           if (part>1) ddlno+=72+4*slice+(part-2);
135           else ddlno+=2*slice+part;
136           arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -silent", ddlno, slice, slice, part, part);
137           handler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
138         } else {
139           arg.Form("-slice %d -partition %d", slice, part);
140           handler->CreateConfiguration(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());
141         }
142
143         // cluster finder components
144         cf.Form("TPC-CF_%02d_%d", slice, part);
145         arg="-release-memory";
146         if (!rawReader && runloader) {
147           arg+=" -do-mc";
148           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
149         } else {
150 #ifndef HAVE_NOT_ALTRORAWSTREAMV3
151           handler->CreateConfiguration(cf.Data(), "TPCClusterFinder32Bit", publisher.Data(),arg.Data());
152 #else
153           // using the AltroDecoder if the official V3 decoder is not
154           // available in the offline code
155           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderDecoder", publisher.Data(), arg.Data());
156 #endif 
157         }
158         if (trackerInput.Length()>0) trackerInput+=" ";
159         trackerInput+=cf;
160         if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
161         sinkClusterInput+=cf;
162       }
163       TString tracker;
164       // tracker finder components
165       tracker.Form("TPC-TR_%02d", slice);
166       handler->CreateConfiguration(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
167
168       if (mergerInput.Length()>0) mergerInput+=" ";
169       mergerInput+=tracker;
170
171     }
172
173     // GlobalMerger component
174     handler->CreateConfiguration("TPC-globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
175
176     // the esd converter configuration
177     TString converterInput="TPC-globalmerger";
178     if (!rawReader && runloader) {
179       // propagate cluster info to the esd converter in order to fill the MC information
180       handler->CreateConfiguration("TPC-clustermc-info", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");  
181       handler->CreateConfiguration("TPC-mcTrackMarker","TPCTrackMCMarker","TPC-globalmerger TPC-clustermc-info","" );
182       converterInput+=" ";
183       converterInput+="TPC-mcTrackMarker";
184     }
185     handler->CreateConfiguration("TPC-esd-converter", "TPCEsdConverter"   , converterInput.Data(), "");
186
187     // cluster dump collection
188     handler->CreateConfiguration("TPC-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");
189
190     /////////////////////////////////////////////////////////////////////////////////////
191     //
192     // a kChain HLTOUT configuration for processing of {'TRAKSEGS':'TPC '} data blocks
193     // collects the data blocks, merges the tracks and produces an ESD object
194
195     // publisher component
196     handler->CreateConfiguration("TPC-hltout-tracksegs-publisher", "AliHLTOUTPublisher"   , NULL, "");
197
198     // GlobalMerger component
199     handler->CreateConfiguration("TPC-hltout-tracksegs-merger", "TPCGlobalMerger", "TPC-hltout-tracksegs-publisher", "");
200
201     // the esd converter configuration
202     handler->CreateConfiguration("TPC-hltout-tracksegs-esd-converter", "TPCEsdConverter", "TPC-hltout-tracksegs-merger", "");
203
204     /////////////////////////////////////////////////////////////////////////////////////
205     //
206     // a kChain HLTOUT configuration for processing of {'TRACKS  ':'TPC '} data blocks
207     // produces an ESD object from the track structure
208
209     // publisher component
210     handler->CreateConfiguration("TPC-hltout-tracks-publisher", "AliHLTOUTPublisher"   , NULL, "");
211
212     // the esd converter configuration
213     handler->CreateConfiguration("TPC-hltout-tracks-esd-converter", "TPCEsdConverter", "TPC-hltout-tracks-publisher", "");
214
215     /////////////////////////////////////////////////////////////////////////////////////
216     //
217     // a kChain HLTOUT configuration for processing of {'CLUSTERS':'TPC '} data blocks
218     // stores the blocks in file HLT.TPC.Clusters.root in HOMER format
219
220     // publisher component
221     handler->CreateConfiguration("TPC-hltout-cluster-publisher", "AliHLTOUTPublisher"   , NULL, "");
222
223     // the HLTOUT component collects the blocks and stores the file
224     handler->CreateConfiguration("TPC-hltout-cluster-dump", "HLTOUT", "TPC-hltout-cluster-publisher", "-digitfile HLT.TPC.Clusters.root -rawout=off -links 2");
225   }
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 AliHLTTPCCATrackerOutputConverter);
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 AliHLTTPCCFComparisonComponent);
303 //   pHandler->AddComponent(new AliHLTTPCCalibSeedMakerComponent);
304 //   pHandler->AddComponent(new AliHLTTPCCalibTimeComponent);
305 //   pHandler->AddComponent(new AliHLTTPCCalibTimeGainComponent);
306 //   pHandler->AddComponent(new AliHLTTPCCalibrationComponent);
307   pHandler->AddComponent(new AliHLTTPCDataCheckerComponent);
308
309   return 0;
310 }
311
312 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
313                                           AliHLTUInt32_t spec,
314                                           AliHLTOUTHandlerDesc& desc) const
315 {
316   // see header file for class documentation
317
318   // raw data blocks to be fed into offline reconstruction
319   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
320     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
321     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
322     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
323         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
324       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
325       return 1;
326     } else {
327       HLTWarning("handler can not process merged data from multiple ddls:"
328                  " min slice %d, max slice %d, min part %d, max part %d",
329                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
330                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
331       return 0;
332     }
333   }
334
335   // dump for {'CLUSTERS':'TPC '} blocks stored in a 'digit' file
336   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
337       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
338       return 1;
339   }
340
341   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
342   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
343       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
344       return 1;
345   }
346
347   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
348   // there is only one data block
349   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
350       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
351       return 1;
352   }
353   return 0;
354 }
355
356 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
357                                                    AliHLTUInt32_t /*spec*/)
358 {
359   // see header file for class documentation
360
361   // raw data blocks to be fed into offline reconstruction
362   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
363     if (!fRawDataHandler) {
364       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
365     }
366     return fRawDataHandler;
367   }
368
369   // dump for {'CLUSTERS':'TPC '}, stored in a file HLT.TPC.Clusters.root in HOMER format
370   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
371     if (fClustersDataHandler==NULL)
372       fClustersDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-cluster-dump libHLTsim.so libAliHLTUtil.so");
373     return fClustersDataHandler;
374   }
375
376   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
377   // in a kChain HLTOUT handler
378   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
379     if (fTracksegsDataHandler==NULL)
380       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
381     return fTracksegsDataHandler;
382   }
383
384   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
385   // there is only one data block
386   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
387     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
388   }
389
390   return NULL;
391 }
392
393 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
394 {
395   // see header file for class documentation
396   if (pInstance==NULL) return -EINVAL;
397
398   if (pInstance==fRawDataHandler) {
399     delete fRawDataHandler;
400     fRawDataHandler=NULL;
401   }
402
403   if (pInstance==fTracksegsDataHandler) {
404     delete fTracksegsDataHandler;
405     fTracksegsDataHandler=NULL;
406   }
407
408   if (pInstance==fClustersDataHandler) {
409     delete fClustersDataHandler;
410     fClustersDataHandler=NULL;
411   }
412
413   return 0;
414 }
415
416 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
417 {
418   // see header file for class documentation
419 }
420
421 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
422 {
423   // see header file for class documentation
424 }
425
426 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
427 {
428   // see header file for class documentation
429   if (!pData) return -EINVAL;
430   AliHLTComponentDataType dt=kAliHLTVoidDataType;
431   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
432   int iResult=pData->GetDataBlockDescription(dt, spec);
433   if (iResult>=0) {
434     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
435     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
436     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
437         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
438       iResult=768;
439       if (part>1) iResult+=72+4*slice+(part-2);
440       else iResult+=2*slice+part;
441     } else {
442       HLTError("handler can not process merged data from multiple ddls:"
443                " min slice %d, max slice %d, min part %d, max part %d",
444                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
445                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
446       iResult=-EBADMSG;
447     }
448   }
449   return iResult;
450 }