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()
58 fPublishRawClusters(kFALSE),
60 fBenchmark("HWClusterTransform")
62 // see header file for class documentation
64 // refer to README to build package
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69 fBenchmark.SetTimer(0,"total");
72 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent()
75 if (!fpDecoder) delete fpDecoder;
79 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
80 // see header file for class documentation
82 return "TPCHWClusterTransform";
85 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
86 // see header file for class documentation
89 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
92 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
93 // see header file for class documentation
95 return AliHLTTPCDefinitions::fgkClustersDataType;
98 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
99 // see header file for class documentation
102 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
103 tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
104 tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC );
105 return tgtList.size();
108 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
109 // see header file for class documentation
111 inputMultiplier = 3.0;
114 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
115 // see header file for class documentation
117 return new AliHLTTPCHWClusterTransformComponent();
120 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
121 // see header file for class documentation
123 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
125 HLTError("AliTPCcalibDB does not exist");
128 calib->SetRun(GetRunNo());
129 calib->UpdateRunInformations(GetRunNo());
131 int err = fTransform.Init( GetBz(), GetTimeStamp() );
134 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
139 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
141 if (iResult>=0 && argc>0)
142 iResult=ConfigureFromArgumentString(argc, argv);
145 fpDecoder=new AliHLTTPCHWCFData;
146 if (!fpDecoder) iResult=-ENOMEM;
152 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
153 // see header file for class documentation
154 if (!fpDecoder) delete fpDecoder;
160 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
161 const AliHLTComponentBlockData* blocks,
162 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
163 AliHLTUInt32_t& size,
164 vector<AliHLTComponentBlockData>& outputBlocks ){
165 // see header file for class documentation
167 UInt_t maxOutSize = size;
170 if(!IsDataEvent()) return 0;
172 if (!fpDecoder) return -ENODEV;
174 fBenchmark.StartNewEvent();
177 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
179 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
181 const AliHLTComponentBlockData *iter = blocks+ndx;
183 fBenchmark.AddInput(iter->fSize);
185 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
186 evtData.fEventID, evtData.fEventID,
187 DataType2Text( iter->fDataType).c_str(),
188 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
190 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
191 // simply forward MC labels
193 if( size+iter->fSize > maxOutSize ){
194 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
199 memcpy( outputPtr, iter->fPtr, iter->fSize );
201 AliHLTComponentBlockData bd;
204 bd.fSize = iter->fSize;
205 bd.fSpecification = iter->fSpecification;
206 bd.fDataType = iter->fDataType;
207 outputBlocks.push_back( bd );
208 fBenchmark.AddOutput(bd.fSize);
210 outputPtr += bd.fSize;
214 if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;
216 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
217 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
218 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
219 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
221 if ((int)minPartition<AliHLTTPCTransform::GetNRowLow())
222 padpitch=AliHLTTPCTransform::GetPadPitchWidthLow();
224 padpitch=AliHLTTPCTransform::GetPadPitchWidthUp();
225 float zwidth=AliHLTTPCTransform::GetZWidth();
227 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
229 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
231 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outputPtr;
232 outPtr->fSpacePointCnt=0;
234 long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
236 AliHLTUInt32_t *buffer;
237 buffer = (AliHLTUInt32_t*)iter->fPtr;
239 // skip the first 8 32-bit CDH words
241 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
243 if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
244 UInt_t nofClusters=fpDecoder->GetNumberOfClusters();
245 for (UInt_t cl=0; cl<nofClusters; cl++) {
246 if(outPtr->fSpacePointCnt>=maxPoints){
247 HLTWarning("No more space to add clusters, exiting!");
252 AliHLTTPCSpacePointData& c=outPtr->fSpacePoints[outPtr->fSpacePointCnt];
253 int padrow=fpDecoder->GetPadRow(cl) + AliHLTTPCTransform::GetFirstRow(minPartition);
255 // something wrong here, padrow is stored in the cluster header
256 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
258 ALIHLTERRORGUARD(1, "can not read cluster header word, skipping %d of %d cluster(s)", nofClusters-cl, nofClusters);
261 AliHLTUInt32_t charge=fpDecoder->GetCharge(cl);
262 // skip clusters below threshold
263 if( charge<fChargeThreshold ) continue;
265 float pad=fpDecoder->GetPad(cl);
266 float time=fpDecoder->GetTime(cl);
267 float sigmaY2=fpDecoder->GetSigmaY2(cl);
268 float sigmaZ2=fpDecoder->GetSigmaZ2(cl);
270 sigmaY2*=padpitch*padpitch;
272 sigmaZ2*=zwidth*zwidth;
275 c.SetSigmaY2(sigmaY2);
276 c.SetSigmaZ2(sigmaZ2);
277 c.SetQMax(fpDecoder->GetQMax(cl));
280 fTransform.Transform( minSlice, padrow, pad + 0.5, time, xyz );
285 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
286 c.SetID( minSlice, minPartition, outPtr->fSpacePointCnt );
288 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", outPtr->fSpacePointCnt, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
290 outPtr->fSpacePointCnt++;
291 } // end of loop over clusters
293 HLTDebug("Number of found clusters: %d", outPtr->fSpacePointCnt);
295 UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
297 AliHLTComponentBlockData bd;
301 bd.fSpecification = iter->fSpecification;
302 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
303 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
305 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
307 outputBlocks.push_back( bd );
309 fBenchmark.AddOutput(bd.fSize);
313 if (fPublishRawClusters) {
315 long maxRawClusters = ((long)maxOutSize-size-sizeof(AliHLTTPCRawClusterData))/sizeof(AliHLTTPCRawCluster);
317 if( maxRawClusters<=0 ) {
318 HLTWarning("No more space to add raw clusters, exiting!");
322 // copy raw cluster data from input
324 AliHLTTPCRawClusterData* outputRaw= (AliHLTTPCRawClusterData*)(outputPtr);
326 outputRaw->fVersion = 0;
327 outputRaw->fCount = 0;
329 UInt_t nofClusters=fpDecoder->GetNumberOfClusters();
330 for (UInt_t cl=0; cl<nofClusters; cl++) {
331 if(outputRaw->fCount>=maxRawClusters){
332 HLTWarning("No more space to add clusters, exiting!");
336 AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
337 int padrow=fpDecoder->GetPadRow(cl) + AliHLTTPCTransform::GetFirstRow(minPartition);
339 // something wrong here, padrow is stored in the cluster header
340 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
344 AliHLTUInt32_t charge= fpDecoder->GetCharge(cl);
345 // skip clusters below threshold
346 if( charge<fChargeThreshold ) continue;
348 float pad =fpDecoder->GetPad(cl);
349 float time =fpDecoder->GetTime(cl);
350 float sigmaP2=fpDecoder->GetSigmaY2(cl);
351 float sigmaT2=fpDecoder->GetSigmaZ2(cl);
358 c.SetSigmaY2(sigmaP2);
359 c.SetSigmaZ2(sigmaT2);
360 c.SetQMax(fpDecoder->GetQMax(cl));
362 // store cluster and continue
366 // fill into HLT output data
367 AliHLTComponentBlockData bdRawClusters;
368 FillBlockData( bdRawClusters );
369 bdRawClusters.fOffset = size;
370 bdRawClusters.fSize = sizeof(AliHLTTPCRawClusterData)+outputRaw->fCount*sizeof(AliHLTTPCRawCluster);
371 bdRawClusters.fSpecification = iter->fSpecification;
372 bdRawClusters.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType | kAliHLTDataOriginTPC;
373 outputBlocks.push_back( bdRawClusters );
374 fBenchmark.AddOutput(bdRawClusters.fSize);
375 size += bdRawClusters.fSize;
376 outputPtr += bdRawClusters.fSize;
379 } // end of loop over data blocks
382 HLTInfo(fBenchmark.GetStatistics());
387 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
389 // see header file for class documentation
391 if (argc<=0) return 0;
393 TString argument=argv[i];
395 if (argument.CompareTo("-solenoidBz")==0){
396 if (++i>=argc) return -EPROTO;
398 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
400 HLTError("CalibDB instance cannot be created.");
403 Float_t magneticField = argument.Atof();
404 calib->SetExBField(magneticField);
405 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
409 if (argument.CompareTo("-change-dataId")==0){
410 HLTDebug("Change data ID received.");
415 if (argument.CompareTo("-charge-threshold")==0) {
416 if (++i>=argc) return -EPROTO;
418 fChargeThreshold=(UInt_t)argument.Atoi();
419 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
423 if (argument.CompareTo("-publish-raw")==0) {
424 fPublishRawClusters=kTRUE;
432 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
433 // see header file for class documentation
434 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
437 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
438 // see header file for class documentation
440 HLTInfo("The size is: %d", size);
441 for(Int_t n32bit=0; n32bit<size; n32bit++){
443 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
444 // cout << "word ptr initialized"<<endl;
445 for(Int_t w=3;w>=0;w--){
446 // cout <<"accessing word"<<endl;
447 AliHLTUInt8_t word = wordPtr[w];
448 // cout<< "word was accessed"<<endl;
449 for(int n=7; n>=0; n--){
450 //print the byte values
451 if((((word>>n)<<7)&0x80) != 0){
462 } // end of PrintDebug
464 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
466 // Get a list of OCDB object description needed for the particular component
467 if (!targetMap) return;
469 // OCDB entries for component arguments
471 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
473 // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
474 targetMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("unknown content"));
475 targetMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("drift velocity calibration"));
476 targetMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("temperature map"));
477 targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
478 targetMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("cluster parameters"));
480 // OCDB entries needed to be fetched by the Pendolino
481 targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
482 targetMap->Add(new TObjString("GRP/CTP/CTPtiming"), new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
484 // OCDB entries necessary for replaying data on the HLT cluster
485 targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));
487 // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
488 targetMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("time0 offset pad by pad"));
489 targetMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("pad noise values"));
490 targetMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("pedestal info"));
491 targetMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("pulser info"));
492 targetMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("CE laser calibration result"));
493 targetMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("unknown content"));
494 targetMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("not important"));
495 targetMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("unknown content"));
496 targetMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("Goofie values, not used at the moment (05.03.2010)"));
497 targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
498 targetMap->Add(new TObjString("TPC/Calib/Ref"), new TObjString("unknown content"));