]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
- adding data structure for raw clusters
[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 "AliHLTTPCCompModelInflaterComponent.h"
39 #include "AliHLTTPCCompModelDeflaterComponent.h"
40 #include "AliHLTTPCCompModelDeconverterComponent.h"
41 #include "AliHLTTPCCompModelConverterComponent.h"
42 #include "AliHLTTPCCompDumpComponent.h"
43 //#include "AliHLTTPCCalibCEComponent.h"
44 //#include "AliHLTTPCCalibPulserComponent.h"
45 //#include "AliHLTTPCCalibPedestalComponent.h"
46 #include "AliHLTTPCCAInputDataCompressorComponent.h"
47 #include "AliHLTTPCCATrackerComponent.h"
48 #include "AliHLTTPCCATrackerOutputConverter.h"
49 #include "AliHLTTPCTrackMCMarkerComponent.h"
50 #include "AliHLTTPCCAGlobalMergerComponent.h"
51 #include "AliHLTTPCdEdxComponent.h"
52 #include "AliHLTTPCGlobalMergerComponent.h"
53 #include "AliHLTTPCSliceTrackerComponent.h"
54 #include "AliHLTTPCClusterFinderComponent.h"
55 #include "AliHLTTPCRawDataUnpackerComponent.h"
56 #include "AliHLTTPCDigitPublisherComponent.h"
57 #include "AliHLTTPCDigitDumpComponent.h"
58 #include "AliHLTTPCClusterDumpComponent.h"
59 #include "AliHLTTPCEsdWriterComponent.h"
60 #include "AliHLTTPCOfflineClustererComponent.h"
61 #include "AliHLTTPCOfflineTrackerComponent.h"
62 #include "AliHLTTPCOfflineTrackerCalibComponent.h"
63 #include "AliHLTTPCOfflineCalibrationComponent.h" // to be added to the calibration library agent
64 #include "AliHLTTPCClusterHistoComponent.h"
65 #include "AliHLTTPCHistogramHandlerComponent.h"
66 //#include "AliHLTTPCCalibTracksComponent.h"
67 #include "AliHLTTPCTrackHistoComponent.h"
68 #include "AliHLTTPCTrackDumpComponent.h"
69 #include "AliHLTTPCHWCFDataReverterComponent.h"
70 #include "AliHLTTPCHWClusterTransformComponent.h"
71 #include "AliHLTTPCCFComparisonComponent.h"
72 // #include "AliHLTTPCCalibSeedMakerComponent.h"
73 // #include "AliHLTTPCCalibTimeComponent.h"
74 // #include "AliHLTTPCCalibTimeGainComponent.h"
75 // #include "AliHLTTPCCalibrationComponent.h"
76 #include "AliHLTTPCDataCheckerComponent.h"
77 #include "AliHLTTPCHWCFEmulatorComponent.h"
78 #include "AliHLTTPCHWCFConsistencyControlComponent.h"
79
80 /** ROOT macro for the implementation of ROOT specific class methods */
81 ClassImp(AliHLTTPCAgent)
82
83 AliHLTTPCAgent::AliHLTTPCAgent()
84   : AliHLTModuleAgent("TPC")
85   , fRawDataHandler(NULL)
86   , fTracksegsDataHandler(NULL)
87   , fClustersDataHandler(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
108     // This the tracking configuration for the full TPC
109     // - 216 clusterfinders (1 per partition)
110     // - 36 slice trackers
111     // - one global merger
112     // - the esd converter
113     // The ESD is shipped embedded into a TTree
114     int iMinSlice=0; 
115     int iMaxSlice=35;
116     int iMinPart=0;
117     int iMaxPart=5;
118     TString mergerInput;
119     TString sinkClusterInput;
120     TString dEdXInput;
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 -publish-raw";
144         if (!rawReader && runloader) {
145           arg+=" -do-mc";
146           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
147         } else {
148           handler->CreateConfiguration(cf.Data(), "TPCClusterFinder32Bit", publisher.Data(),arg.Data());
149         }
150         if (trackerInput.Length()>0) trackerInput+=" ";
151         trackerInput+=cf;
152         if (dEdXInput.Length()>0) dEdXInput+=" ";
153         dEdXInput+=cf;
154         if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
155         sinkClusterInput+=cf;
156       }
157       TString tracker;
158       // tracker finder components
159       tracker.Form("TPC-TR_%02d", slice);
160       handler->CreateConfiguration(tracker.Data(), "TPCCATracker", trackerInput.Data(), "-minTrackPt 0.0");
161
162       if (mergerInput.Length()>0) mergerInput+=" ";
163       mergerInput+=tracker;
164
165     }
166
167     // GlobalMerger component
168     handler->CreateConfiguration("TPC-globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
169
170     if (dEdXInput.Length()>0) dEdXInput+=" ";
171     dEdXInput+="TPC-globalmerger";
172
173     handler->CreateConfiguration("TPC-dEdx","TPCdEdx",dEdXInput.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 ' -datatype 'CLMCINFO' 'TPC '");
188     handler->CreateConfiguration("TPC-raw-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTRAW' 'TPC ' -datatype 'CLMCINFO' '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
241     // 2010-10-26 TPC clusters not written to HLTOUT in order to make the simulation
242     // closer to the real data 
243     //return "TPC-clusters";
244   }
245   return NULL;
246 }
247
248 const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
249 {
250   // see header file for class documentation
251
252   // actually, the TPC library has dependencies to Util and RCU
253   // so the two has to be loaded anyhow before we get here
254   //return "libAliHLTUtil.so libAliHLTRCU.so";
255   return "libAliHLTUtil.so";
256 }
257
258 int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
259 {
260   // see header file for class documentation
261   if (!pHandler) return -EINVAL;
262
263 //   pHandler->AddComponent(new AliHLTTPCCalibCEComponent);
264 //   pHandler->AddComponent(new AliHLTTPCCalibPulserComponent);
265 //   pHandler->AddComponent(new AliHLTTPCCalibPedestalComponent);
266   pHandler->AddComponent(new AliHLTTPCCompModelInflaterComponent);
267   pHandler->AddComponent(new AliHLTTPCCompModelDeflaterComponent);
268   pHandler->AddComponent(new AliHLTTPCCompModelDeconverterComponent);
269   pHandler->AddComponent(new AliHLTTPCCompModelConverterComponent);
270   pHandler->AddComponent(new AliHLTTPCCompDumpComponent);
271   pHandler->AddComponent(new AliHLTTPCCAInputDataCompressorComponent);
272   pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
273   pHandler->AddComponent(new AliHLTTPCCATrackerOutputConverter);
274   pHandler->AddComponent(new AliHLTTPCCAGlobalMergerComponent);
275   pHandler->AddComponent(new AliHLTTPCTrackMCMarkerComponent);
276   pHandler->AddComponent(new AliHLTTPCGlobalMergerComponent);
277   pHandler->AddComponent(new AliHLTTPCdEdxComponent);
278   pHandler->AddComponent(new AliHLTTPCSliceTrackerComponent);
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 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 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 AliHLTTPCCFComparisonComponent);
301 //   pHandler->AddComponent(new AliHLTTPCCalibSeedMakerComponent);
302 //   pHandler->AddComponent(new AliHLTTPCCalibTimeComponent);
303 //   pHandler->AddComponent(new AliHLTTPCCalibTimeGainComponent);
304 //   pHandler->AddComponent(new AliHLTTPCCalibrationComponent);
305   pHandler->AddComponent(new AliHLTTPCDataCheckerComponent);
306   pHandler->AddComponent(new AliHLTTPCHWCFEmulatorComponent);
307   pHandler->AddComponent(new AliHLTTPCHWCFConsistencyControlComponent);
308   return 0;
309 }
310
311 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
312                                           AliHLTUInt32_t spec,
313                                           AliHLTOUTHandlerDesc& desc) const
314 {
315   // see header file for class documentation
316
317   // raw data blocks to be fed into offline reconstruction
318   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
319     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
320     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
321     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
322         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
323       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
324       return 1;
325     } else {
326       HLTWarning("handler can not process merged data from multiple ddls:"
327                  " min slice %d, max slice %d, min part %d, max part %d",
328                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
329                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
330       return 0;
331     }
332   }
333
334   // dump for {'CLUSTERS':'TPC '} blocks stored in a 'digit' file
335   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
336       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
337       return 1;
338   }
339
340   // {'CLUSTRAW':'TPC '} 
341   if (dt==AliHLTTPCDefinitions::fgkRawClustersDataType) {
342       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
343       return 1;
344   }
345
346   // {'CLMCINFO':'TPC '} 
347   if (dt==AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo) {
348       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
349       return 1;
350   }
351
352   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
353   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
354       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
355       return 1;
356   }
357
358   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
359   // there is only one data block
360   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
361       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
362       return 1;
363   }
364   return 0;
365 }
366
367 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
368                                                    AliHLTUInt32_t /*spec*/)
369 {
370   // see header file for class documentation
371
372   // raw data blocks to be fed into offline reconstruction
373   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
374     if (!fRawDataHandler) {
375       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
376     }
377     return fRawDataHandler;
378   }
379
380   // dump for {'CLUSTERS':'TPC '}, stored in a file HLT.TPC.Clusters.root in HOMER format
381   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
382     if (fClustersDataHandler==NULL)
383       fClustersDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-cluster-dump libHLTsim.so libAliHLTUtil.so");
384     return fClustersDataHandler;
385   }
386
387   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
388   // in a kChain HLTOUT handler
389   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
390     if (fTracksegsDataHandler==NULL)
391       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
392     return fTracksegsDataHandler;
393   }
394
395   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
396   // there is only one data block
397   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
398     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
399   }
400
401   return NULL;
402 }
403
404 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
405 {
406   // see header file for class documentation
407   if (pInstance==NULL) return -EINVAL;
408
409   if (pInstance==fRawDataHandler) {
410     delete fRawDataHandler;
411     fRawDataHandler=NULL;
412   }
413
414   if (pInstance==fTracksegsDataHandler) {
415     delete fTracksegsDataHandler;
416     fTracksegsDataHandler=NULL;
417   }
418
419   if (pInstance==fClustersDataHandler) {
420     delete fClustersDataHandler;
421     fClustersDataHandler=NULL;
422   }
423
424   return 0;
425 }
426
427 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
428 {
429   // see header file for class documentation
430 }
431
432 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
433 {
434   // see header file for class documentation
435 }
436
437 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
438 {
439   // see header file for class documentation
440   if (!pData) return -EINVAL;
441   AliHLTComponentDataType dt=kAliHLTVoidDataType;
442   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
443   int iResult=pData->GetDataBlockDescription(dt, spec);
444   if (iResult>=0) {
445     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
446     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
447     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
448         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
449       iResult=768;
450       if (part>1) iResult+=72+4*slice+(part-2);
451       else iResult+=2*slice+part;
452     } else {
453       HLTError("handler can not process merged data from multiple ddls:"
454                " min slice %d, max slice %d, min part %d, max part %d",
455                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
456                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
457       iResult=-EBADMSG;
458     }
459   }
460   return iResult;
461 }