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