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