]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAgent.cxx
Update to allow check per chamber
[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 //  @note   
24
25 #include "AliHLTTPCAgent.h"
26 #include "AliHLTTPCDefinitions.h"
27 #include "AliHLTOUT.h"
28 #include "AliHLTOUTHandlerChain.h"
29 #include "AliHLTMisc.h"
30 #include "AliRunLoader.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBEntry.h"
33 #include "AliTPCParam.h"
34 #include "AliTPCRecoParam.h"
35 #include "TObject.h"
36
37 /** global instance for agent registration */
38 AliHLTTPCAgent gAliHLTTPCAgent;
39
40 // component headers
41 #include "AliHLTTPCCAInputDataCompressorComponent.h"
42 #include "AliHLTTPCCATrackerComponent.h"
43 #include "AliHLTTPCCATrackerOutputConverter.h"
44 #include "AliHLTTPCTrackMCMarkerComponent.h"
45 #include "AliHLTTPCCAGlobalMergerComponent.h"
46 #include "AliHLTTPCdEdxComponent.h"
47 #include "AliHLTTPCdEdxMonitoringComponent.h"
48 #include "AliHLTTPCClusterFinderComponent.h"
49 #include "AliHLTTPCRawDataUnpackerComponent.h"
50 #include "AliHLTTPCDigitPublisherComponent.h"
51 #include "AliHLTTPCDigitDumpComponent.h"
52 #include "AliHLTTPCClusterDumpComponent.h"
53 #include "AliHLTTPCEsdWriterComponent.h"
54 #include "AliHLTTPCOfflineClustererComponent.h"
55 #include "AliHLTTPCOfflineTrackerComponent.h"
56 #include "AliHLTTPCOfflineTrackerCalibComponent.h"
57 #include "AliHLTTPCOfflineCalibrationComponent.h" // to be added to the calibration library agent
58 #include "AliHLTTPCClusterHistoComponent.h"
59 #include "AliHLTTPCHistogramHandlerComponent.h"
60 #include "AliHLTTPCTrackHistoComponent.h"
61 #include "AliHLTTPCTrackDumpComponent.h"
62 #include "AliHLTTPCHWCFDataReverterComponent.h"
63 #include "AliHLTTPCHWClusterTransformComponent.h"
64 #include "AliHLTTPCCFComparisonComponent.h"
65 #include "AliHLTTPCDataCheckerComponent.h"
66 #include "AliHLTTPCHWCFEmulatorComponent.h"
67 #include "AliHLTTPCHWCFConsistencyControlComponent.h"
68 #include "AliHLTTPCDataCompressionComponent.h"
69 #include "AliHLTTPCDataCompressionMonitorComponent.h"
70 #include "AliHLTTPCDataCompressionFilterComponent.h"
71
72 /** ROOT macro for the implementation of ROOT specific class methods */
73 ClassImp(AliHLTTPCAgent)
74
75 AliHLTTPCAgent::AliHLTTPCAgent()
76   : AliHLTModuleAgent("TPC")
77   , fRawDataHandler(NULL)
78   , fTracksegsDataHandler(NULL)
79   , fClustersDataHandler(NULL)
80   , fCompressionMonitorHandler(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
101     // This the tracking configuration for the full TPC
102     // - 216 clusterfinders (1 per partition)
103     // - 36 slice trackers
104     // - one global merger
105     // - the esd converter
106     // The ESD is shipped embedded into a TTree
107     int iMinSlice=0; 
108     int iMaxSlice=35;
109     int iMinPart=0;
110     int iMaxPart=5;
111     TString arg;
112     TString mergerInput;
113     TString sinkRawData;
114     TString sinkClusterInput;
115     TString sinkHWClusterInput;
116     TString dEdXInput;
117     TString compressorInput;
118     for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
119       TString trackerInput;
120       for (int part=iMinPart; part<=iMaxPart; part++) {
121         TString publisher, cf;
122
123         // digit publisher components
124         publisher.Form("TPC-DP_%02d_%d", slice, part);
125         if (rawReader || !runloader) {
126           // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
127           // Alireconstruction: indicated by runloader==NULL, run always on raw data
128           int ddlno=768;
129           if (part>1) ddlno+=72+4*slice+(part-2);
130           else ddlno+=2*slice+part;
131           arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -silent", ddlno, slice, slice, part, part);
132           handler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
133         } else {
134           arg.Form("-slice %d -partition %d", slice, part);
135           handler->CreateConfiguration(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());
136         }
137
138         if (sinkRawData.Length()>0) sinkRawData+=" ";
139         sinkRawData+=publisher;
140
141         // cluster finder components
142         cf.Form("TPC-CF_%02d_%d", slice, part);
143         arg="-release-memory -publish-raw";
144         if (!rawReader && runloader) {
145           arg+=" -do-mc";
146           handler->CreateConfiguration(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
147         } else {
148           handler->CreateConfiguration(cf.Data(), "TPCClusterFinder32Bit", publisher.Data(),arg.Data());
149         }
150
151         // Hardware CF emulator
152         // soon going to replace the software clusterfinder
153         TString hwcfemu;
154         hwcfemu.Form("TPC-HWCFEmu_%02d_%d", slice, part);
155         handler->CreateConfiguration(hwcfemu.Data(), "TPCHWClusterFinderEmulator", publisher.Data(), "-do-mc 1");
156         if (compressorInput.Length()>0) compressorInput+=" ";
157         compressorInput+=hwcfemu;
158
159         TString hwcf;
160         hwcf.Form("TPC-HWCF_%02d_%d", slice, part);
161         handler->CreateConfiguration(hwcf.Data(), "TPCHWClusterTransform",hwcfemu.Data(), "-publish-raw");
162
163         if (trackerInput.Length()>0) trackerInput+=" ";
164         trackerInput+=hwcf;
165         if (dEdXInput.Length()>0) dEdXInput+=" ";
166         dEdXInput+=hwcf;
167         if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
168         sinkClusterInput+=cf;
169         if (sinkHWClusterInput.Length()>0) sinkHWClusterInput+=" ";
170         sinkHWClusterInput+=hwcf;
171       }
172       TString tracker;
173       // tracker finder components
174       tracker.Form("TPC-TR_%02d", slice);
175       handler->CreateConfiguration(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
176
177       if (mergerInput.Length()>0) mergerInput+=" ";
178       mergerInput+=tracker;
179
180     }
181
182     // GlobalMerger component
183     handler->CreateConfiguration("TPC-globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
184
185     // dEdx component
186     if (dEdXInput.Length()>0) dEdXInput+=" ";
187     dEdXInput+="TPC-globalmerger";
188
189     handler->CreateConfiguration("TPC-dEdx","TPCdEdx",dEdXInput.Data(),"");
190
191     // compression component
192     if (compressorInput.Length()>0) compressorInput+=" ";
193     compressorInput+="TPC-globalmerger";
194     handler->CreateConfiguration("TPC-compression", "TPCDataCompressor", compressorInput.Data(), "");
195     handler->CreateConfiguration("TPC-compression-huffman-trainer", "TPCDataCompressor", compressorInput.Data(),"-deflater-mode 3");
196     handler->CreateConfiguration("TPC-compression-monitoring-component", "TPCDataCompressorMonitor", "TPC-compression TPC-hwcfdata","-pushback-period=30");
197     handler->CreateConfiguration("TPC-compression-monitoring", "ROOTFileWriter", "TPC-compression-monitoring-component","-concatenate-events -overwrite -datafile HLT.TPCDataCompression-statistics.root");
198
199     // special configuration to run the emulation automatically if the compressed clusters
200     // of a particular partition is missing. This configuration is announced for reconstruction
201     // of raw data if the HLT mode of the TPC reconstruction is enabled. Compression component
202     // always needs to run in mode 1. Even if the recorded data is mode 3 (optimized partition
203     // clusters), 2 (track model compression), or 4. The emulation can not be in mode 2 or 4,
204     // since the track model block can not be identified with a partition. Have to duplicate the
205     // configuration of the compression component
206     handler->CreateConfiguration("TPC-auto-compression-component", "TPCDataCompressor", compressorInput.Data(), "-mode 1");
207     handler->CreateConfiguration("TPC-auto-compression", "TPCDataCompressorFilter", "TPC-auto-compression-component","");
208
209     // the esd converter configuration
210     TString converterInput="TPC-globalmerger";
211     if (!rawReader && runloader) {
212       // propagate cluster info to the esd converter in order to fill the MC information
213       handler->CreateConfiguration("TPC-clustermc-info", "BlockFilter"   , sinkHWClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");  
214       handler->CreateConfiguration("TPC-mcTrackMarker","TPCTrackMCMarker","TPC-globalmerger TPC-clustermc-info","" );
215       converterInput+=" ";
216       converterInput+="TPC-mcTrackMarker";
217     }
218     handler->CreateConfiguration("TPC-esd-converter", "TPCEsdConverter"   , converterInput.Data(), "");
219
220     // cluster dump collection
221     handler->CreateConfiguration("TPC-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC ' -datatype 'CLMCINFO' 'TPC '");
222     handler->CreateConfiguration("TPC-raw-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTRAW' 'TPC ' -datatype 'CLMCINFO' 'TPC '");
223     handler->CreateConfiguration("TPC-hwclusters", "BlockFilter"   , sinkHWClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC ' -datatype 'CLMCINFO' 'TPC '");
224     handler->CreateConfiguration("TPC-raw-hwclusters", "BlockFilter"   , sinkHWClusterInput.Data(), "-datatype 'CLUSTRAW' 'TPC ' -datatype 'CLMCINFO' 'TPC '");
225
226     // raw data
227     handler->CreateConfiguration("TPC-raw-data", "BlockFilter"   , sinkRawData.Data(), "");
228
229     handler->CreateConfiguration("TPC-hwcfdata", "BlockFilter"   , compressorInput.Data(), "-datatype 'HWCLUST1' 'TPC '");
230
231     /////////////////////////////////////////////////////////////////////////////////////
232     //
233     // dumps on the ALTRO digit level
234     //
235     // selected channel dump
236     arg.Form("-datafile selected-channel.dump -specfmt=_0x%%08x -subdir -blcknofmt= -idfmt=");
237     handler->CreateConfiguration("TPC-selected-altro-digits", "TPCDigitDump", "RCU-channelselect", arg.Data());
238
239     // raw channel dump
240     arg.Form("-datafile channel.dump -specfmt=_0x%%08x -subdir -blcknofmt= -idfmt=");
241     handler->CreateConfiguration("TPC-raw-altro-digits", "TPCDigitDump", "TPC-raw-data", arg.Data());
242
243     /////////////////////////////////////////////////////////////////////////////////////
244     //
245     // a kChain HLTOUT configuration for processing of {'TRAKSEGS':'TPC '} data blocks
246     // collects the data blocks, merges the tracks and produces an ESD object
247
248     // publisher component
249     handler->CreateConfiguration("TPC-hltout-tracksegs-publisher", "AliHLTOUTPublisher"   , NULL, "");
250
251     // GlobalMerger component
252     handler->CreateConfiguration("TPC-hltout-tracksegs-merger", "TPCGlobalMerger", "TPC-hltout-tracksegs-publisher", "");
253
254     // the esd converter configuration
255     handler->CreateConfiguration("TPC-hltout-tracksegs-esd-converter", "TPCEsdConverter", "TPC-hltout-tracksegs-merger", "");
256
257     /////////////////////////////////////////////////////////////////////////////////////
258     //
259     // a kChain HLTOUT configuration for processing of {'TRACKS  ':'TPC '} data blocks
260     // produces an ESD object from the track structure
261
262     // publisher component
263     handler->CreateConfiguration("TPC-hltout-tracks-publisher", "AliHLTOUTPublisher"   , NULL, "");
264
265     // the esd converter configuration
266     handler->CreateConfiguration("TPC-hltout-tracks-esd-converter", "TPCEsdConverter", "TPC-hltout-tracks-publisher", "");
267
268     /////////////////////////////////////////////////////////////////////////////////////
269     //
270     // a kChain HLTOUT configuration for processing of {'CLUSTERS':'TPC '} data blocks
271     // stores the blocks in file HLT.TPC.Clusters.root in HOMER format
272
273     // publisher component
274     handler->CreateConfiguration("TPC-hltout-cluster-publisher", "AliHLTOUTPublisher"   , NULL, "");
275
276     // the HLTOUT component collects the blocks and stores the file
277     handler->CreateConfiguration("TPC-hltout-cluster-dump", "HLTOUT", "TPC-hltout-cluster-publisher", "-digitfile HLT.TPC.Clusters.root -rawout=off -links 2");
278
279     /////////////////////////////////////////////////////////////////////////////////////
280     //
281     // monitoring of compressed TPC data {CLUSTRAW:TPC }, {REMCLSCM,TPC }, {CLSTRKCM,TPC }
282     // 
283
284     // publisher component
285     handler->CreateConfiguration("TPC-hltout-compressionmonitor-publisher", "AliHLTOUTPublisher"   , NULL,
286                                  "-datatype HWCLUST1 'TPC ' "
287                                  "-datatype CLUSTRAW 'TPC ' "
288                                  "-datatype REMCLSCM 'TPC ' "
289                                  "-datatype CLSTRKCM 'TPC ' "
290                                  "-datatype REMCLIDS 'TPC ' "
291                                  "-datatype CLIDSTRK 'TPC ' "
292                                  );
293
294     // the HLTOUT component collects the blocks and stores the file
295     handler->CreateConfiguration("TPC-hltout-compressionmonitor", "TPCDataCompressorMonitor", "TPC-hltout-compressionmonitor-publisher", "-histogram-file HLT.TPC-compression-statistics.root -publishing-mode off");
296   }
297
298   return 0;
299 }
300
301 const char* AliHLTTPCAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
302                                                     AliRunLoader* runloader) const
303 {
304   // see header file for class documentation
305   if (runloader) {
306     // reconstruction chains for AliRoot simulation
307     // Note: run loader is only available while running embedded into
308     // AliRoot simulation
309     //if (runloader->GetLoader("TPCLoader") != NULL)
310       //return "TPC-esd-converter TPC-clusters";
311
312     // 2010-10-26 TPC clusters not written to HLTOUT in order to make the simulation
313     // closer to the real data 
314     //return "TPC-clusters";
315   } else {
316     bool bAddEmulation=true; // add by default
317
318     // FIXME:
319     // tried to make the configuration optional depending on whether the
320     // TPC requires HLT clusters or not, bu the RecoParam OCDB object is a TObjArray
321     // and the event specie is not yet defined. Maybe it can be derived from
322     // the GRP. On the other hand, HLT data compression is expected to be the
323     // default mode from now on, so this block might be safely deleted after some
324     // time (today is 2011-11-18)
325     //
326     // AliTPCRecoParam* param=NULL;
327     // TObject* pObject=AliHLTMisc::Instance().ExtractObject(AliHLTMisc::Instance().LoadOCDBEntry("TPC/Calib/RecoParam"));
328     // if (pObject && (param=dynamic_cast<AliTPCRecoParam*>(pObject))!=NULL) {
329     //   bAddEmulation=param->GetUseHLTClusters()==3 || param->GetUseHLTClusters()==4;
330     //   HLTInfo("%s auto-compression for not existing TPC partitions, TPCRecoParam::GetUseHLTClusters %d",
331     //        bAddEmulation?"adding":"skipping",
332     //        param->GetUseHLTClusters());
333     // }
334     if (bAddEmulation) {
335       // 2011-11-23: not yet enabled
336       // testing required, furthermore a component publishing only the raw data for
337       // the missing links, to big impact to performance otherwise
338       //return "TPC-auto-compression";
339     }
340   }
341   return NULL;
342 }
343
344 const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
345 {
346   // see header file for class documentation
347
348   // actually, the TPC library has dependencies to Util and RCU
349   // so the two has to be loaded anyhow before we get here
350   //return "libAliHLTUtil.so libAliHLTRCU.so";
351   return "libAliHLTUtil.so";
352 }
353
354 int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
355 {
356   // see header file for class documentation
357   if (!pHandler) return -EINVAL;
358
359   pHandler->AddComponent(new AliHLTTPCCAInputDataCompressorComponent);
360   pHandler->AddComponent(new AliHLTTPCCATrackerComponent);
361   pHandler->AddComponent(new AliHLTTPCCATrackerOutputConverter);
362   pHandler->AddComponent(new AliHLTTPCCAGlobalMergerComponent);
363   pHandler->AddComponent(new AliHLTTPCTrackMCMarkerComponent);
364   pHandler->AddComponent(new AliHLTTPCdEdxComponent);
365   pHandler->AddComponent(new AliHLTTPCdEdxMonitoringComponent);
366   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderPacked));
367   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderUnpacked));
368   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinderDecoder));
369   pHandler->AddComponent(new AliHLTTPCClusterFinderComponent(AliHLTTPCClusterFinderComponent::kClusterFinder32Bit));
370   pHandler->AddComponent(new AliHLTTPCRawDataUnpackerComponent);
371   pHandler->AddComponent(new AliHLTTPCDigitPublisherComponent);
372   pHandler->AddComponent(new AliHLTTPCDigitDumpComponent);
373   pHandler->AddComponent(new AliHLTTPCClusterDumpComponent);
374   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliWriter);
375   pHandler->AddComponent(new AliHLTTPCEsdWriterComponent::AliConverter);
376   pHandler->AddComponent(new AliHLTTPCOfflineClustererComponent);
377   pHandler->AddComponent(new AliHLTTPCOfflineTrackerComponent);
378   pHandler->AddComponent(new AliHLTTPCOfflineTrackerCalibComponent);
379   pHandler->AddComponent(new AliHLTTPCOfflineCalibrationComponent);
380   pHandler->AddComponent(new AliHLTTPCClusterHistoComponent);
381   pHandler->AddComponent(new AliHLTTPCHistogramHandlerComponent);
382   pHandler->AddComponent(new AliHLTTPCTrackHistoComponent);
383   pHandler->AddComponent(new AliHLTTPCTrackDumpComponent);
384   pHandler->AddComponent(new AliHLTTPCHWCFDataReverterComponent);
385   pHandler->AddComponent(new AliHLTTPCHWClusterTransformComponent);
386   pHandler->AddComponent(new AliHLTTPCCFComparisonComponent);
387   pHandler->AddComponent(new AliHLTTPCDataCheckerComponent);
388   pHandler->AddComponent(new AliHLTTPCHWCFEmulatorComponent);
389 //  pHandler->AddComponent(new AliHLTTPCHWCFConsistencyControlComponent);  //FIXME: Causes crash: https://savannah.cern.ch/bugs/?83677
390   pHandler->AddComponent(new AliHLTTPCDataCompressionComponent);
391   pHandler->AddComponent(new AliHLTTPCDataCompressionMonitorComponent);
392   pHandler->AddComponent(new AliHLTTPCDataCompressionFilterComponent);
393   return 0;
394 }
395
396 int AliHLTTPCAgent::GetHandlerDescription(AliHLTComponentDataType dt,
397                                           AliHLTUInt32_t spec,
398                                           AliHLTOUTHandlerDesc& desc) const
399 {
400   // see header file for class documentation
401
402   // raw data blocks to be fed into offline reconstruction
403   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
404     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
405     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
406     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
407         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
408       desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
409       return 1;
410     } else {
411       HLTWarning("handler can not process merged data from multiple ddls:"
412                  " min slice %d, max slice %d, min part %d, max part %d",
413                  slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
414                  part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
415       return 0;
416     }
417   }
418
419   // dump for {'CLUSTERS':'TPC '} blocks stored in a 'digit' file
420   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
421       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
422       return 1;
423   }
424
425   // define handlers for all blocks related to compression, flag if the
426   // cluster id blocks are existing, this will be used to decide
427   // whether to create the handler or not
428   // {'CLUSTRAW':'TPC '}
429   // {'HWCLUST1':'TPC '}
430   // {'REMCLSCM':'TPC '}
431   // {'CLSTRKCM':'TPC '}
432   // {'REMCLIDS':'TPC '}
433   // {'CLIDSTRK':'TPC '}
434   if (dt==AliHLTTPCDefinitions::RawClustersDataType() ||
435       dt==AliHLTTPCDefinitions::HWClustersDataType() ||
436       dt==AliHLTTPCDefinitions::RemainingClustersCompressedDataType() ||
437       dt==AliHLTTPCDefinitions::ClusterTracksCompressedDataType()) {
438       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
439       return 1;
440   }
441   if (dt==AliHLTTPCDefinitions::RemainingClusterIdsDataType() ||
442       dt==AliHLTTPCDefinitions::ClusterIdTracksDataType()) {
443       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
444       const_cast<AliHLTTPCAgent*>(this)->SetBit(kHaveCompressedClusterIdDataBlock);
445       return 1;
446   }
447
448   // {'CLMCINFO':'TPC '} 
449   if (dt==AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo) {
450       desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
451       return 1;
452   }
453
454   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
455   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
456       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
457       return 1;
458   }
459
460   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
461   // there is only one data block
462   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
463       desc=AliHLTOUTHandlerDesc(kChain, dt, GetModuleId());
464       return 1;
465   }
466   return 0;
467 }
468
469 AliHLTOUTHandler* AliHLTTPCAgent::GetOutputHandler(AliHLTComponentDataType dt,
470                                                    AliHLTUInt32_t /*spec*/)
471 {
472   // see header file for class documentation
473
474   // raw data blocks to be fed into offline reconstruction
475   if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC)) {
476     if (!fRawDataHandler) {
477       fRawDataHandler=new AliHLTTPCAgent::AliHLTTPCRawDataHandler;
478     }
479     return fRawDataHandler;
480   }
481
482   // dump for {'CLUSTERS':'TPC '}, stored in a file HLT.TPC.Clusters.root in HOMER format
483   if (dt==AliHLTTPCDefinitions::fgkClustersDataType) {
484     if (fClustersDataHandler==NULL)
485       fClustersDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-cluster-dump libHLTsim.so libAliHLTUtil.so");
486     return fClustersDataHandler;
487   }
488
489   // afterburner for {'TRAKSEGS':'TPC '} blocks to be converted to ESD format
490   // in a kChain HLTOUT handler
491   if (dt==AliHLTTPCDefinitions::fgkTrackSegmentsDataType) {
492     if (fTracksegsDataHandler==NULL)
493       fTracksegsDataHandler=new AliHLTOUTHandlerChain("chains=TPC-hltout-tracksegs-esd-converter");
494     return fTracksegsDataHandler;
495   }
496
497   // afterburner for {'TRACKS  ':'TPC '} block to be converted to ESD format
498   // there is only one data block
499   if (dt==AliHLTTPCDefinitions::fgkTracksDataType) {
500     return new AliHLTOUTHandlerChain("chains=TPC-hltout-tracks-esd-converter");
501   }
502
503   // monitoring of compressed data if cluster verification blocks exist
504   // {'REMCLIDS':'TPC '}
505   // {'CLIDSTRK':'TPC '}
506   // FIXME: needs to be commissioned
507   // if (dt==AliHLTTPCDefinitions::RawClustersDataType() ||
508   //     dt==AliHLTTPCDefinitions::HWClustersDataType() ||
509   //     dt==AliHLTTPCDefinitions::RemainingClustersCompressedDataType() ||
510   //     dt==AliHLTTPCDefinitions::ClusterTracksCompressedDataType() ||
511   //     dt==AliHLTTPCDefinitions::RemainingClusterIdsDataType() ||
512   //     dt==AliHLTTPCDefinitions::ClusterIdTracksDataType()) {
513   //   const char* arg="chains=TPC-hltout-compressionmonitor";
514   //   if (!TestBit(kHaveCompressedClusterIdDataBlock))
515   //     arg="chains=TPC-hltout-compressionmonitorpublisher";
516   //   if (!fCompressionMonitorHandler)
517   //     fCompressionMonitorHandler=new AliHLTOUTHandlerChain(arg);
518   //   return fCompressionMonitorHandler;
519   // }
520
521   return NULL;
522 }
523
524 int AliHLTTPCAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
525 {
526   // see header file for class documentation
527   if (pInstance==NULL) return -EINVAL;
528
529   if (pInstance==fRawDataHandler) {
530     delete fRawDataHandler;
531     fRawDataHandler=NULL;
532   }
533
534   if (pInstance==fTracksegsDataHandler) {
535     delete fTracksegsDataHandler;
536     fTracksegsDataHandler=NULL;
537   }
538
539   if (pInstance==fClustersDataHandler) {
540     delete fClustersDataHandler;
541     fClustersDataHandler=NULL;
542   }
543
544   if (pInstance==fCompressionMonitorHandler) {
545     delete fCompressionMonitorHandler;
546     fCompressionMonitorHandler=NULL;
547   }
548
549   return 0;
550 }
551
552 AliHLTTPCAgent::AliHLTTPCRawDataHandler::AliHLTTPCRawDataHandler()
553 {
554   // see header file for class documentation
555 }
556
557 AliHLTTPCAgent::AliHLTTPCRawDataHandler::~AliHLTTPCRawDataHandler()
558 {
559   // see header file for class documentation
560 }
561
562 int AliHLTTPCAgent::AliHLTTPCRawDataHandler::ProcessData(AliHLTOUT* pData)
563 {
564   // see header file for class documentation
565   if (!pData) return -EINVAL;
566   AliHLTComponentDataType dt=kAliHLTVoidDataType;
567   AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
568   int iResult=pData->GetDataBlockDescription(dt, spec);
569   if (iResult>=0) {
570     int slice=AliHLTTPCDefinitions::GetMinSliceNr(spec);
571     int part=AliHLTTPCDefinitions::GetMinPatchNr(spec);
572     if (slice==AliHLTTPCDefinitions::GetMaxSliceNr(spec) &&
573         part==AliHLTTPCDefinitions::GetMaxPatchNr(spec)) {
574       iResult=768;
575       if (part>1) iResult+=72+4*slice+(part-2);
576       else iResult+=2*slice+part;
577     } else {
578       HLTError("handler can not process merged data from multiple ddls:"
579                " min slice %d, max slice %d, min part %d, max part %d",
580                slice, AliHLTTPCDefinitions::GetMaxSliceNr(spec),
581                part, AliHLTTPCDefinitions::GetMaxPatchNr(spec));
582       iResult=-EBADMSG;
583     }
584   }
585   return iResult;
586 }