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"
34 #include "AliTPCcalibDB.h"
35 #include "AliTPCTransform.h"
42 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
44 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
46 fOfflineTransform(NULL)
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
57 // see header file for class documentation
60 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
61 // see header file for class documentation
63 return "TPCHWClusterTransform";
66 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
67 // see header file for class documentation
70 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
73 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
74 // see header file for class documentation
76 return AliHLTTPCDefinitions::fgkClustersDataType;
79 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
80 // see header file for class documentation
83 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
84 return tgtList.size();
87 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
88 // see header file for class documentation
91 inputMultiplier = 2.0;
94 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
95 // see header file for class documentation
97 return new AliHLTTPCHWClusterTransformComponent();
100 int AliHLTTPCHWClusterTransformComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
101 // see header file for class documentation
103 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
105 !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
106 HLTError("Can not retrieve Offline transform from AliTPCcalibDB (%p)", pCalib);
115 // TString configuration="";
116 // TString argument="";
117 // for (int j=0; j<argc && iResult>=0; j++) {
120 // if (!configuration.IsNull()) configuration+=" ";
121 // configuration+=argument;
124 // if (!configuration.IsNull()) {
125 // iResult=Configure(configuration.Data());
127 // iResult=Reconfigure(NULL, NULL);
133 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
134 // see header file for class documentation
139 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
140 const AliHLTComponentBlockData* blocks,
141 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
142 AliHLTUInt32_t& size,
143 vector<AliHLTComponentBlockData>& outputBlocks ){
144 // see header file for class documentation
146 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
151 const AliHLTComponentBlockData *iter = NULL;
154 AliHLTTPCClusterData* outPtr;
156 AliHLTUInt8_t* outBPtr;
157 UInt_t offset, mysize, nSize, tSize = 0;
160 outPtr = (AliHLTTPCClusterData*)outBPtr;
162 AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
164 unsigned long maxPoints = 0;
166 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
172 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
173 evtData.fEventID, evtData.fEventID,
174 DataType2Text( iter->fDataType).c_str(),
175 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
177 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
179 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
180 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
181 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
182 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
184 outPtr = (AliHLTTPCClusterData*)outBPtr;
185 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
187 AliHLTUInt32_t *buffer;
188 buffer = (AliHLTUInt32_t*)iter->fPtr;
191 //cluster fabrication
192 buffer = new AliHLTUInt32_t[14];
194 buffer[0]=0xffffffff;
195 buffer[1]=0xffffffff;
196 buffer[2]=0xffffffff;
197 buffer[3]=0xffffffff;
198 buffer[4]=0xffffffff;
199 buffer[5]=0xffffffff;
200 buffer[6]=0xffffffff;
201 buffer[7]=0xffffffff;
203 buffer[8]=0xC60002EF;
209 buffer[13]=0x80000000;
212 Int_t sector=-99, thisrow=-99;
214 // PrintDebug(buffer, 14);
216 // skip the first 8 32-bit CDH words
219 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
221 unsigned long nAddedClusters = 0;
223 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
224 // for(UInt_t nWords=0; nWords<5; nWords+=5){
226 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
227 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
229 if(bit3130 == 0x3){ //beginning of a cluster
231 //PrintDebug(&buffer[nWords], 5);
233 if(nAddedClusters>=maxPoints){
234 HLTWarning("No more space to add clusters, exiting!");
238 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
241 AliHLTUInt32_t rowCharge = buffer[nWords];
242 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
243 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
245 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
246 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
247 cluster.fSigmaY2 = (Float_t)buffer[nWords+3];
248 cluster.fSigmaZ2 = (Float_t)buffer[nWords+4];
250 // correct expressions for the error calculation
252 //cluster.fSigmaY2 = TMath::Sqrt( (Float_t)buffer[nWords+3] - (Float_t)buffer[nWords+1]*(Float_t)buffer[nWords+1] );
253 //cluster.fSigmaY2 = TMath::Sqrt( (Float_t)buffer[nWords+3] - (Float_t)buffer[nWords+1]*(Float_t)buffer[nWords+1] );
257 HLTInfo("padrow: %d, charge: %f, pad: %d, time: %d", cluster.fPadRow, (Float_t)cluster.fCharge, (Float_t)buffer[nWords+1], (Float_t)buffer[nWords+2]);
259 Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
261 // if(fOfflineTransform == NULL){
262 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
263 AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);
264 AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, (Float_t)buffer[nWords+1], (Float_t)buffer[nWords+2]);
265 if(minSlice>17) xyz[1]=(-1)*xyz[1];
272 // HLTInfo("padrow: %d, pad: %d", cluster.fPadRow, buffer[nWords+1]);
274 // Double_t x[3] = {thisrow, (Float_t)buffer[nWords+1]+.5, (Float_t)buffer[nWords+2]};
275 // Int_t iSector[1]= {sector};
276 // fOfflineTransform->Transform(x,iSector,0,1);
277 // cluster.fX = x[0];
278 // cluster.fY = x[1];
279 // cluster.fZ = x[2];
282 // cluster.fX = xyz[0];
283 // cluster.fY = xyz[1];
284 // cluster.fZ = xyz[2];
286 //HLTInfo("X: %f, Y: %f, Z: %f, Charge: %d", cluster.fX,cluster.fY,cluster.fZ, cluster.fCharge);
288 spacePoints[nAddedClusters] = cluster;
291 } // end of clusters starting with 11=0x3
292 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
295 } // end of loop over clusters
297 HLTDebug("Number of found clusters: %d", nAddedClusters);
299 outPtr->fSpacePointCnt = nAddedClusters;
300 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
301 mysize += nSize+sizeof(AliHLTTPCClusterData);
303 AliHLTComponentBlockData bd;
307 bd.fSpecification = iter->fSpecification;
308 bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
309 outputBlocks.push_back( bd );
313 outPtr = (AliHLTTPCClusterData*)outBPtr;
315 } // end of loop over data blocks
320 // int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) {
321 // // see header file for class documentation
324 // if (!arguments) return iResult;
325 // HLTInfo("parsing configuration string \'%s\'", arguments);
327 // TString allArgs=arguments;
329 // int bMissingParam=0;
331 // TObjArray* pTokens=allArgs.Tokenize(" ");
333 // for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
334 // argument=((TObjString*)pTokens->At(i))->GetString();
335 // if (argument.IsNull()) continue;
337 // if (argument.CompareTo("-sum-noise-histograms")==0) {
338 // fNoiseHistograms = kTRUE;
339 // HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
341 // } else if (argument.CompareTo("-sum-krypton-histograms")==0) {
342 // fKryptonHistograms = kTRUE;
343 // HLTInfo("got \'-sum-krypton-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
345 // } else if (argument.CompareTo("-use-general")==0) {
346 // fUseGeneral = kTRUE;
347 // HLTInfo("got \'-use-general\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
349 // } else if (argument.CompareTo("-ignore-specification")==0) {
350 // fIgnoreSpecification = kTRUE;
351 // HLTInfo("got \'-ignore-specification\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
354 // HLTError("unknown argument %s", argument.Data());
363 // } // end if pTokens
365 // if (bMissingParam) {
366 // HLTError("missing parameter for argument %s", argument.Data());
372 // int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
373 // // see header file for class documentation
376 // const char* path="HLT/ConfigTPC/TPCHistogramHandlerComponent";
377 // const char* defaultNotify="";
380 // defaultNotify=" (default)";
384 // HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
385 // AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
387 // TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
389 // HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
390 // iResult=Configure(pString->GetString().Data());
392 // HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
395 // HLTError("cannot fetch object \"%s\" from CDB", path);
402 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
403 // see header file for class documentation
405 HLTInfo("The size is: %d", size);
406 for(Int_t n32bit=0; n32bit<size; n32bit++){
408 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
409 // cout << "word ptr initialized"<<endl;
410 for(Int_t w=3;w>=0;w--){
411 // cout <<"accessing word"<<endl;
412 AliHLTUInt8_t word = wordPtr[w];
413 // cout<< "word was accessed"<<endl;
414 for(int n=7; n>=0; n--){
415 //print the byte values
416 if((((word>>n)<<7)&0x80) != 0){
427 } // end of PrintDebug