ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / TPCLib / comp / AliHLTTPCDataCompressionMonitorComponent.cxx
CommitLineData
76c437dc 1// $Id$
2//**************************************************************************
3//* This file is property of and copyright by the ALICE HLT Project *
4//* ALICE Experiment at CERN, All rights reserved. *
5//* *
6//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7//* for The ALICE HLT Project. *
8//* *
9//* Permission to use, copy, modify and distribute this software and its *
10//* documentation strictly for non-commercial purposes is hereby granted *
11//* without fee, provided that the above copyright notice appears in all *
12//* copies and that both the copyright notice and this permission notice *
13//* appear in the supporting documentation. The authors make no claims *
14//* about the suitability of this software for any purpose. It is *
15//* provided "as is" without express or implied warranty. *
16//**************************************************************************
17
18/// @file AliHLTTPCDataCompressionMonitorComponent.cxx
19/// @author Matthias Richter
20/// @date 2011-09-12
21/// @brief TPC component for monitoring of data compression
22///
23
24#include "AliHLTTPCDataCompressionMonitorComponent.h"
eb51a006 25#include "AliHLTTPCDataCompressionComponent.h"
f899e060 26#include "AliHLTTPCDataCompressionDecoder.h"
76c437dc 27#include "AliHLTTPCDefinitions.h"
28#include "AliHLTTPCHWCFData.h"
6776da52 29#include "AliHLTTPCDefinitions.h"
30#include "AliHLTTPCClusterDataFormat.h"
31#include "AliHLTTPCRawCluster.h"
32#include "AliHLTTPCTransform.h"
eb51a006 33#include "AliHLTTPCTrackGeometry.h"
779a5a62 34#include "AliHLTTPCHWCFSpacePointContainer.h"
a4fad4be 35#include "AliHLTErrorGuard.h"
bcddeeca 36#include "AliHLTComponentBenchmark.h"
16e6f752 37#include "AliHLTCDHWrapper.h"
6776da52 38#include "AliTPCclusterMI.h"
bc3adc1e 39#include "AliTPCROC.h"
76c437dc 40#include "TH1I.h"
779a5a62 41#include "TH1F.h"
bc3adc1e 42#include "TH1D.h"
76c437dc 43#include "TH2I.h"
69d38ee6 44#include "TH2F.h"
bc3adc1e 45#include "TH2D.h"
69d38ee6 46#include "TH3I.h"
47#include "TH3F.h"
bc3adc1e 48#include "TH3D.h"
49#include "TProfile.h"
76c437dc 50#include "TFile.h"
779a5a62 51#include "TObjArray.h"
a6267876 52#include "TList.h"
76c437dc 53#include <memory>
54
55ClassImp(AliHLTTPCDataCompressionMonitorComponent)
56
57AliHLTTPCDataCompressionMonitorComponent::AliHLTTPCDataCompressionMonitorComponent()
58 : AliHLTProcessor()
bcddeeca 59 , fpBenchmark(NULL)
60 , fpDecoder(NULL)
76c437dc 61 , fpHWClusterDecoder(NULL)
62 , fHistoHWCFDataSize(NULL)
63 , fHistoHWCFReductionFactor(NULL)
d938def0 64 , fHistoTotalReductionFactor(NULL)
76c437dc 65 , fHistoNofClusters(NULL)
bc3adc1e 66 , fHistoNofClustersReductionFactor(NULL)
a6267876 67 , fHistogramFile()
779a5a62 68 , fMonitoringContainer(NULL)
76c437dc 69 , fVerbosity(0)
70 , fFlags(0)
a6267876 71 , fPublishingMode(kPublishSeparate)
76c437dc 72{
73}
74
75AliHLTTPCDataCompressionMonitorComponent::~AliHLTTPCDataCompressionMonitorComponent()
76{
77 /// destructor
78}
79
80
81const char* AliHLTTPCDataCompressionMonitorComponent::GetComponentID()
82{
83 /// inherited from AliHLTComponent: id of the component
84 return "TPCDataCompressorMonitor";
85}
86
87
88void AliHLTTPCDataCompressionMonitorComponent::GetInputDataTypes( AliHLTComponentDataTypeList& tgtList)
89{
90 /// inherited from AliHLTComponent: list of data types in the vector reference
91 tgtList.clear();
92 tgtList.push_back(AliHLTTPCDefinitions::fgkHWClustersDataType);
93 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
94 tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType);
95 tgtList.push_back(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
96 tgtList.push_back(AliHLTTPCDefinitions::ClusterTracksCompressedDataType());
97}
98
99AliHLTComponentDataType AliHLTTPCDataCompressionMonitorComponent::GetOutputDataType()
100{
101 /// inherited from AliHLTComponent: output data type of the component.
102 return kAliHLTMultipleDataType;
103}
104
105int AliHLTTPCDataCompressionMonitorComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
106{
107 /// inherited from AliHLTComponent: multiple output data types of the component.
108 tgtList.clear();
109 tgtList.push_back(kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
110 return tgtList.size();
111}
112
113void AliHLTTPCDataCompressionMonitorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
114{
115 /// inherited from AliHLTComponent: output data size estimator
3a58d9f3 116 constBase=10000000;
76c437dc 117 inputMultiplier=1.0;
118}
119
120AliHLTComponent* AliHLTTPCDataCompressionMonitorComponent::Spawn()
121{
122 /// inherited from AliHLTComponent: spawn function.
123 return new AliHLTTPCDataCompressionMonitorComponent;
124}
125
126int AliHLTTPCDataCompressionMonitorComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
127 const AliHLTComponentBlockData* /*inputBlocks*/,
128 AliHLTComponentTriggerData& /*trigData*/,
129 AliHLTUInt8_t* /*outputPtr*/,
130 AliHLTUInt32_t& /*size*/,
131 AliHLTComponentBlockDataList& /*outputBlocks*/ )
132{
133 /// inherited from AliHLTProcessor: data processing
134 int iResult=0;
135
285aba17 136 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
137 if (!IsDataEvent(&eventType)) {
138 if (eventType==gkAliEventTypeEndOfRun && fPublishingMode!=kPublishOff) {
139 iResult=Publish(fPublishingMode);
140 }
141 return iResult;
142 }
76c437dc 143
bcddeeca 144 if (GetBenchmarkInstance()) {
145 GetBenchmarkInstance()->StartNewEvent();
146 GetBenchmarkInstance()->Start(0);
147 }
148
76c437dc 149 const AliHLTComponentBlockData* pDesc=NULL;
150 unsigned rawDataSize=0;
d938def0 151 unsigned rawEventSizeFromRCUtrailer=0;
76c437dc 152 unsigned hwclustersDataSize=0;
153 unsigned nofClusters=0;
69d38ee6 154 unsigned compDataSize=0;
155
a4fad4be 156 // check size of TPC raw data
76c437dc 157 for (pDesc=GetFirstInputBlock(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC);
158 pDesc!=NULL; pDesc=GetNextInputBlock()) {
159 fFlags|=kHaveRawData;
160 rawDataSize+=pDesc->fSize;
161 }
162
a4fad4be 163 // check size of HWCF data and add to the MonitoringContainer
76c437dc 164 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::fgkHWClustersDataType);
165 pDesc!=NULL; pDesc=GetNextInputBlock()) {
166 fFlags|=kHaveHWClusters;
779a5a62 167 // FIXME: the decoding can now be handled via the data container
16e6f752 168 AliHLTCDHWrapper header(pDesc->fPtr);
169 if (pDesc->fSize<=header.GetHeaderSize()) continue;
76c437dc 170 if (fpHWClusterDecoder) {
171 hwclustersDataSize+=pDesc->fSize;
172 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr);
16e6f752 173 pData+=header.GetHeaderSize();
174 if (fpHWClusterDecoder->Init(pData, pDesc->fSize-header.GetHeaderSize())<0 ||
175 (fpHWClusterDecoder->CheckVersion()<0 && (int)(pDesc->fSize-header.GetHeaderSize())>fpHWClusterDecoder->GetRCUTrailerSize())) {
76c437dc 176 HLTError("data block of type %s corrupted: can not decode format",
177 AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
178 } else {
179 nofClusters+=fpHWClusterDecoder->GetNumberOfClusters();
d938def0 180 if (fpHWClusterDecoder->GetRCUTrailer()) {
181 // first word of the RCU trailer contains the payload size in 32bit words
182 const AliHLTUInt32_t* pRCUTrailer=reinterpret_cast<const AliHLTUInt32_t*>(fpHWClusterDecoder->GetRCUTrailer());
183 AliHLTUInt32_t payloadSize=(*pRCUTrailer)&0x00ffffff;
16e6f752 184 rawEventSizeFromRCUtrailer+=header.GetHeaderSize()
d938def0 185 + payloadSize*sizeof(AliHLTUInt32_t)
186 + fpHWClusterDecoder->GetRCUTrailerSize();
187 }
76c437dc 188 }
189 }
779a5a62 190 if (fMonitoringContainer) {
191 fMonitoringContainer->AddRawData(pDesc);
192 }
76c437dc 193 }
194
2ef6ef75 195 if (fMonitoringContainer && fpDecoder) {
bcddeeca 196 if (GetBenchmarkInstance()) {
197 GetBenchmarkInstance()->Start(1);
198 }
199
779a5a62 200 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::RemainingClusterIdsDataType());
201 pDesc!=NULL; pDesc=GetNextInputBlock()) {
202 iResult=fMonitoringContainer->AddClusterIds(pDesc);
203 }
6776da52 204
779a5a62 205 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::ClusterIdTracksDataType());
206 pDesc!=NULL; pDesc=GetNextInputBlock()) {
207 iResult=fMonitoringContainer->AddClusterIds(pDesc);
208 }
209
f899e060 210 // read data
bcddeeca 211 AliHLTTPCDataCompressionDecoder& decoder=*fpDecoder;
212 decoder.Clear();
a4fad4be 213 bool bHaveRawClusters=false;
214 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::RawClustersDataType());
215 pDesc!=NULL; pDesc=GetNextInputBlock()) {
216 // Note: until r51411 and v5-01-Rev-03 the compressed cluster format was sent with data
217 // type {CLUSTRAW,TPC }, the version member indicated the actual type of data
14f37d68 218 // These data do not include the 0.5 shift in pad position, that's wht it has
219 // to be added in the unpacking. This is a very special case, this data type and
220 // data version==1 only occured in the early TPC data compression test runs with
221 // v5-01-Rev-01
222 if (pDesc->fSize<sizeof(AliHLTTPCRawClusterData)) continue;
223 const AliHLTTPCRawClusterData* clusterData = reinterpret_cast<const AliHLTTPCRawClusterData*>(pDesc->fPtr);
224 if (!clusterData) continue;
225 if (clusterData->fVersion==1) {
226 // compressed clusters without the pad shift
227 // data type {CLUSTRAW,TPC } with version==1
228 decoder.SetPadShift(0.5);
229 } else {
230 decoder.SetPadShift(0.0);
231 }
a4fad4be 232 bHaveRawClusters=true;
233 iResult=decoder.ReadClustersPartition(fMonitoringContainer->BeginRemainingClusterBlock(0, pDesc->fSpecification),
234 reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr),
235 pDesc->fSize,
236 pDesc->fSpecification);
237 if (iResult<0) {
238 HLTError("reading of partition clusters failed with error %d", iResult);
239 }
240 }
241
14f37d68 242 decoder.SetPadShift(0.0);
243
a4fad4be 244 if (!bHaveRawClusters) {
779a5a62 245 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
246 pDesc!=NULL; pDesc=GetNextInputBlock()) {
a4fad4be 247 iResult=decoder.ReadClustersPartition(fMonitoringContainer->BeginRemainingClusterBlock(0, pDesc->fSpecification),
248 reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr),
249 pDesc->fSize,
250 pDesc->fSpecification);
69d38ee6 251 compDataSize+=pDesc->fSize;
779a5a62 252 }
253
254 for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType());
255 pDesc!=NULL; pDesc=GetNextInputBlock()) {
f899e060 256 iResult=decoder.ReadTrackModelClustersCompressed(fMonitoringContainer->BeginTrackModelClusterBlock(0),
779a5a62 257 reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr),
258 pDesc->fSize,
259 pDesc->fSpecification);
69d38ee6 260 compDataSize+=pDesc->fSize;
779a5a62 261 }
a4fad4be 262 } else {
263 if (GetFirstInputBlock(AliHLTTPCDefinitions::RemainingClustersCompressedDataType()) ||
264 GetFirstInputBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType())) {
265 ALIHLTERRORGUARD(5, "conflicting data blocks, monitoring histograms already filled from raw cluster data, ignoring blocks of compressed partition and track clusters");
266 }
267 }
bcddeeca 268 if (GetBenchmarkInstance()) {
269 GetBenchmarkInstance()->Stop(1);
270 }
779a5a62 271
272 fMonitoringContainer->Clear();
eb51a006 273 }
274
d938def0 275 if ((fFlags&kHaveHWClusters)!=0 && (fFlags&kHaveRawData)!=0) {
285aba17 276 if (rawDataSize!=rawEventSizeFromRCUtrailer && rawEventSizeFromRCUtrailer>0) {
d938def0 277 HLTError("got different raw event size from raw data and rcu trailer: raw %d, rcu trailer %d", rawDataSize, rawEventSizeFromRCUtrailer);
278 }
279 }
280 if (rawDataSize==0)
281 rawDataSize=rawEventSizeFromRCUtrailer;
282
283 float hwcfratio=0;
76c437dc 284 float ratio=0;
d938def0 285 float totalratio=0;
286 if (hwclustersDataSize) {hwcfratio=(float)rawDataSize; hwcfratio/=hwclustersDataSize;}
69d38ee6 287 if (compDataSize) {ratio=(float)hwclustersDataSize; ratio/=compDataSize;}
d938def0 288 if (compDataSize) {totalratio=(float)rawDataSize; totalratio/=compDataSize;}
289 if (fHistoHWCFDataSize) fHistoHWCFDataSize ->Fill(rawDataSize/1024, hwclustersDataSize/1024);
290 if (fHistoHWCFReductionFactor) fHistoHWCFReductionFactor->Fill(rawDataSize/1024, hwcfratio);
291 if (fHistoTotalReductionFactor && nofClusters>0)
292 fHistoTotalReductionFactor->Fill(rawDataSize/1024, totalratio);
bc3adc1e 293 if (fHistoNofClusters) fHistoNofClusters ->Fill(rawDataSize/1024, nofClusters);
d938def0 294 if (fHistoNofClustersReductionFactor && nofClusters>0)
295 fHistoNofClustersReductionFactor ->Fill(nofClusters, ratio);
296 HLTInfo("raw data %d, hwcf data %d, comp data %d, ratio %f, %d clusters, total compression ratio %f\n", rawDataSize, hwclustersDataSize, compDataSize, ratio, nofClusters, totalratio);
76c437dc 297
a6267876 298 if (iResult>=0 && fPublishingMode!=kPublishOff) {
299 iResult=Publish(fPublishingMode);
300 }
301
bcddeeca 302 if (GetBenchmarkInstance()) {
303 GetBenchmarkInstance()->Stop(0);
2ef6ef75 304 GetBenchmarkInstance()->AddInput(compDataSize);
bcddeeca 305 HLTBenchmark("%s", GetBenchmarkInstance()->GetStatistics());
306 }
307
a6267876 308 return iResult;
309}
310
311int AliHLTTPCDataCompressionMonitorComponent::Publish(int mode)
312{
313 /// publish to output
bc3adc1e 314 // additional histograms derived from the main ones to publish
315 TObjArray *derivedHistos = new TObjArray();
316 derivedHistos->SetOwner(kTRUE);
a6267876 317
318 // FIXME: code needs to be optimized, maybe a bit to much new and delete for the
319 // moment, the data type might need adjustment
320 int iResult=0;
321 TObjArray* pArray=mode==kPublishArray?(new TObjArray):NULL;
322 TList* pList=mode==kPublishList?(new TList):NULL;
323 if (mode==kPublishSeparate) {
324 if (fHistoHWCFDataSize) PushBack(fHistoHWCFDataSize , kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
325 if (fHistoHWCFReductionFactor) PushBack(fHistoHWCFReductionFactor, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
326 if (fHistoNofClusters) PushBack(fHistoNofClusters , kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
bc3adc1e 327 if (fHistoNofClustersReductionFactor) PushBack(fHistoNofClustersReductionFactor, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
d938def0 328 if (fHistoTotalReductionFactor) PushBack(fHistoTotalReductionFactor, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
a6267876 329 } else if (pList) {
330 if (fHistoHWCFDataSize) pList->Add(fHistoHWCFDataSize->Clone());
331 if (fHistoHWCFReductionFactor) pList->Add(fHistoHWCFReductionFactor->Clone());
332 if (fHistoNofClusters) pList->Add(fHistoNofClusters->Clone());
bc3adc1e 333 if (fHistoNofClustersReductionFactor) pList->Add(fHistoNofClustersReductionFactor->Clone());
d938def0 334 if (fHistoTotalReductionFactor) pList->Add(fHistoTotalReductionFactor->Clone());
a6267876 335 } else if (pArray) {
336 if (fHistoHWCFDataSize) pArray->Add(fHistoHWCFDataSize->Clone());
337 if (fHistoHWCFReductionFactor) pArray->Add(fHistoHWCFReductionFactor->Clone());
338 if (fHistoNofClusters) pArray->Add(fHistoNofClusters->Clone());
bc3adc1e 339 if (fHistoNofClustersReductionFactor) pArray->Add(fHistoNofClustersReductionFactor->Clone());
d938def0 340 if (fHistoTotalReductionFactor) pArray->Add(fHistoTotalReductionFactor->Clone());
a6267876 341 }
342
bc3adc1e 343
a6267876 344 if (fMonitoringContainer) {
345 static const char* searchIds[] = {"fHistograms", "fHistograms2D", "fHistograms3D", NULL};
346 const char** searchId=searchIds;
347 while (*searchId && iResult>=0) {
348 const TObject* o=fMonitoringContainer->FindObject(*searchId);
349 if (o) {
350 const TObjArray* histograms=dynamic_cast<const TObjArray*>(o);
351 if (histograms) {
352 for (int i=0; i<histograms->GetEntriesFast() && iResult>=0; i++) {
353 if (!histograms->At(i)) continue;
bc3adc1e 354 ///
355 TString name=histograms->At(i)->GetName();
356 if( (name.CompareTo(fgkHistogramDefinitions2D[kHistogramQMaxSector].fName)==0) ||
357 (name.CompareTo(fgkHistogramDefinitions2D[kHistogramSigmaY2Sector].fName)==0) ||
358 (name.CompareTo(fgkHistogramDefinitions2D[kHistogramSigmaZ2Sector].fName)==0) ){
359 TH2F *h1=(TH2F*)histograms->At(i);
360 TProfile *h2 = (TProfile*)(h1->ProfileX());
361 derivedHistos->Add(h2);
362 }
363 if( name.CompareTo(fgkHistogramDefinitions3D[kHistogramPadrowPadSector].fName)==0) {
364 TH3F *h1=(TH3F*)histograms->At(i);
365 for (int j=1; j<=72; j++) {
366 h1->GetXaxis()->SetRange(j,j);
367 TString histoname = Form("zy_%d",j);
368 TH2F *h2 = (TH2F*)h1->Project3D(histoname.Data());
369 derivedHistos->Add(h2);
370 }
371 }
372 ///
a6267876 373 if (mode==kPublishSeparate) {
374 iResult=PushBack(histograms->At(i), kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
375 } else if (pList) {
376 pList->Add(histograms->At(i)->Clone());
377 } else if (pArray) {
378 pArray->Add(histograms->At(i)->Clone());
379 }
380 }
bc3adc1e 381 for (int i=0; i<derivedHistos->GetEntriesFast() && iResult>=0; i++) {
382 if (mode==kPublishSeparate) {
383 iResult=PushBack(derivedHistos->At(i), kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC);
384 } else if (pList) {
385 pList->Add(derivedHistos->At(i)->Clone());
386 } else if (pArray) {
387 pArray->Add(derivedHistos->At(i)->Clone());
388 }
389 }
a6267876 390 }
391 } else {
392 HLTError("failed to find object \"%s\"", *searchId);
393 }
394 searchId++;
395 }
396 }
397
398 if (pArray) {
399 iResult=PushBack(pArray, kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC);
400 pArray->SetOwner(kTRUE);
401 delete pArray;
402 pArray=NULL;
403 }
404 if (pList) {
405 iResult=PushBack(pList, kAliHLTDataTypeTObject|kAliHLTDataOriginTPC);
406 pList->SetOwner(kTRUE);
407 delete pList;
408 pList=NULL;
409 }
76c437dc 410 return iResult;
411}
412
413int AliHLTTPCDataCompressionMonitorComponent::DoInit( int argc, const char** argv )
414{
415 /// inherited from AliHLTComponent: component initialisation and argument scan.
416 int iResult=0;
417
418 // component configuration
419 //Stage 1: default initialization.
420 //Default values.
421 fFlags=0;
422
423 //Stage 2: OCDB.
424 TString cdbPath("HLT/ConfigTPC/");
425 cdbPath += GetComponentID();
426 //
427 // iResult = ConfigureFromCDBTObjString(cdbPath);
428 // if (iResult < 0)
429 // return iResult;
430
431 //Stage 3: command line arguments.
432 if (argc && (iResult = ConfigureFromArgumentString(argc, argv)) < 0)
433 return iResult;
434
435 std::auto_ptr<AliHLTTPCHWCFData> hwClusterDecoder(new AliHLTTPCHWCFData);
779a5a62 436 std::auto_ptr<AliDataContainer> dataContainer(new AliDataContainer);
76c437dc 437
438 std::auto_ptr<TH2I> histoHWCFDataSize(new TH2I("HWCFDataSize",
439 "HW ClusterFinder Size",
440 100, 0., 80000., 100, 0., 80000.));
441 if (histoHWCFDataSize.get()) {
442 TAxis* xaxis=histoHWCFDataSize->GetXaxis();
bc3adc1e 443 if (xaxis) xaxis->SetTitle("raw data size [kB]");
76c437dc 444 TAxis* yaxis=histoHWCFDataSize->GetYaxis();
69d38ee6 445 if (yaxis) yaxis->SetTitle("compressed data size [kb]");
76c437dc 446 }
447
448 std::auto_ptr<TH2I> histoHWCFReductionFactor(new TH2I("HWCFReductionFactor",
d938def0 449 "Data reduction HW ClusterFinder vs. raw data size",
450 100, 0., 80000., 30, 0., 3.));
76c437dc 451 if (histoHWCFReductionFactor.get()) {
452 TAxis* xaxis=histoHWCFReductionFactor->GetXaxis();
bc3adc1e 453 if (xaxis) xaxis->SetTitle("raw data size [kB]");
76c437dc 454 TAxis* yaxis=histoHWCFReductionFactor->GetYaxis();
455 if (yaxis) yaxis->SetTitle("reduction factor");
456 }
457
d938def0 458 std::auto_ptr<TH2I> histoTotalReductionFactor(new TH2I("TotalReductionFactor",
459 "Total reduction Factor vs. raw data size",
460 100, 0., 80000., 100, 0., 10.));
461 if (histoTotalReductionFactor.get()) {
462 TAxis* xaxis=histoTotalReductionFactor->GetXaxis();
463 if (xaxis) xaxis->SetTitle("raw data size [kB]");
464 TAxis* yaxis=histoTotalReductionFactor->GetYaxis();
465 if (yaxis) yaxis->SetTitle("reduction factor");
466 }
467
76c437dc 468 std::auto_ptr<TH2I> histoNofClusters(new TH2I("NofClusters",
469 "Number of HLT TPC clusters",
3b5a8606 470 100, 0., 80000., 500, 0., 3000000.));
76c437dc 471 if (histoNofClusters.get()) {
472 TAxis* xaxis=histoNofClusters->GetXaxis();
bc3adc1e 473 if (xaxis) xaxis->SetTitle("raw data size [kB]");
76c437dc 474 TAxis* yaxis=histoNofClusters->GetYaxis();
69d38ee6 475 if (yaxis) yaxis->SetTitle("N. of clusters");
76c437dc 476 }
477
362b09a1 478 std::auto_ptr<TH2I> histoNofClustersReductionFactor(new TH2I("ReductionFactorVsNofClusters",
479 "Reduction Factor vs. Number of HLT TPC clusters",
3b5a8606 480 500, 0., 3000000., 100, 0., 10.));
bc3adc1e 481 if (histoNofClustersReductionFactor.get()) {
482 TAxis* xaxis=histoNofClustersReductionFactor->GetXaxis();
483 if (xaxis) xaxis->SetTitle("N. of clusters");
484 TAxis* yaxis=histoNofClustersReductionFactor->GetYaxis();
485 if (yaxis) yaxis->SetTitle("reduction factor");
486 }
487
bcddeeca 488 std::auto_ptr<AliHLTComponentBenchmark> benchmark(new AliHLTComponentBenchmark);
489 if (benchmark.get()) {
490 benchmark->SetTimer(0,"total");
491 benchmark->SetTimer(1,"clusterdecoding");
492 } else {
493 return -ENOMEM;
494 }
495
496 auto_ptr<AliHLTTPCDataCompressionDecoder> decoder(new AliHLTTPCDataCompressionDecoder);
497 if (!decoder.get()) {
498 return -ENOMEM;
499 }
500
501
a6267876 502 fHistoHWCFDataSize=histoHWCFDataSize.release();
503 fHistoHWCFReductionFactor=histoHWCFReductionFactor.release();
d938def0 504 fHistoTotalReductionFactor=histoTotalReductionFactor.release();
a6267876 505 fHistoNofClusters=histoNofClusters.release();
bc3adc1e 506 fHistoNofClustersReductionFactor=histoNofClustersReductionFactor.release();
76c437dc 507
508 fpHWClusterDecoder=hwClusterDecoder.release();
779a5a62 509 fMonitoringContainer=dataContainer.release();
bcddeeca 510 fpBenchmark=benchmark.release();
511 fpDecoder=decoder.release();
76c437dc 512
513 return iResult;
514}
515
516int AliHLTTPCDataCompressionMonitorComponent::DoDeinit()
517{
518 /// inherited from AliHLTComponent: component cleanup
519 int iResult=0;
520
bcddeeca 521 if (fpBenchmark) delete fpBenchmark; fpBenchmark=NULL;
522 if (fpDecoder) delete fpDecoder;
523 fpDecoder=NULL;
76c437dc 524 if (fpHWClusterDecoder) delete fpHWClusterDecoder;
525 fpHWClusterDecoder=NULL;
526
527 if (!fHistogramFile.IsNull()) {
528 TFile out(fHistogramFile, "RECREATE");
529 if (!out.IsZombie()) {
530 out.cd();
531 if (fHistoHWCFDataSize) fHistoHWCFDataSize->Write();
532 if (fHistoHWCFReductionFactor) fHistoHWCFReductionFactor->Write();
d938def0 533 if (fHistoTotalReductionFactor) fHistoTotalReductionFactor->Write();
76c437dc 534 if (fHistoNofClusters) fHistoNofClusters->Write();
bc3adc1e 535 if (fHistoNofClustersReductionFactor) fHistoNofClustersReductionFactor->Write();
779a5a62 536 if (fMonitoringContainer) {
69d38ee6 537 const TObject* o1=fMonitoringContainer->FindObject("fHistograms");
538 const TObject* o2=fMonitoringContainer->FindObject("fHistograms2D");
539 const TObject* o3=fMonitoringContainer->FindObject("fHistograms3D");
540 if (o1) o1->Write();
541 if (o2) o2->Write();
542 if (o3) o3->Write();
779a5a62 543 }
76c437dc 544 out.Close();
545 }
546 }
547 if (fHistoHWCFDataSize) delete fHistoHWCFDataSize;
548 fHistoHWCFDataSize=NULL;
549 if (fHistoHWCFReductionFactor) delete fHistoHWCFReductionFactor;
550 fHistoHWCFReductionFactor=NULL;
d938def0 551 if (fHistoTotalReductionFactor) delete fHistoTotalReductionFactor;
552 fHistoTotalReductionFactor=NULL;
76c437dc 553 if (fHistoNofClusters) delete fHistoNofClusters;
554 fHistoNofClusters=NULL;
bc3adc1e 555 if (fHistoNofClustersReductionFactor) delete fHistoNofClustersReductionFactor;
556 fHistoNofClustersReductionFactor=NULL;
9b2c9b8b 557 if (fMonitoringContainer) {
558 fMonitoringContainer->Clear();
559 delete fMonitoringContainer;
560 }
561 fMonitoringContainer=NULL;
562
76c437dc 563
564 return iResult;
565}
566
567int AliHLTTPCDataCompressionMonitorComponent::ScanConfigurationArgument(int argc, const char** argv)
568{
569 /// inherited from AliHLTComponent: argument scan
570 int iResult=0;
571 if (argc<1) return 0;
572 int bMissingParam=0;
573 int i=0;
574 TString argument=argv[i];
575
576 do {
577 // -histogram-file
578 if (argument.CompareTo("-histogram-file")==0) {
579 if ((bMissingParam=(++i>=argc))) break;
580 fHistogramFile=argv[i++];
a6267876 581 return i;
582 }
583 // -publishing-mode
584 if (argument.CompareTo("-publishing-mode")==0) {
585 if ((bMissingParam=(++i>=argc))) break;
586 TString option=argv[i++];
587 if (option.CompareTo("off")==0) fPublishingMode=kPublishOff ;
588 else if (option.CompareTo("separate")==0) fPublishingMode=kPublishSeparate;
589 else if (option.CompareTo("list")==0) fPublishingMode=kPublishList ;
590 else if (option.CompareTo("array")==0) fPublishingMode=kPublishArray ;
591 else {
592 HLTError("invalid option \"%s\" for argument \"%s\", expecting 'off', 'separate', 'list', or 'array'", option.Data(), argument.Data());
593 return -EPROTO;
594 }
595 return i;
76c437dc 596 }
597 } while (0); // using do-while only to have break available
598
599 if (bMissingParam) {
600 HLTError("missing parameter for argument %s", argument.Data());
601 iResult=-EPROTO;
602 }
603
604 return iResult;
605}
6776da52 606
779a5a62 607AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::AliDataContainer()
69d38ee6 608 : fHistograms(new TObjArray)
609 , fHistograms2D(new TObjArray)
610 , fHistograms3D(new TObjArray)
779a5a62 611 , fHistogramPointers()
69d38ee6 612 , fHistogram2DPointers()
613 , fHistogram3DPointers()
779a5a62 614 , fRemainingClusterIds()
615 , fTrackModelClusterIds()
616 , fCurrentClusterIds(NULL)
617 , fRawData(NULL)
362b09a1 618 , fCurrentCluster()
69d38ee6 619 , fSector(-1)
779a5a62 620 , fBegin()
d938def0 621 , fMaxSigmaY2Scaled((0x1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fBitLength)-1)
622 , fMaxSigmaZ2Scaled((0x1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fBitLength)-1)
779a5a62 623{
624 /// constructor
362b09a1 625 memset(&fCurrentCluster, 0, sizeof(AliHLTTPCRawCluster));
779a5a62 626 if (fHistograms) {
627 fHistograms->SetOwner(kTRUE);
628 fHistogramPointers.resize(kNumberOfHistograms, NULL);
629 for (const AliHistogramDefinition* definition=fgkHistogramDefinitions;
630 definition->fName!=NULL; definition++) {
bc3adc1e 631 fHistogramPointers[definition->fId]=new TH1D(definition->fName,
779a5a62 632 definition->fTitle,
633 definition->fBins,
634 definition->fLowerBound,
635 definition->fUpperBound
636 );
d938def0 637 if (fHistogramPointers[definition->fId]) {
638 fHistogramPointers[definition->fId]->SetOption(definition->fDrawOptions);
779a5a62 639 fHistograms->AddAt(fHistogramPointers[definition->fId], definition->fId);
d938def0 640 }
779a5a62 641 }
642 }
69d38ee6 643 ///
644 if (fHistograms2D) {
645 fHistograms2D->SetOwner(kTRUE);
646 fHistogram2DPointers.resize(kNumberOfHistograms2D, NULL);
647 for (const AliHistogramDefinition2D* definition=fgkHistogramDefinitions2D;
648 definition->fName!=NULL; definition++) {
bc3adc1e 649 fHistogram2DPointers[definition->fId]=new TH2D(definition->fName,
69d38ee6 650 definition->fTitle,
651 definition->fBinsX,
652 definition->fLowerBoundX,
653 definition->fUpperBoundX,
654 definition->fBinsY,
655 definition->fLowerBoundY,
656 definition->fUpperBoundY
657 );
d938def0 658 if (fHistogram2DPointers[definition->fId]) {
659 fHistogram2DPointers[definition->fId]->SetOption(definition->fDrawOptions);
69d38ee6 660 fHistograms2D->AddAt(fHistogram2DPointers[definition->fId], definition->fId);
d938def0 661 }
69d38ee6 662 }
663 }
664 ///
665 if (fHistograms3D) {
666 fHistograms3D->SetOwner(kTRUE);
667 fHistogram3DPointers.resize(kNumberOfHistograms3D, NULL);
668 for (const AliHistogramDefinition3D* definition=fgkHistogramDefinitions3D;
669 definition->fName!=NULL; definition++) {
bc3adc1e 670 fHistogram3DPointers[definition->fId]=new TH3D(definition->fName,
69d38ee6 671 definition->fTitle,
672 definition->fBinsX,
673 definition->fLowerBoundX,
674 definition->fUpperBoundX,
675 definition->fBinsY,
676 definition->fLowerBoundY,
677 definition->fUpperBoundY,
678 definition->fBinsZ,
679 definition->fLowerBoundZ,
680 definition->fUpperBoundZ
681 );
d938def0 682 if (fHistogram3DPointers[definition->fId]) {
683 fHistogram3DPointers[definition->fId]->SetOption(definition->fDrawOptions);
69d38ee6 684 fHistograms3D->AddAt(fHistogram3DPointers[definition->fId], definition->fId);
d938def0 685 }
69d38ee6 686 }
687 }
688
779a5a62 689}
690
691const AliHLTTPCDataCompressionMonitorComponent::AliHistogramDefinition AliHLTTPCDataCompressionMonitorComponent::fgkHistogramDefinitions[] = {
d938def0 692 {kHistogramPadrow, "padrow" , "padrow; padrow; counts" , 160, 0., 160., ""},
693 {kHistogramHWCFPad, "hwcfpad" , "hwcfpad; pad; counts" , 280, 0., 140., ""},
694 {kHistogramPad, "pad" , "pad; pad; counts" , 280, 0., 140., ""},
695 {kHistogramTime, "timebin" , "timebin; time; counts" , 1024, 0., 1024., ""},
696 {kHistogramSigmaY2, "sigmaY2" , "sigmaY2; #sigma_{Y}^{2}; counts" , 100, 0., 1., ""},
697 {kHistogramSigmaZ2, "sigmaZ2" , "sigmaZ2; #sigma_{Z}^{2}; counts" , 100, 0., 1., ""},
698 {kHistogramCharge, "charge" , "charge; charge; counts" , 1024, 0., 65536., ""},
699 {kHistogramQMax, "qmax" , "qmax; Q_{max}; counts" , 128, 0., 1024., ""},
700 {kHistogramDeltaPadrow, "d_padrow" , "d_padrow; #Delta padrow; counts" , 1000, -1., 1., ""},
701 {kHistogramDeltaPad, "d_pad" , "d_pad; #Delta pad; counts" , 1000, -1., 1., ""},
702 {kHistogramDeltaTime, "d_time" , "d_time; #Delta time; counts" , 1000, -1., 1., ""},
703 {kHistogramDeltaSigmaY2, "d_sigmaY2", "d_sigmaY2; #Delta #sigma_{Y}^{2}; counts", 1000, -1., 1., ""},
704 {kHistogramDeltaSigmaZ2, "d_sigmaZ2", "d_sigmaZ2; #Delta #sigma_{Z}^{2}; counts", 1000, -1., 1., ""},
705 {kHistogramDeltaCharge, "d_charge" , "d_charge; #Delta charge" , 1000, -1., 1., ""},
706 {kHistogramDeltaQMax, "d_qmax" , "d_qmax; #Delta Q_{max}" , 1000, -1., 1., ""},
707 {kHistogramOutOfRange, "ResError" , "Residual Error; padrow; counts" , 159, 0., 159., ""},
708 {kNumberOfHistograms, NULL, NULL, 0,0.,0., NULL}
779a5a62 709};
710
d938def0 711const AliHLTTPCDataCompressionMonitorComponent::AliHistogramDefinition2D AliHLTTPCDataCompressionMonitorComponent::fgkHistogramDefinitions2D[] = {
712 {kHistogramQMaxSector, "qmaxsector" , "qmaxsector; sector; Q_{max}" , 72, 0., 72., 1024, 0., 1024., "colz"},
713 {kHistogramSigmaY2Sector, "sigmaY2sector", "sigmaY2sector; sector; #sigma_{Y}^{2}" , 72, 0., 72., 100, 0., 1., "colz"},
714 {kHistogramSigmaZ2Sector, "sigmaZ2sector", "sigmaZ2sector; sector; #sigma_{Z}^{2}" , 72, 0., 72., 100, 0., 1., "colz"},
715 {kHistogramXYA, "XYA", "XY - A side; X[cm]; Y[cm]" , 100,-300., 300., 100,-300., 300., "colz"},
716 {kHistogramXYC, "XYC", "XY - C side; X[cm]; Y[cm]" , 100,-300., 300., 100,-300., 300., "colz"},
717 {kNumberOfHistograms2D, NULL, NULL, 0,0.,0., 0,0.,0., NULL}
718};
69d38ee6 719
d938def0 720const AliHLTTPCDataCompressionMonitorComponent::AliHistogramDefinition3D AliHLTTPCDataCompressionMonitorComponent::fgkHistogramDefinitions3D[] = {
721 {kHistogramPadrowPadSector,"padrowpadsector","padrowpadsector; sector; pad;padrow", 72,0.,72., 140,0.,140., 159,0.,159., ""},
722 {kNumberOfHistograms3D, NULL, NULL, 0,0.,0., 0,0.,0., 0,0.,0., NULL}
723};
69d38ee6 724
779a5a62 725AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::~AliDataContainer()
726{
727 /// dectructor
728 if (fRawData) delete fRawData;
729 if (fHistograms) delete fHistograms;
69d38ee6 730 if (fHistograms2D) delete fHistograms2D;
731 if (fHistograms3D) delete fHistograms3D;
779a5a62 732}
733
bcddeeca 734AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::iterator& AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::BeginPartitionClusterBlock(int /*count*/, AliHLTUInt32_t specification)
779a5a62 735{
736 /// iterator of remaining clusters block of specification
737 AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(specification);
738 AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(specification);
739 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
740 if (index<fRemainingClusterIds.size())
741 fCurrentClusterIds=&fRemainingClusterIds[index];
742 else
743 fCurrentClusterIds=NULL;
744 fBegin=iterator(this);
779a5a62 745 return fBegin;
746}
747
748AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::iterator& AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::BeginTrackModelClusterBlock(int /*count*/)
749{
750 /// iterator of track model clusters
751 if (fTrackModelClusterIds.fIds && fTrackModelClusterIds.fSize>0)
752 fCurrentClusterIds=&fTrackModelClusterIds;
753 else
754 fCurrentClusterIds=NULL;
755 fBegin=iterator(this);
779a5a62 756 return fBegin;
757}
758
779a5a62 759int AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::AddRawData(const AliHLTComponentBlockData* pDesc)
760{
362b09a1 761 /// add raw data bloack
762 int iResult=0;
779a5a62 763 if (pDesc->fDataType==AliHLTTPCDefinitions::HWClustersDataType()) {
764 if (!fRawData) fRawData=new AliHLTTPCHWCFSpacePointContainer(AliHLTTPCHWCFSpacePointContainer::kModeCreateMap);
765 if (!fRawData) return -ENOMEM;
362b09a1 766 if ((iResult=fRawData->AddInputBlock(pDesc))<0) return iResult;
767 AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* pSpacePointGrid=AliHLTTPCHWCFSpacePointContainer::AllocateIndexGrid();
768 if (pSpacePointGrid) {
769 fRawData->PopulateAccessGrid(pSpacePointGrid, pDesc->fSpecification);
770 fRawData->SetSpacePointPropertyGrid(pDesc->fSpecification, pSpacePointGrid);
771 }
772 return 0;
779a5a62 773 }
774 return -ENODATA;
775}
776
777int AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::AddClusterIds(const AliHLTComponentBlockData* pDesc)
778{
779 /// add cluster id block for remaining or track model clusters
780 if (!pDesc) return -EINVAL;
781 if (pDesc->fDataType==AliHLTTPCDefinitions::ClusterIdTracksDataType()) {
782 fTrackModelClusterIds.fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
783 fTrackModelClusterIds.fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
784 return 0;
785 }
786 if (pDesc->fDataType==AliHLTTPCDefinitions::RemainingClusterIdsDataType()) {
787 AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
788 AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
789 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
790 if (fRemainingClusterIds.size()<=index) {
791 if ((int)fRemainingClusterIds.size()<AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches()) {
792 fRemainingClusterIds.resize(AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches());
793 } else {
794 fRemainingClusterIds.resize(index+1);
795 }
796 }
797 fRemainingClusterIds[index].fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
798 fRemainingClusterIds[index].fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
799 return 0;
800 }
801 return -ENODATA;
802}
803
804AliHLTUInt32_t AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::GetClusterId(int clusterNo) const
805{
806 /// get the cluster id from the current cluster id block (optional)
807 if (!fCurrentClusterIds ||
6b6242a8 808 clusterNo<0 ||
779a5a62 809 (int)fCurrentClusterIds->fSize<=clusterNo)
810 return kAliHLTVoidDataSpec;
811 return fCurrentClusterIds->fIds[clusterNo];
812}
813
362b09a1 814AliHLTUInt32_t AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FindNearestCluster(int slice, int partition, const AliHLTTPCRawCluster& cluster) const
815{
816 /// get the cluster id of the nearest original cluster
817 if (!fRawData) return kAliHLTVoidDataSpec;
818 AliHLTUInt32_t key=AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, partition, partition);
819 // FIXME: AliHLTIndexGrid::Index is not declared const
820 AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* pGrid=const_cast<AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid*>(fRawData->GetSpacePointPropertyGrid(key));
821 if (!pGrid) return kAliHLTVoidDataSpec;
822 AliHLTUInt32_t clusterId=kAliHLTVoidDataSpec;
823 // search a 4x4 matrix out of the 9x9 matrix around the cell addressed by
824 // pad and time
825 float padrow=(float)cluster.GetPadRow()-AliHLTTPCTransform::GetFirstRow(partition);
826 float pad=cluster.GetPad();
827 float time=cluster.GetTime();
828 float minr2=-1.;
829 const float padpitch=AliHLTTPCTransform::GetPadPitchWidth(partition);
830 const float zwidth=AliHLTTPCTransform::GetZWidth();
831 float maxDeltaPad=AliHLTTPCDefinitions::GetMaxClusterDeltaPad();
832 float maxDeltaTime=AliHLTTPCDefinitions::GetMaxClusterDeltaTime();
833 int rowindex=pGrid->GetXIndex(padrow);
834 int padstartindex=pGrid->GetYIndex(pad);
835 int timestartindex=pGrid->GetZIndex(time);
836 int cellindex=pGrid->Index(rowindex, padstartindex, timestartindex);
837 float centerpad=pGrid->GetCenterY(cellindex);
838 float centertime=pGrid->GetCenterZ(cellindex);
839 if ((TMath::Abs(centerpad-pad)>maxDeltaPad && pad>0.) ||
840 (TMath::Abs(centertime-time)>maxDeltaTime && time>0.)) {
841 ALIHLTERRORGUARD(20, "invalid pad center calculation, please check dimensions if dimensions of index grid match the maximum possible deviation");
842 }
843
844 int paddirection=1;
845 int timedirection=1;
846 if (centerpad>pad) paddirection=-1;
847 if (centertime>time) timedirection=-1;
848 for (int padcount=0, padindex=padstartindex; padcount<2; padcount++, padindex+=paddirection) {
849 if (padindex<0) continue;
850 if (padindex>=pGrid->GetDimensionY()) break;
851 for (int timecount=0, timeindex=timestartindex; timecount<2; timecount++, timeindex+=timedirection) {
852 if (timeindex<0) continue;
853 if (timeindex>=pGrid->GetDimensionZ()) break;
854 cellindex=pGrid->Index(rowindex, padindex, timeindex);
855 float cellpad=pGrid->GetCenterY(cellindex);
856 float celltime=pGrid->GetCenterZ(cellindex);
857 for (AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid::iterator& cl=pGrid->begin((float)padrow, cellpad, celltime);
858 cl!=pGrid->end(); cl++) {
859 if (cl.Data().fTrackId>=0) continue;
860 if (fRawData->GetCharge(cl.Data().fId)!=cluster.GetCharge() ||
861 fRawData->GetQMax(cl.Data().fId)!=cluster.GetQMax()) continue;
862 if (TMath::Abs(padrow-fRawData->GetX(cl.Data().fId))>=1.) {
863 HLTError("slice %d, partition %d, cluster 0x%08x: mismatch on padrow: %f vs. cluster %f", slice, partition, cl.Data().fId, padrow, fRawData->GetX(cl.Data().fId));
864 continue;
865 }
866 float clusterpad=fRawData->GetY(cl.Data().fId);
867 float clustertime=fRawData->GetZ(cl.Data().fId);
868 clusterpad-=pad;
869 clusterpad*=padpitch;
870 clustertime-=time;
871 clustertime*=zwidth;
872 float r2=clusterpad*clusterpad+clustertime*clustertime;
873 if (minr2<0. || r2<minr2) {
874 clusterId=cl.Data().fId;
875 cl.Data().fTrackId=1;
876 minr2=r2;
877 }
878 }
879 }
880 }
881 return clusterId;
882}
883
884void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillPadRow(int row, int slice, AliHLTUInt32_t /*clusterId*/)
779a5a62 885{
886 /// fill padrow histogram
887 unsigned index=kHistogramPadrow;
362b09a1 888 fCurrentCluster.SetPadRow(row);
69d38ee6 889 // the inner sectors consist of readout partitions 0 and 1, if the row
890 // is smaller than first row of readout partition 2, its an inner sector
891 if (row<AliHLTTPCTransform::GetFirstRow(2)) {
892 fSector = slice;
893 } else {
894 fSector = slice+AliHLTTPCTransform::GetNSlice();
895 }
779a5a62 896 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
897 fHistogramPointers[index]->Fill(row);
779a5a62 898}
899
362b09a1 900void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillPad(float pad, AliHLTUInt32_t /*clusterId*/)
779a5a62 901{
902 /// fill pad histogram
362b09a1 903 fCurrentCluster.SetPad(pad);
904 int currentRow=fCurrentCluster.GetPadRow();
779a5a62 905 unsigned index=kHistogramPad;
906 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
907 fHistogramPointers[index]->Fill(pad);
69d38ee6 908
909 index=kHistogramPadrowPadSector;
910 if (index<fHistogram3DPointers.size() && fHistogram3DPointers[index]!=NULL)
362b09a1 911 fHistogram3DPointers[index]->Fill(fSector,pad,currentRow);
bc3adc1e 912
913 AliTPCROC *roc=AliTPCROC::Instance();
bcddeeca 914 if (roc) {
f4626c32 915 Float_t pos[3]={0.,0.,0.};
14f37d68 916 roc->GetPositionGlobal(fSector, fSector>35?currentRow-63:currentRow, (int)pad, pos);
4201513f 917 if (fSector<=17 || (fSector>=36&&fSector<=53))
918 //Sectors 0 to 17 and 36 to 53 are on the A side, sectors 18 to 35 and 54 to 71 are on the C side.
919 {
920 index=kHistogramXYA;
921 if (index<fHistogram2DPointers.size() && fHistogram2DPointers[index]!=NULL)
922 fHistogram2DPointers[index]->Fill(pos[0],pos[1]);
923 } else {
924 index=kHistogramXYC;
925 if (index<fHistogram2DPointers.size() && fHistogram2DPointers[index]!=NULL)
926 fHistogram2DPointers[index]->Fill(pos[0],pos[1]);
927 }
bcddeeca 928 }
4201513f 929
779a5a62 930}
931
362b09a1 932void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillTime(float time, AliHLTUInt32_t /*clusterId*/)
779a5a62 933{
934 /// fill pad histogram
362b09a1 935 fCurrentCluster.SetTime(time);
779a5a62 936 unsigned index=kHistogramTime;
937 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
938 fHistogramPointers[index]->Fill(time);
779a5a62 939}
940
362b09a1 941void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillSigmaY2(float sigmaY2, AliHLTUInt32_t /*clusterId*/, int partition)
779a5a62 942{
943 /// fill sigmaY2 histogram
362b09a1 944 fCurrentCluster.SetSigmaY2(sigmaY2);
779a5a62 945 unsigned index=kHistogramSigmaY2;
ac30bb87 946 /// take account for different pad widths
947 float weight=AliHLTTPCTransform::GetPadPitchWidth(partition);
779a5a62 948 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
ac30bb87 949 fHistogramPointers[index]->Fill(sigmaY2*weight*weight);
69d38ee6 950
951 index=kHistogramSigmaY2Sector;
952 if (index<fHistogram2DPointers.size() && fHistogram2DPointers[index]!=NULL)
953 fHistogram2DPointers[index]->Fill(fSector,sigmaY2*weight*weight);
954
779a5a62 955}
956
362b09a1 957void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillSigmaZ2(float sigmaZ2, AliHLTUInt32_t /*clusterId*/)
779a5a62 958{
959 /// fill sigmaZ2 histogram
362b09a1 960 fCurrentCluster.SetSigmaZ2(sigmaZ2);
779a5a62 961 unsigned index=kHistogramSigmaZ2;
ac30bb87 962 // FIXME: this is just a fixed value, to be correct the values from the global
963 // parameter block has to be used
964 float weight=AliHLTTPCTransform::GetZWidth();
779a5a62 965 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
ac30bb87 966 fHistogramPointers[index]->Fill(sigmaZ2*weight*weight);
69d38ee6 967
968 index=kHistogramSigmaZ2Sector;
969 if (index<fHistogram2DPointers.size() && fHistogram2DPointers[index]!=NULL)
970 fHistogram2DPointers[index]->Fill(fSector,sigmaZ2*weight*weight);
971
779a5a62 972}
973
362b09a1 974void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillCharge(unsigned charge, AliHLTUInt32_t /*clusterId*/)
779a5a62 975{
976 /// fill charge histogram
362b09a1 977 fCurrentCluster.SetCharge(charge);
779a5a62 978 unsigned index=kHistogramCharge;
979 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
980 fHistogramPointers[index]->Fill(charge);
779a5a62 981}
982
362b09a1 983void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FillQMax(unsigned qmax, AliHLTUInt32_t /*clusterId*/)
779a5a62 984{
985 /// fill qmax histogram
362b09a1 986 fCurrentCluster.SetQMax(qmax);
779a5a62 987 unsigned index=kHistogramQMax;
988 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL)
989 fHistogramPointers[index]->Fill(qmax);
69d38ee6 990
991 index=kHistogramQMaxSector;
992 if (index<fHistogram2DPointers.size() && fHistogram2DPointers[index]!=NULL)
993 fHistogram2DPointers[index]->Fill(fSector,qmax);
362b09a1 994}
995
996void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::Fill(int slice, int partition, AliHLTUInt32_t clusterId)
997{
998 /// fill cluster histograms requiring the full cluster information
999
1000 // TODO: the complete filling of histograms can be moved to this function
1001 // and the cluster struct be filled in the iterator
1002 // The delta histograms are filled here either by using the specified
1003 // cluster, or the nearest cluster on the padrow with identical charge
1004 // and qmax is searched for comparison.
1005 if (clusterId==kAliHLTVoidDataSpec) {
1006 clusterId=FindNearestCluster(slice, partition, fCurrentCluster);
1007 }
1008 if (clusterId==kAliHLTVoidDataSpec) return;
1009 bool bResidualError=false;
1010 int currentRow=fCurrentCluster.GetPadRow();
1011
1012 unsigned index=kHistogramDeltaPadrow;
1013 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1014 if (fRawData->Check(clusterId)) {
1015 fHistogramPointers[index]->Fill(fCurrentCluster.GetPadRow()-fRawData->GetX(clusterId));
1016 }
1017 }
1018
1019 index=kHistogramDeltaPad;
1020 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1021 if (fRawData->Check(clusterId)) {
1022 float dPad=fCurrentCluster.GetPad()-fRawData->GetY(clusterId);
1023 fHistogramPointers[index]->Fill(dPad);
1024 static const float maxdPad=0.015; // better 100um for 4 and 6mm pad width
1025 if (TMath::Abs(dPad)>maxdPad) {
1026 //HLTError("cluster 0x%08x slice %d partition %d: pad difference %f - max %f", clusterId, slice, partition, dPad, maxdPad);
1027 bResidualError=true;
1028 }
1029 }
1030 }
1031
1032 index=kHistogramDeltaTime;
1033 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1034 if (fRawData->Check(clusterId)) {
1035 float dTime=fCurrentCluster.GetTime()-fRawData->GetZ(clusterId);
1036 fHistogramPointers[index]->Fill(dTime);
1037 static const float maxdTime=0.04; // corresponds to 100um
1038 if (TMath::Abs(dTime)>maxdTime) {
1039 //HLTError("cluster 0x%08x slice %d partition %d: time difference %f - max %f", clusterId, slice, partition, dTime, maxdTime);
1040 bResidualError=true;
1041 }
1042 }
1043 }
1044
1045 index=kHistogramDeltaSigmaY2;
1046 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1047 if (fRawData->Check(clusterId)) {
d938def0 1048 float factor=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fScale;
1049 float sigma=fRawData->GetYWidth(clusterId)*factor;
1050 if (sigma>fMaxSigmaY2Scaled) sigma=fMaxSigmaY2Scaled;
1051 sigma/=factor;
1052 fHistogramPointers[index]->Fill(fCurrentCluster.GetSigmaY2()-sigma);
362b09a1 1053 }
1054 }
1055
1056 index=kHistogramDeltaSigmaZ2;
1057 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1058 if (fRawData->Check(clusterId)) {
d938def0 1059 float factor=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fScale;
1060 float sigma=fRawData->GetZWidth(clusterId)*factor;
1061 if (sigma>fMaxSigmaZ2Scaled) sigma=fMaxSigmaZ2Scaled;
1062 sigma/=factor;
1063 fHistogramPointers[index]->Fill(fCurrentCluster.GetSigmaZ2()-sigma);
362b09a1 1064 }
1065 }
1066
1067 index=kHistogramDeltaCharge;
1068 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1069 if (fRawData->Check(clusterId)) {
1070 fHistogramPointers[index]->Fill(fCurrentCluster.GetCharge()-fRawData->GetCharge(clusterId));
1071 }
1072 }
69d38ee6 1073
779a5a62 1074 index=kHistogramDeltaQMax;
1075 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1076 if (fRawData->Check(clusterId)) {
362b09a1 1077 fHistogramPointers[index]->Fill(fCurrentCluster.GetQMax()-fRawData->GetQMax(clusterId));
779a5a62 1078 }
1079 }
362b09a1 1080
1081 if (bResidualError) {
1082 index=kHistogramOutOfRange;
1083 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData) {
1084 fHistogramPointers[index]->Fill(currentRow>=0?currentRow:0);
1085 }
1086 }
1087
1088 index=kHistogramHWCFPad;
1089 if (index<fHistogramPointers.size() && fHistogramPointers[index]!=NULL && fRawData)
1090 fHistogramPointers[index]->Fill(fRawData->GetY(clusterId));
779a5a62 1091}
1092
1093void AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::Clear(Option_t * option)
1094{
1095 /// internal cleanup
1096 if (fRawData) fRawData->Clear(option);
1097}
1098
69d38ee6 1099TObject* AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::FindObject(const char *name) const
779a5a62 1100{
1101 /// get histogram object
a6267876 1102 if (!name) return NULL;
69d38ee6 1103 if ( strcmp(name,"fHistograms") == 0 )
1104 return fHistograms;
1105 if ( strcmp(name,"fHistograms2D") == 0 )
1106 return fHistograms2D;
1107 if ( strcmp(name,"fHistograms3D") == 0 )
1108 return fHistograms3D;
1109
1110 return NULL;
779a5a62 1111}