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