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