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