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"
36 #include "AliTPCCalPad.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBEntry.h"
42 #include "TObjString.h"
47 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
49 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
51 fOfflineTransform(NULL),
54 // see header file for class documentation
56 // refer to README to build package
58 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
61 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() {
62 // see header file for class documentation
65 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() {
66 // see header file for class documentation
68 return "TPCHWClusterTransform";
71 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
72 // see header file for class documentation
75 list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
78 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() {
79 // see header file for class documentation
81 return AliHLTTPCDefinitions::fgkClustersDataType;
84 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
85 // see header file for class documentation
88 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
89 return tgtList.size();
92 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
93 // see header file for class documentation
95 inputMultiplier = 3.0;
98 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
99 // see header file for class documentation
101 return new AliHLTTPCHWClusterTransformComponent();
104 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) {
105 // see header file for class documentation
107 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
109 !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
110 HLTError("Cannot retrieve offline transform from AliTPCcalibDB (%p)", pCalib);
119 TString configuration="";
121 for(int j=0; j<argc && iResult>=0; j++){
123 if (!configuration.IsNull()) configuration+=" ";
124 configuration+=argument;
127 if (!configuration.IsNull()) {
128 iResult=Configure(configuration.Data());
131 //iResult=Reconfigure(NULL, NULL);
137 int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
138 // see header file for class documentation
143 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData,
144 const AliHLTComponentBlockData* blocks,
145 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
146 AliHLTUInt32_t& size,
147 vector<AliHLTComponentBlockData>& outputBlocks ){
148 // see header file for class documentation
150 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
155 const AliHLTComponentBlockData *iter = NULL;
158 AliHLTTPCClusterData* outPtr;
160 AliHLTUInt8_t* outBPtr;
161 UInt_t offset, mysize, nSize, tSize = 0;
164 outPtr = (AliHLTTPCClusterData*)outBPtr;
166 AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
168 unsigned long maxPoints = 0;
170 for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
176 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
177 evtData.fEventID, evtData.fEventID,
178 DataType2Text( iter->fDataType).c_str(),
179 DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());
181 if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;
183 UInt_t minSlice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
184 UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
185 //UInt_t maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr(*iter);
186 //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
188 HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
190 outPtr = (AliHLTTPCClusterData*)outBPtr;
191 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
193 AliHLTUInt32_t *buffer;
194 buffer = (AliHLTUInt32_t*)iter->fPtr;
197 //cluster fabrication
198 buffer = new AliHLTUInt32_t[14];
200 buffer[0]=0xffffffff;
201 buffer[1]=0xffffffff;
202 buffer[2]=0xffffffff;
203 buffer[3]=0xffffffff;
204 buffer[4]=0xffffffff;
205 buffer[5]=0xffffffff;
206 buffer[6]=0xffffffff;
207 buffer[7]=0xffffffff;
209 buffer[8]=0xC60002EF;
215 buffer[13]=0x80000000;
218 Int_t sector=-99, thisrow=-99;
220 // PrintDebug(buffer, 14);
222 // skip the first 8 32-bit CDH words
225 //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
227 unsigned long nAddedClusters = 0;
229 for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
230 // for(UInt_t nWords=0; nWords<5; nWords+=5){
232 // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
233 AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
235 if(bit3130 == 0x3){ //beginning of a cluster
237 //PrintDebug(&buffer[nWords], 5);
239 if(nAddedClusters>=maxPoints){
240 HLTWarning("No more space to add clusters, exiting!");
244 AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
247 AliHLTUInt32_t rowCharge = buffer[nWords];
248 AliHLTUInt8_t *rowPtr = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);
249 rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
251 cluster.fPadRow = (UChar_t)((*rowPtr)&0x3f);
252 cluster.fCharge = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
254 Float_t tmpPad = *((Float_t*)&buffer[nWords+1]);
255 Float_t tmpTime = *((Float_t*)&buffer[nWords+2]);
256 //cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
257 //cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
259 // correct expressions for the error calculation
261 cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
262 cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
264 Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
266 HLTDebug("padrow: %d, charge: %f, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (Float_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);
268 if(fOfflineTransform == NULL){
269 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
270 AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);
271 AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, tmpPad, tmpTime);
272 if(minSlice>17) xyz[1]=(-1)*xyz[1];
278 cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);
279 AliHLTTPCTransform::Slice2Sector(minSlice, (UInt_t)cluster.fPadRow, sector, thisrow);
280 Double_t x[3] = {(Double_t)cluster.fPadRow,tmpPad+.5,tmpTime};
281 Int_t iSector[1]= {sector};
282 fOfflineTransform->Transform(x,iSector,0,1);
288 HLTDebug("cluster X: %f, Y: %f, Z: %f \n", cluster.fX, cluster.fY, cluster.fZ);
289 spacePoints[nAddedClusters] = cluster;
292 } // end of clusters starting with 11=0x3
293 else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
296 } // end of loop over clusters
298 HLTDebug("Number of found clusters: %d", nAddedClusters);
300 outPtr->fSpacePointCnt = nAddedClusters;
301 nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
302 mysize += nSize+sizeof(AliHLTTPCClusterData);
304 AliHLTComponentBlockData bd;
308 bd.fSpecification = iter->fSpecification;
310 if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
311 else bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
313 //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
315 outputBlocks.push_back( bd );
319 outPtr = (AliHLTTPCClusterData*)outBPtr;
321 } // end of loop over data blocks
326 int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) {
327 // see header file for class documentation
330 if (!arguments) return iResult;
331 HLTInfo("parsing configuration string \'%s\'", arguments);
333 TString allArgs=arguments;
337 TObjArray* pTokens=allArgs.Tokenize(" ");
339 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
340 argument=((TObjString*)pTokens->At(i))->GetString();
341 if (argument.IsNull()) continue;
343 if (argument.CompareTo("-change-dataId")==0) {
345 HLTInfo("got \'-change-dataId\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
348 HLTError("unknown argument %s", argument.Data());
359 HLTError("missing parameter for argument %s", argument.Data());
365 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* cdbEntry, const char* chainId) {
366 // see header file for class documentation
369 const char* path="HLT/ConfigTPC/TPCHWClusterTransform";
370 const char* defaultNotify="";
373 defaultNotify=" (default)";
377 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
378 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
380 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
382 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
383 iResult=Configure(pString->GetString().Data());
385 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
388 HLTError("cannot fetch object \"%s\" from CDB", path);
394 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
395 // see header file for class documentation
397 HLTInfo("The size is: %d", size);
398 for(Int_t n32bit=0; n32bit<size; n32bit++){
400 AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
401 // cout << "word ptr initialized"<<endl;
402 for(Int_t w=3;w>=0;w--){
403 // cout <<"accessing word"<<endl;
404 AliHLTUInt8_t word = wordPtr[w];
405 // cout<< "word was accessed"<<endl;
406 for(int n=7; n>=0; n--){
407 //print the byte values
408 if((((word>>n)<<7)&0x80) != 0){
419 } // end of PrintDebug