]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
681715a8f6884d7a3adb4e95c29003646eb9cd80
[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       converterInput+=" ";
180       converterInput+=sinkClusterInput;
181     }
182     handler->CreateConfiguration("TPC-esd-converter", "TPCEsdConverter"   , converterInput.Data(), "");
183
184     // cluster dump collection
185     handler->CreateConfiguration("TPC-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");
186
187     /////////////////////////////////////////////////////////////////////////////////////
188     //
189     // a kChain HLTOUT configuration for processing of {'TRAKSEGS':'TPC '} data blocks
190     // collects the data blocks, merges the tracks and produces an ESD object
191
192     // publisher component
193     handler->CreateConfiguration("TPC-hltout-tracksegs-publisher", "AliHLTOUTPublisher"   , NULL, "");
194
195     // GlobalMerger component
196     handler->CreateConfiguration("TPC-hltout-tracksegs-merger", "TPCGlobalMerger", "TPC-hltout-tracksegs-publisher", "");
197
198     // the esd converter configuration
199     handler->CreateConfiguration("TPC-hltout-tracksegs-esd-converter", "TPCEsdConverter", "TPC-hltout-tracksegs-merger", "");
200
201     /////////////////////////////////////////////////////////////////////////////////////
202     //
203     // a kChain HLTOUT configuration for processing of {'TRACKS  ':'TPC '} data blocks
204     // produces an ESD object from the track structure
205
206     // publisher component
207     handler->CreateConfiguration("TPC-hltout-tracks-publisher", "AliHLTOUTPublisher"   , NULL, "");
208
209     // the esd converter configuration
210     handler->CreateConfiguration("TPC-hltout-tracks-esd-converter", "TPCEsdConverter", "TPC-hltout-tracks-publisher", "");
211   }
212   return 0;
213 }
214
215 const char* AliHLTTPCAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
216                                                     AliRunLoader* runloader) const
217 {
218   // see header file for class documentation
219   if (runloader) {
220     // reconstruction chains for AliRoot simulation
221     // Note: run loader is only available while running embedded into
222     // AliRoot simulation
223     if (runloader->GetLoader("TPCLoader") != NULL)
224       return "TPC-esd-converter TPC-clusters";
225   }
226   return NULL;
227 }
228
229 const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
230 {
231   // see header file for class documentation
232
233   // actually, the TPC library has dependencies to Util and RCU
234   // so the two has to be loaded anyhow before we get here
235   //return "libAliHLTUtil.so libAliHLTRCU.so";
236   return NULL;
237 }
238
239 int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
240 {
241   // see header file for class documentation
242   if (!pHandler) return -EINVAL;
243
244   pHandler->AddComponent(new AliHLTTPCRunStatisticsProducerComponent);
245   pHandler->AddComponent(new AliHLTTPCEventStatisticsProducerComponent);
246   pHandler->AddComponent(new AliHLTTPCCalibCEComponent);
247   pHandler->AddComponent(new AliHLTTPCCalibPulserComponent);
248   pHandler->AddComponent(new AliHLTTPCCalibPedestalComponent);
249   pHandler->AddComponent(new AliHLTTPCCompModelInflaterComponent);
250   pHandler->AddComponent(new AliHLTTPCCompModelDeflaterComponent);
251   pHandler->AddComponent(new AliHLTTPCCompModelDeconverterComponent);
252   pHandler->AddComponent(new AliHLTTPCCompModelConverterComponent);
253   pHandler->AddComponent(new AliHLTTPCCompDumpComponent);
254   pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
255   pHandler->AddComponent(new AliHLTTPCCAGlobalMergerComponent);
256   pHandler->AddComponent(new AliHLTTPCTrackMCMarkerComponent);
257   pHandler->AddComponent(new AliHLTTPCGlobalMergerComponent);
258   pHandler->AddComponent(new AliHLTTPCSliceTrackerComponent);
259   pHandler->AddComponent(new AliHLTTPCVertexFinderComponent);
260   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderPacked));
261   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderUnpacked));
262   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderDecoder));
263   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinder32Bit));
264   pHandler->AddComponent(new AliHLTTPCRawDataUnpackerComponent);
265   pHandler->AddComponent(new AliHLTTPCDigitPublisherComponent);
266   pHandler->AddComponent(new AliHLTTPCZeroSuppressionComponent);
267   pHandler->AddComponent(new AliHLTTPCDigitDumpComponent);
268   pHandler->AddComponent(new AliHLTTPCClusterDumpComponent);
269   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliWriter);
270   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliConverter);
271   pHandler->AddComponent(new AliHLTTPCOfflineClustererComponent);
272   pHandler->AddComponent(new AliHLTTPCOfflineTrackerComponent);
273   pHandler->AddComponent(new AliHLTTPCOfflineTrackerCalibComponent);
274   pHandler->AddComponent(new AliHLTTPCOfflineCalibrationComponent);
275   pHandler->AddComponent(new AliHLTTPCClusterHistoComponent);
276   pHandler->AddComponent(new AliHLTTPCNoiseMapComponent);
277   pHandler->AddComponent(new AliHLTTPCHistogramHandlerComponent);
278   pHandler->AddComponent(new AliHLTTPCCalibTracksComponent);
279   pHandler->AddComponent(new AliHLTTPCTrackHistoComponent);
280   pHandler->AddComponent(new AliHLTTPCTrackDumpComponent);
281   pHandler->AddComponent(new AliHLTTPCHWCFDataReverterComponent);
282   pHandler->AddComponent(new AliHLTTPCHWClusterTransformComponent);
283
284   return 0;
285 }
286
287 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
288                                           AliHLTUInt32_t spec,
289                                           AliHLTOUTHandlerDesc& desc) const
290 {
291   // see header file for class documentation
292
293   // raw data blocks to be fed into offline reconstruction
294   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
295     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
296     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
297     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
298         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
299       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
300       return 1;
301     } else {
302       HLTWarning("handler can not process merged data from multiple ddls:"
303                  " min slice %d, max slice %d, min part %d, max part %d",
304                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
305                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
306       return 0;
307     }
308   }
309
310   // dump for {'CLUSTERS':'TPC '} currently not used any more
311   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
312       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
313       return 1;
314   }
315
316   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
317   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
318       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
319       return 1;
320   }
321
322   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
323   // there is only one data block
324   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
325       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
326       return 1;
327   }
328   return 0;
329 }
330
331 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
332                                                    AliHLTUInt32_t /*spec*/)
333 {
334   // see header file for class documentation
335
336   // raw data blocks to be fed into offline reconstruction
337   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
338     if (!fRawDataHandler) {
339       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
340     }
341     return fRawDataHandler;
342   }
343
344   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
345   // in a kChain HLTOUT handler
346   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
347     if (fTracksegsDataHandler==NULL)
348       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
349     return fTracksegsDataHandler;
350   }
351
352   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
353   // there is only one data block
354   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
355     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
356   }
357
358   return NULL;
359 }
360
361 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
362 {
363   // see header file for class documentation
364   if (pInstance==NULL) return -EINVAL;
365
366   if (pInstance==fRawDataHandler) {
367     delete fRawDataHandler;
368     fRawDataHandler=NULL;
369   }
370
371   if (pInstance==fTracksegsDataHandler) {
372     delete fTracksegsDataHandler;
373     fTracksegsDataHandler=NULL;
374   }
375   return 0;
376 }
377
378 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
379 {
380   // see header file for class documentation
381 }
382
383 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
384 {
385   // see header file for class documentation
386 }
387
388 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
389 {
390   // see header file for class documentation
391   if (!pData) return -EINVAL;
392   AliHLTComponentDataType dt=kAliHLTVoidDataType;
393   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
394   int iResult=pData->GetDataBlockDescription(dt, spec);
395   if (iResult>=0) {
396     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
397     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
398     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
399         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
400       iResult=768;
401       if (part>1) iResult+=72+4*slice+(part-2);
402       else iResult+=2*slice+part;
403     } else {
404       HLTError("handler can not process merged data from multiple ddls:"
405                " min slice %d, max slice %d, min part %d, max part %d",
406                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
407                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
408       iResult=-EBADMSG;
409     }
410   }
411   return iResult;
412 }