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"
35 #include "AliCDBManager.h"
36 #include "AliCDBEntry.h"
37 #include "AliTPCcalibDB.h"
40 #include "TObjString.h"
45 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
47 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
49 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
54 fBenchmark("HWClusterTransform")
56 // see header file for class documentation
58 // refer to README to build package
60 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63 fBenchmark.SetTimer(0,"total");
66 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
67 // see header file for class documentation
70 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
71 // see header file for class documentation
73 return "TPCHWClusterTransform";
76 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
77 // see header file for class documentation
80 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
83 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
84 // see header file for class documentation
86 return AliHLTTPCDefinitions::fgkClustersDataType;
89 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
90 // see header file for class documentation
93 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
94 tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
95 return tgtList.size();
98 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
99 // see header file for class documentation
101 inputMultiplier = 3.0;
104 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
105 // see header file for class documentation
107 return new AliHLTTPCHWClusterTransformComponent();
110 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
111 // see header file for class documentation
113 AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
115 HLTError("AliTPCcalibDB does not exist");
118 calib->SetRun(GetRunNo());
119 calib->UpdateRunInformations(GetRunNo());
121 int err = fTransform.Init( GetBz(), GetTimeStamp() );
124 HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
129 iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
131 if (iResult>=0 && argc>0)
132 iResult=ConfigureFromArgumentString(argc, argv);
137 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
138 // see header file for class documentation
142 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
143 const AliHLTComponentBlockData* blocks,
144 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
145 AliHLTUInt32_t& size,
146 vector<AliHLTComponentBlockData>& outputBlocks ){
147 // see header file for class documentation
149 UInt_t maxOutSize = size;
152 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
156 fBenchmark.StartNewEvent();
159 fTransform.SetCurrentTimeStamp( GetTimeStamp() );
161 for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
163 const AliHLTComponentBlockData *iter = blocks+ndx;
165 fBenchmark.AddInput(iter->fSize);
167 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
168 evtData.fEventID, evtData.fEventID,
169 DataType2Text( iter->fDataType).c_str(),
170 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
172 if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
173 // simply forward MC labels
175 if( size+iter->fSize > maxOutSize ){
176 HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
181 memcpy( outputPtr, iter->fPtr, iter->fSize );
183 AliHLTComponentBlockData bd;
186 bd.fSize = iter->fSize;
187 bd.fSpecification = iter->fSpecification;
188 bd.fDataType = iter->fDataType;
189 outputBlocks.push_back( bd );
190 fBenchmark.AddOutput(bd.fSize);
192 outputPtr += bd.fSize;
196 if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;
198 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
199 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
200 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
201 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
203 fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
205 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
207 AliHLTTPCClusterData* outPtr = (AliHLTTPCClusterData*)outputPtr;
209 long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
212 AliHLTUInt32_t *buffer;
213 buffer = (AliHLTUInt32_t*)iter->fPtr;
216 //cluster fabrication
217 buffer = new AliHLTUInt32_t[14];
219 buffer[0]=0xffffffff;
220 buffer[1]=0xffffffff;
221 buffer[2]=0xffffffff;
222 buffer[3]=0xffffffff;
223 buffer[4]=0xffffffff;
224 buffer[5]=0xffffffff;
225 buffer[6]=0xffffffff;
226 buffer[7]=0xffffffff;
228 buffer[8]=0xC60002EF;
234 buffer[13]=0x80000000;
237 // PrintDebug(buffer, 14);
239 // skip the first 8 32-bit CDH words
241 UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
243 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
245 long nAddedClusters = 0;
247 for(UInt_t nWords=0; nWords<bufferSize32; nWords+=5){
248 // for(UInt_t nWords=0; nWords<5; nWords+=5){
250 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
251 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
253 if(bit3130 == 0x3){ //beginning of a cluster
255 //PrintDebug(&buffer[nWords], 5);
257 if(nAddedClusters>=maxPoints){
258 HLTWarning("No more space to add clusters, exiting!");
263 AliHLTTPCSpacePointData cluster;
266 AliHLTUInt32_t rowCharge = buffer[nWords];
267 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
268 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
270 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
271 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
273 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
274 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
275 cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
276 cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
279 if(cluster.fCharge<fChargeThreshold) continue;
281 // correct expressions for the error calculation
282 // Kenneth: 12.11.2009 I'm not sure if this is a correct calculation. Leave it out for now since it is anyway not used later since it caused segfaults.
283 // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
284 // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
286 HLTDebug("padrow: %d, charge: %d, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (UInt_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);
288 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
291 fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
296 // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
297 cluster.SetID( minSlice, minPartition, nAddedClusters );
299 HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
300 outPtr->fSpacePoints[nAddedClusters] = cluster;
303 } // end of clusters starting with 11=0x3
304 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
307 } // end of loop over clusters
309 HLTDebug("Number of found clusters: %d", nAddedClusters);
311 outPtr->fSpacePointCnt = nAddedClusters;
313 UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
315 AliHLTComponentBlockData bd;
319 bd.fSpecification = iter->fSpecification;
320 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
321 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
323 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
325 outputBlocks.push_back( bd );
327 fBenchmark.AddOutput(bd.fSize);
331 } // end of loop over data blocks
334 HLTInfo(fBenchmark.GetStatistics());
339 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
341 // see header file for class documentation
343 if (argc<=0) return 0;
345 TString argument=argv[i];
347 if (argument.CompareTo("-solenoidBz")==0){
348 if (++i>=argc) return -EPROTO;
350 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
352 HLTError("CalibDB instance cannot be created.");
355 Float_t magneticField = argument.Atof();
356 calib->SetExBField(magneticField);
357 HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
361 if (argument.CompareTo("-change-dataId")==0){
362 HLTDebug("Change data ID received.");
367 if (argument.CompareTo("-charge-threshold")==0) {
368 if (++i>=argc) return -EPROTO;
370 fChargeThreshold=(UInt_t)argument.Atoi();
371 HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
379 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
380 // see header file for class documentation
381 return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
384 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
385 // see header file for class documentation
387 HLTInfo("The size is: %d", size);
388 for(Int_t n32bit=0; n32bit<size; n32bit++){
390 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
391 // cout << "word ptr initialized"<<endl;
392 for(Int_t w=3;w>=0;w--){
393 // cout <<"accessing word"<<endl;
394 AliHLTUInt8_t word = wordPtr[w];
395 // cout<< "word was accessed"<<endl;
396 for(int n=7; n>=0; n--){
397 //print the byte values
398 if((((word>>n)<<7)&0x80) != 0){
409 } // end of PrintDebug
411 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
413 // Get a list of OCDB object description needed for the particular component
414 if (!targetMap) return;
416 // OCDB entries for component arguments
418 targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
420 // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
421 targetMap->Add(new TObjString("TPC/Calib/Parameters"), new TObjString("unknown content"));
422 targetMap->Add(new TObjString("TPC/Calib/TimeDrift"), new TObjString("drift velocity calibration"));
423 targetMap->Add(new TObjString("TPC/Calib/Temperature"), new TObjString("temperature map"));
424 targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
425 targetMap->Add(new TObjString("TPC/Calib/ClusterParam"), new TObjString("cluster parameters"));
427 // OCDB entries needed to be fetched by the Pendolino
428 targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
429 targetMap->Add(new TObjString("GRP/CTP/CTPtiming"), new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
431 // OCDB entries necessary for replaying data on the HLT cluster
432 targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));
434 // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
435 targetMap->Add(new TObjString("TPC/Calib/PadTime0"), new TObjString("time0 offset pad by pad"));
436 targetMap->Add(new TObjString("TPC/Calib/PadNoise"), new TObjString("pad noise values"));
437 targetMap->Add(new TObjString("TPC/Calib/Pedestals"), new TObjString("pedestal info"));
438 targetMap->Add(new TObjString("TPC/Calib/Pulser"), new TObjString("pulser info"));
439 targetMap->Add(new TObjString("TPC/Calib/CE"), new TObjString("CE laser calibration result"));
440 targetMap->Add(new TObjString("TPC/Calib/Raw"), new TObjString("unknown content"));
441 targetMap->Add(new TObjString("TPC/Calib/QA"), new TObjString("not important"));
442 targetMap->Add(new TObjString("TPC/Calib/Mapping"), new TObjString("unknown content"));
443 targetMap->Add(new TObjString("TPC/Calib/Goofie"), new TObjString("Goofie values, not used at the moment (05.03.2010)"));
444 targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
445 targetMap->Add(new TObjString("TPC/Calib/Ref"), new TObjString("unknown content"));