1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 // The HitRec Component is designed to deal the rawdata inputfiles to findout the
21 // the reconstructed hits. The output is send to the output block for further
24 // Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com )
32 #include "AliHLTMUONHitReconstructorComponent.h"
33 #include "AliHLTMUONHitReconstructor.h"
34 #include "AliHLTMUONRecHitsBlockStruct.h"
35 #include "AliHLTLogging.h"
36 #include "AliHLTSystem.h"
37 #include "AliHLTDefinitions.h"
43 // The global object used for automatic component registration,
44 // Note DO NOT use this component for calculation!
45 AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent;
48 ClassImp(AliHLTMUONHitReconstructorComponent)
51 AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent()
55 // see header file for class documentation
58 AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
60 // see header file for class documentation
64 int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv ){
65 // see header file for class documentation
67 fHitRec = new AliHLTMUONHitReconstructor();
69 HLTInfo("dHLT hitrec");
70 if (argc==0 && argv==NULL) {
71 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Arguments missing", " no arguments" );
72 // this is just to get rid of the warning "unused parameter"
76 char lutFileName[500],buspatchFileName[500];
79 if ( !strcmp( argv[i], "lut" ) ) {
81 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing LookupTable filename", "LookupTable filename not specified" );
82 return EINVAL; /* Invalid argument */
85 sprintf(lutFileName,"%s",argv[i+1]);
91 if ( !strcmp( argv[i], "ddl" ) ) {
93 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing DDL argument", "DDL number not specified" );
94 HLTError("AliHLTMUONHitReconstructorComponent::DoInit : DDL number is not specified ");
95 return EINVAL; /* Invalid argument */
98 iDDL = atoi(argv[i+1]);
104 if ( !strcmp( argv[i], "buspatchmap" ) ) {
106 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing buspatch filename", "buspatch filename not specified" );
107 return EINVAL; /* Invalid argument */
110 sprintf(buspatchFileName,"%s",argv[i+1]);
114 }// buspatch argument
118 }// end of while loop
120 int lutline = fHitRec->GetLutLine(iDDL);
121 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
122 if(!ReadLookUpTable(lookupTable,lutFileName,iDDL)){
123 Logging(kHLTLogInfo, "AliHLTMUONHitReconstructorComponent::DoInit", "Failed to read lut", "lut cannot be read, DoInit");
124 return ENOENT ; /* No such file or directory */
126 for(int i = 0;i<lutline; i++){
128 // printf("%d\t%d\t%d\t%f\t%f\t%f\t%d\t\n",
129 // lookupTable[i].fIdManuChannel,
130 // lookupTable[i].fIX,
131 // lookupTable[i].fIY,
132 // lookupTable[i].fRealX,
133 // lookupTable[i].fRealY,
134 // lookupTable[i].fRealZ,
135 // lookupTable[i].fPcbZone,
136 // lookupTable[i].fPlane
141 BusToDetElem busToDetElem;
142 if(!ReadBusPatchToDetElemFile(busToDetElem,buspatchFileName)){
143 Logging(kHLTLogInfo, "AliHLTMUONHitReconstructorComponent::DoInit", "Failed to read buspatchmap", "buspatchmap cannot be read, DoInit");
144 return ENOENT ; /* No such file or directory */
147 fHitRec->SetBusToDetMap(busToDetElem);
148 fHitRec->LoadLookUpTable(lookupTable,iDDL);
155 int AliHLTMUONHitReconstructorComponent::DoDeinit(){
156 // see header file for class documentation
159 HLTInfo("dHLT hitrec");
163 int AliHLTMUONHitReconstructorComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
164 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
165 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
166 // see header file for class documentation
167 HLTInfo("dHLT hitrec");
169 // if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
170 // outputPtr==0 && size==0)
172 // outputBlocks.clear();
173 // // this is just to get rid of the warning "unused parameter"
176 unsigned long totalSize = 0;
177 unsigned long mySize;
178 //cout<<"Block Count : "<<evtData.fBlockCnt<<endl;
179 for(UInt_t i=0;i<evtData.fBlockCnt;i++){
181 cout<<"0: totalsize : "<<totalSize<<"\tkAliHLTBlockAlignment :"<<kAliHLTBlockAlignment<<"\t size :"<<size<<endl;
183 // Align the beginning of this block to the required value.
184 // if ( totalSize % kAliHLTBlockAlignment ){
185 // totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
188 if ( totalSize > size )
191 cout<<"1: totalsize : "<<totalSize<<"\tkAliHLTBlockAlignment :"<<kAliHLTBlockAlignment<<endl;
192 // Determine the size we should use for the output for this block (the input block's size times the relative output size)
195 int totalDDLSize = blocks[i].fSize/4;
196 int ddlRawDataSize = totalDDLSize - AliHLTMUONHitReconstructor::GetkDDLHeaderSize();
198 memcpy((char *) & ddlHeader,blocks[i].fPtr,(size_t)4*(AliHLTMUONHitReconstructor::GetkDDLHeaderSize()));
200 // for(int j=0;j<8;j++)
201 // HLTDebug("ddlHeader[%d] : %d\n",j,ddlHeader[j]);
203 int* buffer = new int[ddlRawDataSize];
204 memcpy((int*)buffer,((int*)blocks[i].fPtr + AliHLTMUONHitReconstructor::GetkDDLHeaderSize()),(sizeof(int)*ddlRawDataSize));
206 // for(int j=0;j<ddlRawDataSize;j++)
207 // HLTDebug("buffer[%d] : %x\n",j,buffer[j]);
210 AliHLTMUONRecHitStruct recHit[300];
213 if(! (fHitRec->Run(buffer,&ddlRawDataSize,recHit,&nofHit))){
214 cerr <<"AliHLTMUONHitReconstructorComponent::DoEvent : ERROR In Processing of HitRec Algo "<< endl;
218 mySize = sizeof(AliHLTMUONRecHitStruct)*nofHit;
220 HLTInfo("mySize set (1) mySize == %lu B - blocks[%lu].fSize == %lu",
221 mySize, i, blocks[i].fSize);
223 // Check how much space we have left and adapt this output block's size accordingly.
224 if ( totalSize + mySize > size )
225 mySize = size-totalSize;
227 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
228 mySize, totalSize, size );
231 continue; // No room left to write a further block.
233 // Now copy the input block
234 unsigned long copied = 0;
235 // First copy all full multiples of the input block
236 while ( copied+blocks[i].fSize <= mySize )
238 Logging( kHLTLogInfo, "0 : HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
239 blocks[i].fSize, copied, totalSize );
240 memcpy( outputPtr+totalSize+copied, blocks[i].fPtr, blocks[i].fSize );
241 copied += blocks[i].fSize;
243 // And the copy the remaining fragment of the block
244 Logging( kHLTLogInfo, "1 : HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B",
245 mySize-copied, copied, totalSize );
246 memcpy( outputPtr+totalSize+copied, blocks[i].fPtr, mySize-copied );
247 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B",
252 AliHLTComponentBlockData bd;
254 bd.fOffset = totalSize;;
256 //bd.fPtr = (AliHLTUInt8_t*)(&recHit[0]);
257 bd.fSpecification = blocks[i].fSpecification;
258 outputBlocks.push_back( bd );
262 // for(int j=0; j<nofHit; j++){
263 // printf("%d\t\t%d\t\t%f\t%f\t%f\n",
264 // i,outPtr->fRecPoint[j].fDetElemId,outPtr->fRecPoint[j].fX,
265 // outPtr->fRecPoint[j].fY,outPtr->fRecPoint[j].fZ);
266 // printf("1 : %d\t\t%d\t\t%f\t%f\t%f\n",
267 // i,(((AliHLTMUONRecHitStruct*)bd.fPtr) + j)->fDetElemId,
268 // (((AliHLTMUONRecHitStruct*)bd.fPtr) + j)->fX,
269 // (((AliHLTMUONRecHitStruct*)bd.fPtr) + j)->fY,
270 // (((AliHLTMUONRecHitStruct*)bd.fPtr) + j)->fZ);
274 if(totalSize > size){
275 cout<<"size : "<<size<<"\t totalSize: "<<totalSize<<"\t mySize :"<<mySize<<endl;
276 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoEvent", "Size exceeds the quota", "Size Exceeds the maximum quota" );
288 bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(
289 AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath, int iDDL
292 // Reads in a lookup table for the hit reconstruction algorithm from file.
294 if (iDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
295 iDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL())
297 // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "Invalid DDL")
298 // << "DDL number is out of range (must be " << AliHLTLog::kDec << HLTMUONHitRec::fgkDDLOffSet
299 // << " <= iDDL < " << AliHLTLog::kDec
300 // << HLTMUONHitRec::fgkDDLOffSet + HLTMUONHitRec::fgkNofDDL
305 int lutLine = fHitRec->GetLutLine(iDDL);
306 // cout<<"LutLine :"<<lutLine<<endl;
307 FILE* fin = fopen(lutpath, "r");
310 // LOG(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "I/O error")
311 // << "Failed to open file: " << lutpath << ENDLOG;
316 // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "Trace")
317 // << "Reading LUT file: " << lutpath << ENDLOG;
320 for(int i=0;i<lutLine;i++)
324 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
325 &lookupTable[i].fIdManuChannel,
328 &lookupTable[i].fRealX,
329 &lookupTable[i].fRealY,
330 &lookupTable[i].fRealZ,
331 &lookupTable[i].fPcbZone,
332 &lookupTable[i].fPlane
340 // implement this as well.
342 bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(
343 BusToDetElem& busToDetElem, const char* buspatchmappath
346 // Loads the bus patch to detector element ID map from an ASCII file.
350 int detElem, minBusPatch, maxBusPatch;
352 FILE* fin = fopen(buspatchmappath, "r");
355 // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "I/O error")
356 // << "Failed to open file: " << buspatchmappath << ENDLOG;
361 // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "Trace")
362 // << "Reading bus patch mapping file: " << buspatchmappath << ENDLOG;
367 fgets(getLine,80,fin);
368 sscanf(getLine, "%d\t%d %c %d", &detElem, &minBusPatch, &temp, &maxBusPatch);
369 if (detElem >= 700 && detElem <= 1025)
371 for(int i = minBusPatch; i <= maxBusPatch; i++)
372 busToDetElem[i] = detElem;
374 } // while loop for file