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 "AliRawDataHeader.h"
31 #include "AliHLTTPCRawCluster.h"
32 #include "AliHLTTPCHWCFEmulator.h"
33 #include "AliHLTTPCHWCFData.h"
34 #include "AliHLTErrorGuard.h"
36 #include "AliCDBManager.h"
37 #include "AliCDBEntry.h"
38 #include "AliTPCcalibDB.h"
41 #include "TObjString.h"
48 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
50 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
52 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
56 fPublishRawClusters(kFALSE),
58 fBenchmark("HWClusterTransform")
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 fBenchmark.SetTimer(0,"total");
70 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent()
73 if (!fpDecoder) delete fpDecoder;
77 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
78 // see header file for class documentation
80 return "TPCHWClusterTransform";
83 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
84 // see header file for class documentation
87 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
90 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
91 // see header file for class documentation
93 return AliHLTTPCDefinitions::fgkClustersDataType;
96 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
97 // see header file for class documentation
100 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
101 tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
102 tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
103 return tgtList.size();
106 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
107 // see header file for class documentation
109 inputMultiplier = 3.0;
112 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
113 // see header file for class documentation
115 return new AliHLTTPCHWClusterTransformComponent();
118 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
119 // see header file for class documentation
121 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
123 HLTError("AliTPCcalibDB does not exist");
126 calib->SetRun(GetRunNo());
127 calib->UpdateRunInformations(GetRunNo());
129 int err = fTransform.Init( GetBz(), GetTimeStamp() );
132 HLTError(Form("Cannot retrieve offline transform from AliTPCcalibDB, AliHLTTPCClusterTransformation returns %d",err));
137 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
139 if (iResult>=0 && argc>0)
140 iResult=ConfigureFromArgumentString(argc, argv);
143 fpDecoder=new AliHLTTPCHWCFData;
144 if (!fpDecoder) iResult=-ENOMEM;
150 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
151 // see header file for class documentation
152 if (!fpDecoder) delete fpDecoder;
158 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
159 const AliHLTComponentBlockData* blocks,
160 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
161 AliHLTUInt32_t& size,
162 vector<AliHLTComponentBlockData>& outputBlocks ){
163 // see header file for class documentation
165 UInt_t maxOutSize = size;
168 if(!IsDataEvent()) return 0;
170 if (!fpDecoder) return -ENODEV;
172 fBenchmark.StartNewEvent();
175 // fTransform.SetCurrentTimeStamp( GetTimeStamp() ); !!! for the future
177 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
179 const AliHLTComponentBlockData *iter = blocks+ndx;
181 fBenchmark.AddInput(iter->fSize);
183 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
184 evtData.fEventID, evtData.fEventID,
185 DataType2Text( iter->fDataType).c_str(),
186 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
188 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
189 // simply forward MC labels
191 if( size+iter->fSize > maxOutSize ){
192 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
197 memcpy( outputPtr, iter->fPtr, iter->fSize );
199 AliHLTComponentBlockData bd;
202 bd.fSize = iter->fSize;
203 bd.fSpecification = iter->fSpecification;
204 bd.fDataType = iter->fDataType;
205 outputBlocks.push_back( bd );
206 fBenchmark.AddOutput(bd.fSize);
208 outputPtr += bd.fSize;
212 if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;
214 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
215 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
216 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
217 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
219 if ((int)minPartition<AliHLTTPCTransform::GetNRowLow())
220 padpitch=AliHLTTPCTransform::GetPadPitchWidthLow();
222 padpitch=AliHLTTPCTransform::GetPadPitchWidthUp();
223 float zwidth=AliHLTTPCTransform::GetZWidth();
225 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
227 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
229 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outputPtr;
230 outPtr->fSpacePointCnt=0;
232 long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
234 AliHLTUInt32_t *buffer;
235 buffer = (AliHLTUInt32_t*)iter->fPtr;
237 // skip the first 8 32-bit CDH words
239 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
241 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
242 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
243 if(outPtr->fSpacePointCnt>=maxPoints){
244 HLTWarning("No more space to add clusters, exiting!");
249 AliHLTTPCSpacePointData& c=outPtr->fSpacePoints[outPtr->fSpacePointCnt];
250 int padrow=cl.GetPadRow();
252 // something wrong here, padrow is stored in the cluster header
253 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
255 ALIHLTERRORGUARD(1, "can not read cluster header word");
258 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
259 AliHLTUInt32_t charge=cl.GetCharge();
261 float pad=cl.GetPad();
262 float time=cl.GetTime();
263 float sigmaY2=cl.GetSigmaY2();
264 float sigmaZ2=cl.GetSigmaZ2();
265 sigmaY2*=padpitch*padpitch;
266 sigmaZ2*=zwidth*zwidth;
269 c.SetSigmaY2(sigmaY2);
270 c.SetSigmaZ2(sigmaZ2);
271 c.SetQMax(cl.GetQMax());
274 fTransform.Transform( minSlice, padrow, pad, time, xyz );
279 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
280 c.SetID( minSlice, minPartition, outPtr->fSpacePointCnt );
282 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", outPtr->fSpacePointCnt, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
284 outPtr->fSpacePointCnt++;
285 } // end of loop over clusters
287 HLTDebug("Number of found clusters: %d", outPtr->fSpacePointCnt);
289 UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
291 AliHLTComponentBlockData bd;
295 bd.fSpecification = iter->fSpecification;
296 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
297 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
299 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
301 outputBlocks.push_back( bd );
303 fBenchmark.AddOutput(bd.fSize);
307 if (fPublishRawClusters) {
309 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
311 if( maxRawClusters<=0 ) {
312 HLTWarning("No more space to add raw clusters, exiting!");
316 // copy raw cluster data from input
318 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
320 outputRaw->fVersion = 0;
321 outputRaw->fCount = 0;
323 // check if there are clusters available, if not the format might
324 // not even been decoded at that moment
325 if (fpDecoder->GetNumberOfClusters()>0) {
326 for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
327 if(outputRaw->fCount>=maxRawClusters){
328 HLTWarning("No more space to add clusters, exiting!");
332 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
333 int padrow=cl.GetPadRow();
335 // something wrong here, padrow is stored in the cluster header
336 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
340 padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
341 AliHLTUInt32_t charge= cl.GetCharge();
343 float pad =cl.GetPad();
344 float time =cl.GetTime();
345 float sigmaP2=cl.GetSigmaY2();
346 float sigmaT2=cl.GetSigmaZ2();
351 c.SetSigmaY2(sigmaP2);
352 c.SetSigmaZ2(sigmaT2);
353 c.SetQMax(cl.GetQMax());
355 // store cluster and continue
360 // fill into HLT output data
361 AliHLTComponentBlockData bdRawClusters;
362 FillBlockData( bdRawClusters );
363 bdRawClusters.fOffset = size;
364 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
365 bdRawClusters.fSpecification = iter->fSpecification;
366 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
367 outputBlocks.push_back( bdRawClusters );
368 fBenchmark.AddOutput(bdRawClusters.fSize);
369 size += bdRawClusters.fSize;
370 outputPtr += bdRawClusters.fSize;
373 } // end of loop over data blocks
376 HLTInfo(fBenchmark.GetStatistics());
381 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
383 // see header file for class documentation
385 if (argc<=0) return 0;
387 TString argument=argv[i];
389 if (argument.CompareTo("-solenoidBz")==0){
390 if (++i>=argc) return -EPROTO;
392 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
394 HLTError("CalibDB instance cannot be created.");
397 Float_t magneticField = argument.Atof();
398 calib->SetExBField(magneticField);
399 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
403 if (argument.CompareTo("-change-dataId")==0){
404 HLTDebug("Change data ID received.");
409 if (argument.CompareTo("-charge-threshold")==0) {
410 if (++i>=argc) return -EPROTO;
412 HLTInfo("The argument -charge-threshold is deprecated.");
416 if (argument.CompareTo("-publish-raw")==0) {
417 fPublishRawClusters=kTRUE;
425 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
426 // see header file for class documentation
427 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
430 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
431 // see header file for class documentation
433 HLTInfo("The size is: %d", size);
434 for(Int_t n32bit=0; n32bit<size; n32bit++){
436 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
437 // cout << "word ptr initialized"<<endl;
438 for(Int_t w=3;w>=0;w--){
439 // cout <<"accessing word"<<endl;
440 AliHLTUInt8_t word = wordPtr[w];
441 // cout<< "word was accessed"<<endl;
442 for(int n=7; n>=0; n--){
443 //print the byte values
444 if((((word>>n)<<7)&0x80) != 0){
455 } // end of PrintDebug
457 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
459 // Get a list of OCDB object description needed for the particular component
460 if (!targetMap) return;
462 // OCDB entries for component arguments
464 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
466 // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
467 targetMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("unknown content"));
468 targetMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("drift velocity calibration"));
469 targetMap->Add(new TObjString("TPC/Calib/TimeGain"), new TObjString("time gain calibration"));
470 targetMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("temperature map"));
471 targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
472 targetMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("cluster parameters"));
473 targetMap->Add(new TObjString("TPC/Calib/Correction"), new TObjString("coreection"));
474 targetMap->Add(new TObjString("TPC/Calib/RecoParam"), new TObjString("reconstruction parameters"));
476 // OCDB entries needed to be fetched by the Pendolino
477 targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
478 targetMap->Add(new TObjString("GRP/CTP/CTPtiming"), new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
480 // OCDB entries necessary for replaying data on the HLT cluster
481 targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));
483 // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
484 targetMap->Add(new TObjString("TPC/Calib/Distortion"), new TObjString("distortion map"));
485 targetMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("gain factor dedx"));
486 targetMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("time0 offset pad by pad"));
487 targetMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("pad noise values"));
488 targetMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("pedestal info"));
489 targetMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("pulser info"));
490 targetMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("CE laser calibration result"));
491 targetMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("unknown content"));
492 targetMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("not important"));
493 targetMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("unknown content"));
494 targetMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("Goofie values, not used at the moment (05.03.2010)"));
495 targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
496 targetMap->Add(new TObjString("TPC/Calib/Ref"), new TObjString("unknown content"));