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