]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
correction HLT TPC simulation: reading AliTPCParam from OCDB, applies to digit to...
[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     for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
124       TString trackerInput;
125       for (int part=iMinPart; part<=iMaxPart; part++) {
126         TString arg, publisher, cf;
127
128         // digit publisher components
129         publisher.Form("TPC-DP_%02d_%d", slice, part);
130         if (!rawReader) {
131           arg.Form("-slice %d -partition %d", slice, part);
132           handler->CreateConfiguration(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());
133         } else {
134           int ddlno=768;
135           if (part>1) ddlno+=72+4*slice+(part-2);
136           else ddlno+=2*slice+part;
137           arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -silent", ddlno, slice, slice, part, part);
138           handler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
139         }
140
141         // cluster finder components
142         cf.Form("TPC-CF_%02d_%d", slice, part);
143         arg="";
144         if (pTPCParam) {
145           arg+=" -timebins "; arg+=pTPCParam->GetMaxTBin()+1;
146         }
147         if (!rawReader) {
148           arg+=" -sorted";
149           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
150         } else {
151           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderDecoder", publisher.Data(), arg.Data());
152         }
153         if (trackerInput.Length()>0) trackerInput+=" ";
154         trackerInput+=cf;
155       }
156       TString tracker;
157       // tracker finder components
158       tracker.Form("TPC-TR_%02d", slice);
159       handler->CreateConfiguration(tracker.Data(), "TPCSliceTracker", trackerInput.Data(), "-pp-run -bfield 0.5");
160
161       if (mergerInput.Length()>0) mergerInput+=" ";
162       mergerInput+=tracker;
163
164     }
165
166     // GlobalMerger component
167     handler->CreateConfiguration("TPC-globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
168
169     // the esd converter configuration
170     handler->CreateConfiguration("TPC-esd-converter", "TPCEsdConverter"   , "TPC-globalmerger", "");
171
172     /////////////////////////////////////////////////////////////////////////////////////
173     //
174     // a kChain HLTOUT configuration for processing of {'TRAKSEGS':'TPC '} data blocks
175     // collects the data blocks, merges the tracks and produces an ESD object
176
177     // publisher component
178     handler->CreateConfiguration("TPC-hltout-tracksegs-publisher", "AliHLTOUTPublisher"   , NULL, "");
179
180     // GlobalMerger component
181     handler->CreateConfiguration("TPC-hltout-tracksegs-merger", "TPCGlobalMerger", "TPC-hltout-tracksegs-publisher", "");
182
183     // the esd converter configuration
184     handler->CreateConfiguration("TPC-hltout-tracksegs-esd-converter", "TPCEsdConverter", "TPC-hltout-tracksegs-merger", "");
185
186     /////////////////////////////////////////////////////////////////////////////////////
187     //
188     // a kChain HLTOUT configuration for processing of {'TRACKS  ':'TPC '} data blocks
189     // produces an ESD object from the track structure
190
191     // publisher component
192     handler->CreateConfiguration("TPC-hltout-tracks-publisher", "AliHLTOUTPublisher"   , NULL, "");
193
194     // the esd converter configuration
195     handler->CreateConfiguration("TPC-hltout-tracks-esd-converter", "TPCEsdConverter", "TPC-hltout-tracks-publisher", "");
196   }
197   return 0;
198 }
199
200 const char* AliHLTTPCAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
201                                                     AliRunLoader* runloader) const
202 {
203   // see header file for class documentation
204   if (runloader) {
205     // reconstruction chains for AliRoot simulation
206     // Note: run loader is only available while running embedded into
207     // AliRoot simulation
208     if (runloader->GetLoader("TPCLoader") != NULL)
209       return "TPC-esd-converter";
210   }
211   return NULL;
212 }
213
214 const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
215 {
216   // see header file for class documentation
217
218   // actually, the TPC library has dependencies to Util and RCU
219   // so the two has to be loaded anyhow before we get here
220   //return "libAliHLTUtil.so libAliHLTRCU.so";
221   return NULL;
222 }
223
224 int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
225 {
226   // see header file for class documentation
227   if (!pHandler) return -EINVAL;
228
229   pHandler->AddComponent(new AliHLTTPCRunStatisticsProducerComponent);
230   pHandler->AddComponent(new AliHLTTPCEventStatisticsProducerComponent);
231   pHandler->AddComponent(new AliHLTTPCCalibCEComponent);
232   pHandler->AddComponent(new AliHLTTPCCalibPulserComponent);
233   pHandler->AddComponent(new AliHLTTPCCalibPedestalComponent);
234   pHandler->AddComponent(new AliHLTTPCCompModelInflaterComponent);
235   pHandler->AddComponent(new AliHLTTPCCompModelDeflaterComponent);
236   pHandler->AddComponent(new AliHLTTPCCompModelDeconverterComponent);
237   pHandler->AddComponent(new AliHLTTPCCompModelConverterComponent);
238   pHandler->AddComponent(new AliHLTTPCCompDumpComponent);
239   pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
240   pHandler->AddComponent(new AliHLTTPCGlobalMergerComponent);
241   pHandler->AddComponent(new AliHLTTPCSliceTrackerComponent);
242   pHandler->AddComponent(new AliHLTTPCVertexFinderComponent);
243   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderPacked));
244   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderUnpacked));
245   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderDecoder));
246   pHandler->AddComponent(new AliHLTTPCRawDataUnpackerComponent);
247   pHandler->AddComponent(new AliHLTTPCDigitPublisherComponent);
248   pHandler->AddComponent(new AliHLTTPCZeroSuppressionComponent);
249   pHandler->AddComponent(new AliHLTTPCDigitDumpComponent);
250   pHandler->AddComponent(new AliHLTTPCClusterDumpComponent);
251   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliWriter);
252   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliConverter);
253   pHandler->AddComponent(new AliHLTTPCOfflineClustererComponent);
254   pHandler->AddComponent(new AliHLTTPCOfflineTrackerComponent);
255   pHandler->AddComponent(new AliHLTTPCOfflineTrackerCalibComponent);
256   pHandler->AddComponent(new AliHLTTPCOfflineCalibrationComponent);
257   pHandler->AddComponent(new AliHLTTPCClusterHistoComponent);
258   pHandler->AddComponent(new AliHLTTPCNoiseMapComponent);
259   pHandler->AddComponent(new AliHLTTPCHistogramHandlerComponent);
260   pHandler->AddComponent(new AliHLTTPCCalibTracksComponent);
261   pHandler->AddComponent(new AliHLTTPCTrackHistoComponent);
262   pHandler->AddComponent(new AliHLTTPCTrackDumpComponent);
263   pHandler->AddComponent(new AliHLTTPCHWCFDataReverterComponent);
264
265   return 0;
266 }
267
268 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
269                                           AliHLTUInt32_t spec,
270                                           AliHLTOUTHandlerDesc& desc) const
271 {
272   // see header file for class documentation
273
274   // raw data blocks to be fed into offline reconstruction
275   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
276     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
277     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
278     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
279         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
280       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
281       return 1;
282     } else {
283       HLTWarning("handler can not process merged data from multiple ddls:"
284                  " min slice %d, max slice %d, min part %d, max part %d",
285                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
286                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
287       return 0;
288     }
289   }
290
291   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
292   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
293       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
294       return 1;
295   }
296
297   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
298   // there is only one data block
299   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
300       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
301       return 1;
302   }
303   return 0;
304 }
305
306 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
307                                                    AliHLTUInt32_t /*spec*/)
308 {
309   // see header file for class documentation
310
311   // raw data blocks to be fed into offline reconstruction
312   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
313     if (!fRawDataHandler) {
314       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
315     }
316     return fRawDataHandler;
317   }
318
319   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
320   // in a kChain HLTOUT handler
321   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
322     if (fTracksegsDataHandler==NULL)
323       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
324     return fTracksegsDataHandler;
325   }
326
327   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
328   // there is only one data block
329   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
330     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
331   }
332
333   return NULL;
334 }
335
336 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
337 {
338   // see header file for class documentation
339   if (pInstance==NULL) return -EINVAL;
340
341   if (pInstance==fRawDataHandler) {
342     delete fRawDataHandler;
343     fRawDataHandler=NULL;
344   }
345
346   if (pInstance==fTracksegsDataHandler) {
347     delete fTracksegsDataHandler;
348     fTracksegsDataHandler=NULL;
349   }
350   return 0;
351 }
352
353 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
354 {
355   // see header file for class documentation
356 }
357
358 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
359 {
360   // see header file for class documentation
361 }
362
363 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
364 {
365   // see header file for class documentation
366   if (!pData) return -EINVAL;
367   AliHLTComponentDataType dt=kAliHLTVoidDataType;
368   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
369   int iResult=pData->GetDataBlockDescription(dt, spec);
370   if (iResult>=0) {
371     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
372     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
373     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
374         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
375       iResult=768;
376       if (part>1) iResult+=72+4*slice+(part-2);
377       else iResult+=2*slice+part;
378     } else {
379       HLTError("handler can not process merged data from multiple ddls:"
380                " min slice %d, max slice %d, min part %d, max part %d",
381                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
382                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
383       iResult=-EBADMSG;
384     }
385   }
386   return iResult;
387 }