3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTPCHWClusterTransformComponent.cxx
20 @author Kalliopi Kanaki
28 #include "AliHLTTPCHWClusterTransformComponent.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTTPCTransform.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCClusterDataFormat.h"
33 #include "AliRawDataHeader.h"
34 #include "AliHLTTPCRawCluster.h"
35 #include "AliHLTTPCHWCFEmulator.h"
36 #include "AliHLTTPCHWCFData.h"
37 #include "AliHLTErrorGuard.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBEntry.h"
41 #include "AliTPCcalibDB.h"
44 #include "TObjString.h"
49 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
51 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
53 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
57 fPublishRawClusters(kFALSE),
59 fBenchmark("HWClusterTransform")
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 fBenchmark.SetTimer(0,"total");
71 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent()
74 if (!fpDecoder) delete fpDecoder;
78 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
79 // see header file for class documentation
81 return "TPCHWClusterTransform";
84 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
85 // see header file for class documentation
88 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
91 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
92 // see header file for class documentation
94 return AliHLTTPCDefinitions::fgkClustersDataType;
97 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
98 // see header file for class documentation
101 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
102 tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
103 tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
104 return tgtList.size();
107 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
108 // see header file for class documentation
110 inputMultiplier = 3.0;
113 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
114 // see header file for class documentation
116 return new AliHLTTPCHWClusterTransformComponent();
119 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
120 // see header file for class documentation
122 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
124 HLTError("AliTPCcalibDB does not exist");
127 calib->SetRun(GetRunNo());
128 calib->UpdateRunInformations(GetRunNo());
130 int err = fTransform.Init( GetBz(), GetTimeStamp() );
133 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
138 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
140 if (iResult>=0 && argc>0)
141 iResult=ConfigureFromArgumentString(argc, argv);
144 fpDecoder=new AliHLTTPCHWCFData;
145 if (!fpDecoder) iResult=-ENOMEM;
151 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
152 // see header file for class documentation
153 if (!fpDecoder) delete fpDecoder;
159 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
160 const AliHLTComponentBlockData* blocks,
161 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
162 AliHLTUInt32_t& size,
163 vector<AliHLTComponentBlockData>& outputBlocks ){
164 // see header file for class documentation
166 UInt_t maxOutSize = size;
169 if(!IsDataEvent()) return 0;
171 if (!fpDecoder) return -ENODEV;
173 fBenchmark.StartNewEvent();
176 // fTransform.SetCurrentTimeStamp( GetTimeStamp() ); !!! for the future
178 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
180 const AliHLTComponentBlockData *iter = blocks+ndx;
182 fBenchmark.AddInput(iter->fSize);
184 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
185 evtData.fEventID, evtData.fEventID,
186 DataType2Text( iter->fDataType).c_str(),
187 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
189 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
190 // simply forward MC labels
192 if( size+iter->fSize > maxOutSize ){
193 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
198 memcpy( outputPtr, iter->fPtr, iter->fSize );
200 AliHLTComponentBlockData bd;
203 bd.fSize = iter->fSize;
204 bd.fSpecification = iter->fSpecification;
205 bd.fDataType = iter->fDataType;
206 outputBlocks.push_back( bd );
207 fBenchmark.AddOutput(bd.fSize);
209 outputPtr += bd.fSize;
213 if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;
215 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
216 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
217 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
218 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
220 if ((int)minPartition<AliHLTTPCTransform::GetNRowLow())
221 padpitch=AliHLTTPCTransform::GetPadPitchWidthLow();
223 padpitch=AliHLTTPCTransform::GetPadPitchWidthUp();
224 float zwidth=AliHLTTPCTransform::GetZWidth();
226 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
228 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
230 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outputPtr;
231 outPtr->fSpacePointCnt=0;
233 long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
235 AliHLTUInt32_t *buffer;
236 buffer = (AliHLTUInt32_t*)iter->fPtr;
238 // skip the first 8 32-bit CDH words
240 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
242 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
243 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
244 if(outPtr->fSpacePointCnt>=maxPoints){
245 HLTWarning("No more space to add clusters, exiting!");
250 AliHLTTPCSpacePointData& c=outPtr->fSpacePoints[outPtr->fSpacePointCnt];
251 int padrow=cl.GetPadRow();
253 // something wrong here, padrow is stored in the cluster header
254 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
256 ALIHLTERRORGUARD(1, "can not read cluster header word");
259 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
260 AliHLTUInt32_t charge=cl.GetCharge();
262 float pad=cl.GetPad();
263 float time=cl.GetTime();
264 float sigmaY2=cl.GetSigmaY2();
265 float sigmaZ2=cl.GetSigmaZ2();
266 sigmaY2*=padpitch*padpitch;
267 sigmaZ2*=zwidth*zwidth;
270 c.SetSigmaY2(sigmaY2);
271 c.SetSigmaZ2(sigmaZ2);
272 c.SetQMax(cl.GetQMax());
275 fTransform.Transform( minSlice, padrow, pad, time, xyz );
280 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
281 c.SetID( minSlice, minPartition, outPtr->fSpacePointCnt );
283 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", outPtr->fSpacePointCnt, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
285 outPtr->fSpacePointCnt++;
286 } // end of loop over clusters
288 HLTDebug("Number of found clusters: %d", outPtr->fSpacePointCnt);
290 UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
292 AliHLTComponentBlockData bd;
296 bd.fSpecification = iter->fSpecification;
297 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
298 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
300 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
302 outputBlocks.push_back( bd );
304 fBenchmark.AddOutput(bd.fSize);
308 if (fPublishRawClusters) {
310 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
312 if( maxRawClusters<=0 ) {
313 HLTWarning("No more space to add raw clusters, exiting!");
317 // copy raw cluster data from input
319 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
321 outputRaw->fVersion = 0;
322 outputRaw->fCount = 0;
324 // check if there are clusters available, if not the format might
325 // not even been decoded at that moment
326 if (fpDecoder->GetNumberOfClusters()>0) {
327 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
328 if(outputRaw->fCount>=maxRawClusters){
329 HLTWarning("No more space to add clusters, exiting!");
333 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
334 int padrow=cl.GetPadRow();
336 // something wrong here, padrow is stored in the cluster header
337 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
341 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
342 AliHLTUInt32_t charge= cl.GetCharge();
344 float pad =cl.GetPad();
345 float time =cl.GetTime();
346 float sigmaP2=cl.GetSigmaY2();
347 float sigmaT2=cl.GetSigmaZ2();
352 c.SetSigmaY2(sigmaP2);
353 c.SetSigmaZ2(sigmaT2);
354 c.SetQMax(cl.GetQMax());
356 // store cluster and continue
361 // fill into HLT output data
362 AliHLTComponentBlockData bdRawClusters;
363 FillBlockData( bdRawClusters );
364 bdRawClusters.fOffset = size;
365 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
366 bdRawClusters.fSpecification = iter->fSpecification;
367 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
368 outputBlocks.push_back( bdRawClusters );
369 fBenchmark.AddOutput(bdRawClusters.fSize);
370 size += bdRawClusters.fSize;
371 outputPtr += bdRawClusters.fSize;
374 } // end of loop over data blocks
377 HLTInfo(fBenchmark.GetStatistics());
382 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
384 // see header file for class documentation
386 if (argc<=0) return 0;
388 TString argument=argv[i];
390 if (argument.CompareTo("-solenoidBz")==0){
391 if (++i>=argc) return -EPROTO;
393 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
395 HLTError("CalibDB instance cannot be created.");
398 Float_t magneticField = argument.Atof();
399 calib->SetExBField(magneticField);
400 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
404 if (argument.CompareTo("-change-dataId")==0){
405 HLTDebug("Change data ID received.");
410 if (argument.CompareTo("-charge-threshold")==0) {
411 if (++i>=argc) return -EPROTO;
413 HLTInfo("The argument -charge-threshold is deprecated.");
417 if (argument.CompareTo("-publish-raw")==0) {
418 fPublishRawClusters=kTRUE;
426 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
427 // see header file for class documentation
428 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
431 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
432 // see header file for class documentation
434 HLTInfo("The size is: %d", size);
435 for(Int_t n32bit=0; n32bit<size; n32bit++){
437 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
438 // cout << "word ptr initialized"<<endl;
439 for(Int_t w=3;w>=0;w--){
440 // cout <<"accessing word"<<endl;
441 AliHLTUInt8_t word = wordPtr[w];
442 // cout<< "word was accessed"<<endl;
443 for(int n=7; n>=0; n--){
444 //print the byte values
445 if((((word>>n)<<7)&0x80) != 0){
456 } // end of PrintDebug
458 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
460 // Get a list of OCDB object description needed for the particular component
461 if (!targetMap) return;
463 // OCDB entries for component arguments
465 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
467 // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
468 targetMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("unknown content"));
469 targetMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("drift velocity calibration"));
470 targetMap->Add(new TObjString("TPC/Calib/TimeGain"), new TObjString("time gain calibration"));
471 targetMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("temperature map"));
472 targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
473 targetMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("cluster parameters"));
474 targetMap->Add(new TObjString("TPC/Calib/Correction"), new TObjString("coreection"));
475 targetMap->Add(new TObjString("TPC/Calib/RecoParam"), new TObjString("reconstruction parameters"));
477 // OCDB entries needed to be fetched by the Pendolino
478 targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
479 targetMap->Add(new TObjString("GRP/CTP/CTPtiming"), new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
481 // OCDB entries necessary for replaying data on the HLT cluster
482 targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));
484 // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
485 targetMap->Add(new TObjString("TPC/Calib/Distortion"), new TObjString("distortion map"));
486 targetMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("gain factor dedx"));
487 targetMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("time0 offset pad by pad"));
488 targetMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("pad noise values"));
489 targetMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("pedestal info"));
490 targetMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("pulser info"));
491 targetMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("CE laser calibration result"));
492 targetMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("unknown content"));
493 targetMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("not important"));
494 targetMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("unknown content"));
495 targetMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("Goofie values, not used at the moment (05.03.2010)"));
496 targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
497 targetMap->Add(new TObjString("TPC/Calib/PreprocStatus"), new TObjString("not important"));
498 targetMap->Add(new TObjString("TPC/Calib/Ref"), new TObjString("unknown content"));