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
25 #include "AliHLTTPCHWClusterTransformComponent.h"
26 #include "AliHLTTPCDefinitions.h"
27 #include "AliHLTTPCTransform.h"
28 #include "AliHLTTPCSpacePointData.h"
29 #include "AliHLTTPCClusterDataFormat.h"
30 #include "AliHLTCDHWrapper.h"
31 #include "AliHLTTPCRawCluster.h"
32 #include "AliHLTTPCHWCFEmulator.h"
33 #include "AliHLTTPCHWCFData.h"
34 #include "AliHLTErrorGuard.h"
35 #include "AliTPCTransform.h"
37 #include "AliCDBManager.h"
38 #include "AliCDBEntry.h"
39 #include "AliTPCcalibDB.h"
42 #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 AliHLTTPCClusterTransformation AliHLTTPCHWClusterTransformComponent::fgTransform;
54 Bool_t AliHLTTPCHWClusterTransformComponent::fgTimeInitialisedFromEvent = 0;
56 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
59 fPublishRawClusters(kFALSE),
61 fBenchmark("HWClusterTransform")
63 // see header file for class documentation
65 // refer to README to build package
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 fBenchmark.SetTimer(0,"total");
73 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent()
76 if (!fpDecoder) delete fpDecoder;
80 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
81 // see header file for class documentation
83 return "TPCHWClusterTransform";
86 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
87 // see header file for class documentation
90 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
93 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
94 // see header file for class documentation
96 return AliHLTTPCDefinitions::fgkClustersDataType;
99 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
100 // see header file for class documentation
103 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
104 tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
105 tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
106 return tgtList.size();
109 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
110 // see header file for class documentation
112 inputMultiplier = 3.0;
115 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
116 // see header file for class documentation
118 return new AliHLTTPCHWClusterTransformComponent();
121 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv )
123 // see header file for class documentation
125 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
127 HLTError("AliTPCcalibDB does not exist");
130 calib->SetRun(GetRunNo());
131 calib->UpdateRunInformations(GetRunNo());
133 if( !fgTransform.IsInitialised() ){
134 int err = fgTransform.Init( GetBz(), GetTimeStamp() );
136 HLTError(Form("Cannot retrieve offline transform from AliTPCcalibDB, AliHLTTPCClusterTransformation returns %d",err));
142 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
144 if (iResult>=0 && argc>0)
145 iResult=ConfigureFromArgumentString(argc, argv);
148 fpDecoder=new AliHLTTPCHWCFData;
149 if (!fpDecoder) iResult=-ENOMEM;
155 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
156 // see header file for class documentation
157 if (!fpDecoder) delete fpDecoder;
159 fgTransform.DeInit();
163 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
164 const AliHLTComponentBlockData* blocks,
165 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
166 AliHLTUInt32_t& size,
167 vector<AliHLTComponentBlockData>& outputBlocks ){
168 // see header file for class documentation
170 UInt_t maxOutSize = size;
173 if(!IsDataEvent()) return 0;
175 if (!fpDecoder) return -ENODEV;
176 if( !fgTransform.IsInitialised() ){
177 HLTError(" TPC Transformation is not initialised ");
181 fBenchmark.StartNewEvent();
184 // Initialise the transformation here once more for the case of off-line reprocessing
185 if( !fgTimeInitialisedFromEvent ){
186 Long_t currentTime = static_cast<AliHLTUInt32_t>(time(NULL));
187 Long_t eventTimeStamp = GetTimeStamp();
188 if( TMath::Abs( fgTransform.GetCurrentTimeStamp() - eventTimeStamp )>60 &&
189 TMath::Abs( currentTime - eventTimeStamp)>60*60*5 ){
190 int err = fgTransform.SetCurrentTimeStamp( eventTimeStamp );
192 HLTError(Form("Cannot set time stamp, AliHLTTPCClusterTransformation returns %d",err));
196 fgTimeInitialisedFromEvent = 1;
199 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
201 const AliHLTComponentBlockData *iter = blocks+ndx;
203 fBenchmark.AddInput(iter->fSize);
205 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
206 evtData.fEventID, evtData.fEventID,
207 DataType2Text( iter->fDataType).c_str(),
208 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
210 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
211 // simply forward MC labels
213 if( size+iter->fSize > maxOutSize ){
214 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
219 memcpy( outputPtr, iter->fPtr, iter->fSize );
221 AliHLTComponentBlockData bd;
224 bd.fSize = iter->fSize;
225 bd.fSpecification = iter->fSpecification;
226 bd.fDataType = iter->fDataType;
227 outputBlocks.push_back( bd );
228 fBenchmark.AddOutput(bd.fSize);
230 outputPtr += bd.fSize;
234 if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;
236 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
237 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
238 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
239 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
241 if ((int)minPartition<AliHLTTPCTransform::GetNRowLow())
242 padpitch=AliHLTTPCTransform::GetPadPitchWidthLow();
244 padpitch=AliHLTTPCTransform::GetPadPitchWidthUp();
245 float zwidth=AliHLTTPCTransform::GetZWidth();
247 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
249 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
251 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outputPtr;
252 outPtr->fSpacePointCnt=0;
254 long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
256 AliHLTUInt32_t *buffer;
257 buffer = (AliHLTUInt32_t*)iter->fPtr;
258 AliHLTCDHWrapper cdh(iter->fPtr);
260 // skip the first 8 32-bit CDH words
261 buffer += cdh.GetHeaderSize()/sizeof(AliHLTUInt32_t);
262 UInt_t bufferSize32 = ((Int_t)iter->fSize - cdh.GetHeaderSize() )/sizeof(AliHLTUInt32_t);
264 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
265 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
266 if(outPtr->fSpacePointCnt>=maxPoints){
267 HLTWarning("No more space to add clusters, exiting!");
272 AliHLTTPCSpacePointData& c=outPtr->fSpacePoints[outPtr->fSpacePointCnt];
273 int padrow=cl.GetPadRow();
275 // something wrong here, padrow is stored in the cluster header
276 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
278 ALIHLTERRORGUARD(1, "can not read cluster header word");
281 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
282 AliHLTUInt32_t charge=cl.GetCharge();
284 float pad=cl.GetPad();
285 float time=cl.GetTime();
286 float sigmaY2=cl.GetSigmaY2();
287 float sigmaZ2=cl.GetSigmaZ2();
288 sigmaY2*=padpitch*padpitch;
289 sigmaZ2*=zwidth*zwidth;
292 c.SetSigmaY2(sigmaY2);
293 c.SetSigmaZ2(sigmaZ2);
294 c.SetQMax(cl.GetQMax());
297 int err = fgTransform.Transform( minSlice, padrow, pad, time, xyz );
299 HLTWarning(Form("Cannot transform the cluster, AliHLTTPCClusterTransformation returns error %d, %s",err, fgTransform.GetLastError()));
306 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
307 c.SetID( minSlice, minPartition, outPtr->fSpacePointCnt );
309 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", outPtr->fSpacePointCnt, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
311 outPtr->fSpacePointCnt++;
312 } // end of loop over clusters
314 HLTDebug("Number of found clusters: %d", outPtr->fSpacePointCnt);
316 UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
318 AliHLTComponentBlockData bd;
322 bd.fSpecification = iter->fSpecification;
323 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
324 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
326 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
328 outputBlocks.push_back( bd );
330 fBenchmark.AddOutput(bd.fSize);
334 if (fPublishRawClusters) {
336 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
338 if( maxRawClusters<=0 ) {
339 HLTWarning("No more space to add raw clusters, exiting!");
343 // copy raw cluster data from input
345 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
347 outputRaw->fVersion = 0;
348 outputRaw->fCount = 0;
350 // check if there are clusters available, if not the format might
351 // not even been decoded at that moment
352 if (fpDecoder->GetNumberOfClusters()>0) {
353 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
354 if(outputRaw->fCount>=maxRawClusters){
355 HLTWarning("No more space to add clusters, exiting!");
359 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
360 int padrow=cl.GetPadRow();
362 // something wrong here, padrow is stored in the cluster header
363 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
367 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
368 AliHLTUInt32_t charge= cl.GetCharge();
370 float pad =cl.GetPad();
371 float time =cl.GetTime();
372 float sigmaP2=cl.GetSigmaY2();
373 float sigmaT2=cl.GetSigmaZ2();
378 c.SetSigmaY2(sigmaP2);
379 c.SetSigmaZ2(sigmaT2);
380 c.SetQMax(cl.GetQMax());
382 // store cluster and continue
387 // fill into HLT output data
388 AliHLTComponentBlockData bdRawClusters;
389 FillBlockData( bdRawClusters );
390 bdRawClusters.fOffset = size;
391 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
392 bdRawClusters.fSpecification = iter->fSpecification;
393 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
394 outputBlocks.push_back( bdRawClusters );
395 fBenchmark.AddOutput(bdRawClusters.fSize);
396 size += bdRawClusters.fSize;
397 outputPtr += bdRawClusters.fSize;
400 } // end of loop over data blocks
403 HLTInfo(fBenchmark.GetStatistics());
408 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
410 // see header file for class documentation
412 if (argc<=0) return 0;
414 TString argument=argv[i];
416 if (argument.CompareTo("-solenoidBz")==0){
417 if (++i>=argc) return -EPROTO;
419 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
421 HLTError("CalibDB instance cannot be created.");
424 Float_t magneticField = argument.Atof();
425 calib->SetExBField(magneticField);
426 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
430 if (argument.CompareTo("-change-dataId")==0){
431 HLTDebug("Change data ID received.");
436 if (argument.CompareTo("-charge-threshold")==0) {
437 if (++i>=argc) return -EPROTO;
439 HLTInfo("The argument -charge-threshold is deprecated.");
443 if (argument.CompareTo("-publish-raw")==0) {
444 fPublishRawClusters=kTRUE;
452 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
453 // see header file for class documentation
454 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
457 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
458 // see header file for class documentation
460 HLTInfo("The size is: %d", size);
461 for(Int_t n32bit=0; n32bit<size; n32bit++){
463 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
464 // cout << "word ptr initialized"<<endl;
465 for(Int_t w=3;w>=0;w--){
466 // cout <<"accessing word"<<endl;
467 AliHLTUInt8_t word = wordPtr[w];
468 // cout<< "word was accessed"<<endl;
469 for(int n=7; n>=0; n--){
470 //print the byte values
471 if((((word>>n)<<7)&0x80) != 0){
482 } // end of PrintDebug
484 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
486 // Get a list of OCDB object description needed for the particular component
487 if (!targetMap) return;
489 // OCDB entries for component arguments
491 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
493 // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
494 targetMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("unknown content"));
495 targetMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("drift velocity calibration"));
496 targetMap->Add(new TObjString("TPC/Calib/TimeGain"), new TObjString("time gain calibration"));
497 targetMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("temperature map"));
498 targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
499 targetMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("cluster parameters"));
500 targetMap->Add(new TObjString("TPC/Calib/Correction"), new TObjString("coreection"));
501 targetMap->Add(new TObjString("TPC/Calib/RecoParam"), new TObjString("reconstruction parameters"));
503 // OCDB entries needed to be fetched by the Pendolino
504 targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
505 targetMap->Add(new TObjString("GRP/CTP/CTPtiming"), new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
507 // OCDB entries necessary for replaying data on the HLT cluster
508 targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));
510 // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
511 targetMap->Add(new TObjString("TPC/Calib/Distortion"), new TObjString("distortion map"));
512 targetMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("gain factor dedx"));
513 targetMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("time0 offset pad by pad"));
514 targetMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("pad noise values"));
515 targetMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("pedestal info"));
516 targetMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("pulser info"));
517 targetMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("CE laser calibration result"));
518 targetMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("unknown content"));
519 targetMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("not important"));
520 targetMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("unknown content"));
521 targetMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("Goofie values, not used at the moment (05.03.2010)"));
522 targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
523 targetMap->Add(new TObjString("TPC/Calib/Ref"), new TObjString("unknown content"));