]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx
Adding change for GCC backward compatability.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONHitReconstructorComponent.cxx
CommitLineData
b0201cbe 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
baff881d 18///*
19//
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
22// processing.
23//
24// Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com )
25//
26//*/
b0201cbe 27
28#if __GNUC__>= 3
29using namespace std;
30#endif
31
32#include "AliHLTMUONHitReconstructorComponent.h"
b12fe461 33#include "AliHLTMUONHitReconstructor.h"
baff881d 34#include "AliHLTMUONRecHitsBlockStruct.h"
b0201cbe 35#include "AliHLTLogging.h"
36#include "AliHLTSystem.h"
37#include "AliHLTDefinitions.h"
38#include <stdlib.h>
39#include <errno.h>
40
41namespace
42{
43 // The global object used for automatic component registration,
44 // Note DO NOT use this component for calculation!
45 AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent;
46}
47
b0201cbe 48ClassImp(AliHLTMUONHitReconstructorComponent)
49
50
51AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent()
52 :
53 fHitRec(NULL)
54{
55 // see header file for class documentation
56}
57
58AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
59{
60 // see header file for class documentation
61
62}
63
64int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv ){
65 // see header file for class documentation
66
b12fe461 67 fHitRec = new AliHLTMUONHitReconstructor();
b0201cbe 68
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"
73 }
74
75 Int_t i = 0;
76 char lutFileName[500],buspatchFileName[500];
baff881d 77 int iDDL = -1;
b0201cbe 78 while(i<argc){
79 if ( !strcmp( argv[i], "lut" ) ) {
80 if ( argc <= i+1 ) {
81 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing LookupTable filename", "LookupTable filename not specified" );
82 return EINVAL; /* Invalid argument */
83 }
84
85 sprintf(lutFileName,"%s",argv[i+1]);
86
87 i += 2;
88 continue;
89 }// lut argument
90
91 if ( !strcmp( argv[i], "ddl" ) ) {
92 if ( argc <= i+1 ) {
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 */
96 }
97
98 iDDL = atoi(argv[i+1]);
99
100 i += 2;
101 continue;
102 }// ddl argument
103
104 if ( !strcmp( argv[i], "buspatchmap" ) ) {
105 if ( argc <= i+1 ) {
106 Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing buspatch filename", "buspatch filename not specified" );
107 return EINVAL; /* Invalid argument */
108 }
109
110 sprintf(buspatchFileName,"%s",argv[i+1]);
111
112 i += 2;
113 continue;
114 }// buspatch argument
115
116
117
118 }// end of while loop
119
120 int lutline = fHitRec->GetLutLine(iDDL);
baff881d 121 AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
b0201cbe 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 */
125 }else{
126 for(int i = 0;i<lutline; i++){
127 //#ifdef MY_DEBUG
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
137// );
138 //#endif
139 }
140
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 */
145 }
146
147 fHitRec->SetBusToDetMap(busToDetElem);
148 fHitRec->LoadLookUpTable(lookupTable,iDDL);
149
150 }// reading lut
151
152 return 0;
153}
154
155int AliHLTMUONHitReconstructorComponent::DoDeinit(){
156 // see header file for class documentation
157 if(fHitRec)
158 delete fHitRec;
159 HLTInfo("dHLT hitrec");
160 return 0;
161}
162
163int 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");
168
169// if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
170// outputPtr==0 && size==0)
171// {
172// outputBlocks.clear();
173// // this is just to get rid of the warning "unused parameter"
174// }
175
176 unsigned long totalSize = 0;
177 unsigned long mySize;
178 //cout<<"Block Count : "<<evtData.fBlockCnt<<endl;
b12fe461 179 for(UInt_t i=0;i<evtData.fBlockCnt;i++){
b0201cbe 180
181 cout<<"0: totalsize : "<<totalSize<<"\tkAliHLTBlockAlignment :"<<kAliHLTBlockAlignment<<"\t size :"<<size<<endl;
182
183 // Align the beginning of this block to the required value.
184 // if ( totalSize % kAliHLTBlockAlignment ){
185 // totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
186 // }
187
188 if ( totalSize > size )
189 break;
190
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)
193
194
195 int totalDDLSize = blocks[i].fSize/4;
baff881d 196 int ddlRawDataSize = totalDDLSize - AliHLTMUONHitReconstructor::GetkDDLHeaderSize();
b0201cbe 197 int ddlHeader[8];
baff881d 198 memcpy((char *) & ddlHeader,blocks[i].fPtr,(size_t)4*(AliHLTMUONHitReconstructor::GetkDDLHeaderSize()));
b0201cbe 199
200// for(int j=0;j<8;j++)
201// HLTDebug("ddlHeader[%d] : %d\n",j,ddlHeader[j]);
202
203 int* buffer = new int[ddlRawDataSize];
baff881d 204 memcpy((int*)buffer,((int*)blocks[i].fPtr + AliHLTMUONHitReconstructor::GetkDDLHeaderSize()),(sizeof(int)*ddlRawDataSize));
b0201cbe 205
206// for(int j=0;j<ddlRawDataSize;j++)
207// HLTDebug("buffer[%d] : %x\n",j,buffer[j]);
208
209
b12fe461 210 AliHLTMUONRecHitStruct recHit[300];
b0201cbe 211 int nofHit = 300;
212
213 if(! (fHitRec->Run(buffer,&ddlRawDataSize,recHit,&nofHit))){
214 cerr <<"AliHLTMUONHitReconstructorComponent::DoEvent : ERROR In Processing of HitRec Algo "<< endl;
215 return EIO;
216 }
217
b12fe461 218 mySize = sizeof(AliHLTMUONRecHitStruct)*nofHit;
b0201cbe 219
220 HLTInfo("mySize set (1) mySize == %lu B - blocks[%lu].fSize == %lu",
221 mySize, i, blocks[i].fSize);
222
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;
226
227 Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu",
228 mySize, totalSize, size );
229
230 if ( mySize<=0 )
231 continue; // No room left to write a further block.
232
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 )
237 {
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;
242 }
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",
248 copied, totalSize );
249
250
251
252 AliHLTComponentBlockData bd;
253 FillBlockData( bd );
254 bd.fOffset = totalSize;;
255 bd.fSize = mySize;
256 //bd.fPtr = (AliHLTUInt8_t*)(&recHit[0]);
257 bd.fSpecification = blocks[i].fSpecification;
258 outputBlocks.push_back( bd );
259
260 totalSize += mySize;
261
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",
b12fe461 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);
b0201cbe 271// }// nof RecHits
272
273
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" );
277 return EMSGSIZE;
278 }
279
280 }// block loop
281
282 size = totalSize;
283
284 return 0;
285}
286
287
288bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(
baff881d 289 AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath, int iDDL
b0201cbe 290 )
291{
baff881d 292// Reads in a lookup table for the hit reconstruction algorithm from file.
293
294 if (iDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
295 iDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL())
b0201cbe 296 {
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
301// << ENDLOG;
302 return false;
303 }
304
305 int lutLine = fHitRec->GetLutLine(iDDL);
306// cout<<"LutLine :"<<lutLine<<endl;
307 FILE* fin = fopen(lutpath, "r");
308 if (fin == NULL)
309 {
310// LOG(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "I/O error")
311// << "Failed to open file: " << lutpath << ENDLOG;
312 return false;
313 }
314
315# ifdef DEBUG
316// Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "Trace")
317// << "Reading LUT file: " << lutpath << ENDLOG;
318# endif
319
320 for(int i=0;i<lutLine;i++)
321 {
322 fscanf(
323 fin,
324 "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
325 &lookupTable[i].fIdManuChannel,
326 &lookupTable[i].fIX,
327 &lookupTable[i].fIY,
328 &lookupTable[i].fRealX,
329 &lookupTable[i].fRealY,
330 &lookupTable[i].fRealZ,
331 &lookupTable[i].fPcbZone,
332 &lookupTable[i].fPlane
333 );
334 }
335
336 fclose(fin);
337 return true;
338}
339
340// implement this as well.
341
342bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(
343 BusToDetElem& busToDetElem, const char* buspatchmappath
344 )
345{
baff881d 346// Loads the bus patch to detector element ID map from an ASCII file.
347
b0201cbe 348 char getLine[80];
349 char temp;
350 int detElem, minBusPatch, maxBusPatch;
351
352 FILE* fin = fopen(buspatchmappath, "r");
353 if (fin == NULL)
354 {
355// Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "I/O error")
356// << "Failed to open file: " << buspatchmappath << ENDLOG;
357 return false;
358 }
359
360# ifdef DEBUG
361// Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "Trace")
362// << "Reading bus patch mapping file: " << buspatchmappath << ENDLOG;
363# endif
364
365 while (feof(fin)==0)
366 {
367 fgets(getLine,80,fin);
368 sscanf(getLine, "%d\t%d %c %d", &detElem, &minBusPatch, &temp, &maxBusPatch);
369 if (detElem >= 700 && detElem <= 1025)
370 {
371 for(int i = minBusPatch; i <= maxBusPatch; i++)
372 busToDetElem[i] = detElem;
373 } // detElem condn
374 } // while loop for file
375
376 fclose(fin);
377 return true;
378}