]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | */ | |
27 | ||
28 | #if __GNUC__>= 3 | |
29 | using namespace std; | |
30 | #endif | |
31 | ||
32 | #include "AliHLTMUONHitReconstructorComponent.h" | |
33 | #include "AliHLTLogging.h" | |
34 | #include "AliHLTSystem.h" | |
35 | #include "AliHLTDefinitions.h" | |
36 | #include <stdlib.h> | |
37 | #include <errno.h> | |
38 | ||
39 | namespace | |
40 | { | |
41 | // The global object used for automatic component registration, | |
42 | // Note DO NOT use this component for calculation! | |
43 | AliHLTMUONHitReconstructorComponent gAliHLTMUONHitReconstructorComponent; | |
44 | } | |
45 | ||
46 | ||
47 | ClassImp(AliHLTMUONHitReconstructorComponent) | |
48 | ||
49 | ||
50 | AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() | |
51 | : | |
52 | fHitRec(NULL) | |
53 | { | |
54 | // see header file for class documentation | |
55 | } | |
56 | ||
57 | AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() | |
58 | { | |
59 | // see header file for class documentation | |
60 | ||
61 | } | |
62 | ||
63 | int AliHLTMUONHitReconstructorComponent::DoInit( int argc, const char** argv ){ | |
64 | // see header file for class documentation | |
65 | ||
66 | fHitRec = new AliHLTMUONHitRec(); | |
67 | ||
68 | HLTInfo("dHLT hitrec"); | |
69 | if (argc==0 && argv==NULL) { | |
70 | Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Arguments missing", " no arguments" ); | |
71 | // this is just to get rid of the warning "unused parameter" | |
72 | } | |
73 | ||
74 | Int_t i = 0; | |
75 | char lutFileName[500],buspatchFileName[500]; | |
76 | int iDDL; | |
77 | while(i<argc){ | |
78 | if ( !strcmp( argv[i], "lut" ) ) { | |
79 | if ( argc <= i+1 ) { | |
80 | Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing LookupTable filename", "LookupTable filename not specified" ); | |
81 | return EINVAL; /* Invalid argument */ | |
82 | } | |
83 | ||
84 | sprintf(lutFileName,"%s",argv[i+1]); | |
85 | ||
86 | i += 2; | |
87 | continue; | |
88 | }// lut argument | |
89 | ||
90 | if ( !strcmp( argv[i], "ddl" ) ) { | |
91 | if ( argc <= i+1 ) { | |
92 | Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing DDL argument", "DDL number not specified" ); | |
93 | HLTError("AliHLTMUONHitReconstructorComponent::DoInit : DDL number is not specified "); | |
94 | return EINVAL; /* Invalid argument */ | |
95 | } | |
96 | ||
97 | iDDL = atoi(argv[i+1]); | |
98 | ||
99 | i += 2; | |
100 | continue; | |
101 | }// ddl argument | |
102 | ||
103 | if ( !strcmp( argv[i], "buspatchmap" ) ) { | |
104 | if ( argc <= i+1 ) { | |
105 | Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoInit", "Missing buspatch filename", "buspatch filename not specified" ); | |
106 | return EINVAL; /* Invalid argument */ | |
107 | } | |
108 | ||
109 | sprintf(buspatchFileName,"%s",argv[i+1]); | |
110 | ||
111 | i += 2; | |
112 | continue; | |
113 | }// buspatch argument | |
114 | ||
115 | ||
116 | ||
117 | }// end of while loop | |
118 | ||
119 | int lutline = fHitRec->GetLutLine(iDDL); | |
120 | DHLTLut* lookupTable = new DHLTLut[lutline]; | |
121 | if(!ReadLookUpTable(lookupTable,lutFileName,iDDL)){ | |
122 | Logging(kHLTLogInfo, "AliHLTMUONHitReconstructorComponent::DoInit", "Failed to read lut", "lut cannot be read, DoInit"); | |
123 | return ENOENT ; /* No such file or directory */ | |
124 | }else{ | |
125 | for(int i = 0;i<lutline; i++){ | |
126 | //#ifdef MY_DEBUG | |
127 | // printf("%d\t%d\t%d\t%f\t%f\t%f\t%d\t\n", | |
128 | // lookupTable[i].fIdManuChannel, | |
129 | // lookupTable[i].fIX, | |
130 | // lookupTable[i].fIY, | |
131 | // lookupTable[i].fRealX, | |
132 | // lookupTable[i].fRealY, | |
133 | // lookupTable[i].fRealZ, | |
134 | // lookupTable[i].fPcbZone, | |
135 | // lookupTable[i].fPlane | |
136 | // ); | |
137 | //#endif | |
138 | } | |
139 | ||
140 | BusToDetElem busToDetElem; | |
141 | if(!ReadBusPatchToDetElemFile(busToDetElem,buspatchFileName)){ | |
142 | Logging(kHLTLogInfo, "AliHLTMUONHitReconstructorComponent::DoInit", "Failed to read buspatchmap", "buspatchmap cannot be read, DoInit"); | |
143 | return ENOENT ; /* No such file or directory */ | |
144 | } | |
145 | ||
146 | fHitRec->SetBusToDetMap(busToDetElem); | |
147 | fHitRec->LoadLookUpTable(lookupTable,iDDL); | |
148 | ||
149 | }// reading lut | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
154 | int AliHLTMUONHitReconstructorComponent::DoDeinit(){ | |
155 | // see header file for class documentation | |
156 | if(fHitRec) | |
157 | delete fHitRec; | |
158 | HLTInfo("dHLT hitrec"); | |
159 | return 0; | |
160 | } | |
161 | ||
162 | int AliHLTMUONHitReconstructorComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, | |
163 | AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, | |
164 | AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) { | |
165 | // see header file for class documentation | |
166 | HLTInfo("dHLT hitrec"); | |
167 | ||
168 | // if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 && | |
169 | // outputPtr==0 && size==0) | |
170 | // { | |
171 | // outputBlocks.clear(); | |
172 | // // this is just to get rid of the warning "unused parameter" | |
173 | // } | |
174 | ||
175 | unsigned long totalSize = 0; | |
176 | unsigned long mySize; | |
177 | //cout<<"Block Count : "<<evtData.fBlockCnt<<endl; | |
178 | for(Int_t i=0;i<evtData.fBlockCnt;i++){ | |
179 | ||
180 | cout<<"0: totalsize : "<<totalSize<<"\tkAliHLTBlockAlignment :"<<kAliHLTBlockAlignment<<"\t size :"<<size<<endl; | |
181 | ||
182 | // Align the beginning of this block to the required value. | |
183 | // if ( totalSize % kAliHLTBlockAlignment ){ | |
184 | // totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment); | |
185 | // } | |
186 | ||
187 | if ( totalSize > size ) | |
188 | break; | |
189 | ||
190 | cout<<"1: totalsize : "<<totalSize<<"\tkAliHLTBlockAlignment :"<<kAliHLTBlockAlignment<<endl; | |
191 | // Determine the size we should use for the output for this block (the input block's size times the relative output size) | |
192 | ||
193 | ||
194 | int totalDDLSize = blocks[i].fSize/4; | |
195 | int ddlRawDataSize = totalDDLSize - AliHLTMUONHitRec::fgkDDLHeaderSize; | |
196 | int ddlHeader[8]; | |
197 | memcpy((char *) & ddlHeader,blocks[i].fPtr,(size_t)4*(AliHLTMUONHitRec::fgkDDLHeaderSize)); | |
198 | ||
199 | // for(int j=0;j<8;j++) | |
200 | // HLTDebug("ddlHeader[%d] : %d\n",j,ddlHeader[j]); | |
201 | ||
202 | int* buffer = new int[ddlRawDataSize]; | |
203 | memcpy((int*)buffer,((int*)blocks[i].fPtr + AliHLTMUONHitRec::fgkDDLHeaderSize),(sizeof(int)*ddlRawDataSize)); | |
204 | ||
205 | // for(int j=0;j<ddlRawDataSize;j++) | |
206 | // HLTDebug("buffer[%d] : %x\n",j,buffer[j]); | |
207 | ||
208 | ||
209 | AliHLTMUONRecPoint recHit[300]; | |
210 | int nofHit = 300; | |
211 | ||
212 | if(! (fHitRec->Run(buffer,&ddlRawDataSize,recHit,&nofHit))){ | |
213 | cerr <<"AliHLTMUONHitReconstructorComponent::DoEvent : ERROR In Processing of HitRec Algo "<< endl; | |
214 | return EIO; | |
215 | } | |
216 | ||
217 | mySize = sizeof(AliHLTMUONRecPoint)*nofHit; | |
218 | ||
219 | HLTInfo("mySize set (1) mySize == %lu B - blocks[%lu].fSize == %lu", | |
220 | mySize, i, blocks[i].fSize); | |
221 | ||
222 | // Check how much space we have left and adapt this output block's size accordingly. | |
223 | if ( totalSize + mySize > size ) | |
224 | mySize = size-totalSize; | |
225 | ||
226 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", | |
227 | mySize, totalSize, size ); | |
228 | ||
229 | if ( mySize<=0 ) | |
230 | continue; // No room left to write a further block. | |
231 | ||
232 | // Now copy the input block | |
233 | unsigned long copied = 0; | |
234 | // First copy all full multiples of the input block | |
235 | while ( copied+blocks[i].fSize <= mySize ) | |
236 | { | |
237 | Logging( kHLTLogInfo, "0 : HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", | |
238 | blocks[i].fSize, copied, totalSize ); | |
239 | memcpy( outputPtr+totalSize+copied, blocks[i].fPtr, blocks[i].fSize ); | |
240 | copied += blocks[i].fSize; | |
241 | } | |
242 | // And the copy the remaining fragment of the block | |
243 | Logging( kHLTLogInfo, "1 : HLT::Dummy::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", | |
244 | mySize-copied, copied, totalSize ); | |
245 | memcpy( outputPtr+totalSize+copied, blocks[i].fPtr, mySize-copied ); | |
246 | Logging( kHLTLogInfo, "HLT::Dummy::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", | |
247 | copied, totalSize ); | |
248 | ||
249 | ||
250 | ||
251 | AliHLTComponentBlockData bd; | |
252 | FillBlockData( bd ); | |
253 | bd.fOffset = totalSize;; | |
254 | bd.fSize = mySize; | |
255 | //bd.fPtr = (AliHLTUInt8_t*)(&recHit[0]); | |
256 | bd.fSpecification = blocks[i].fSpecification; | |
257 | outputBlocks.push_back( bd ); | |
258 | ||
259 | totalSize += mySize; | |
260 | ||
261 | // for(int j=0; j<nofHit; j++){ | |
262 | // printf("%d\t\t%d\t\t%f\t%f\t%f\n", | |
263 | // i,outPtr->fRecPoint[j].fDetElemId,outPtr->fRecPoint[j].fX, | |
264 | // outPtr->fRecPoint[j].fY,outPtr->fRecPoint[j].fZ); | |
265 | // printf("1 : %d\t\t%d\t\t%f\t%f\t%f\n", | |
266 | // i,(((AliHLTMUONRecPoint*)bd.fPtr) + j)->fDetElemId, | |
267 | // (((AliHLTMUONRecPoint*)bd.fPtr) + j)->fX, | |
268 | // (((AliHLTMUONRecPoint*)bd.fPtr) + j)->fY, | |
269 | // (((AliHLTMUONRecPoint*)bd.fPtr) + j)->fZ); | |
270 | // }// nof RecHits | |
271 | ||
272 | ||
273 | if(totalSize > size){ | |
274 | cout<<"size : "<<size<<"\t totalSize: "<<totalSize<<"\t mySize :"<<mySize<<endl; | |
275 | Logging( kHLTLogError, "AliHLTMUONHitReconstructorComponent::DoEvent", "Size exceeds the quota", "Size Exceeds the maximum quota" ); | |
276 | return EMSGSIZE; | |
277 | } | |
278 | ||
279 | }// block loop | |
280 | ||
281 | size = totalSize; | |
282 | ||
283 | return 0; | |
284 | } | |
285 | ||
286 | ||
287 | bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable( | |
288 | DHLTLut* lookupTable, const char* lutpath, int iDDL | |
289 | ) | |
290 | { | |
291 | if (iDDL < AliHLTMUONHitRec::fgkDDLOffSet || | |
292 | iDDL >= AliHLTMUONHitRec::fgkDDLOffSet + AliHLTMUONHitRec::fgkNofDDL) | |
293 | { | |
294 | // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "Invalid DDL") | |
295 | // << "DDL number is out of range (must be " << AliHLTLog::kDec << HLTMUONHitRec::fgkDDLOffSet | |
296 | // << " <= iDDL < " << AliHLTLog::kDec | |
297 | // << HLTMUONHitRec::fgkDDLOffSet + HLTMUONHitRec::fgkNofDDL | |
298 | // << ENDLOG; | |
299 | return false; | |
300 | } | |
301 | ||
302 | int lutLine = fHitRec->GetLutLine(iDDL); | |
303 | // cout<<"LutLine :"<<lutLine<<endl; | |
304 | FILE* fin = fopen(lutpath, "r"); | |
305 | if (fin == NULL) | |
306 | { | |
307 | // LOG(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "I/O error") | |
308 | // << "Failed to open file: " << lutpath << ENDLOG; | |
309 | return false; | |
310 | } | |
311 | ||
312 | # ifdef DEBUG | |
313 | // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadLookUpTable", "Trace") | |
314 | // << "Reading LUT file: " << lutpath << ENDLOG; | |
315 | # endif | |
316 | ||
317 | for(int i=0;i<lutLine;i++) | |
318 | { | |
319 | fscanf( | |
320 | fin, | |
321 | "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n", | |
322 | &lookupTable[i].fIdManuChannel, | |
323 | &lookupTable[i].fIX, | |
324 | &lookupTable[i].fIY, | |
325 | &lookupTable[i].fRealX, | |
326 | &lookupTable[i].fRealY, | |
327 | &lookupTable[i].fRealZ, | |
328 | &lookupTable[i].fPcbZone, | |
329 | &lookupTable[i].fPlane | |
330 | ); | |
331 | } | |
332 | ||
333 | fclose(fin); | |
334 | return true; | |
335 | } | |
336 | ||
337 | // implement this as well. | |
338 | ||
339 | bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile( | |
340 | BusToDetElem& busToDetElem, const char* buspatchmappath | |
341 | ) | |
342 | { | |
343 | char getLine[80]; | |
344 | char temp; | |
345 | int detElem, minBusPatch, maxBusPatch; | |
346 | ||
347 | FILE* fin = fopen(buspatchmappath, "r"); | |
348 | if (fin == NULL) | |
349 | { | |
350 | // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "I/O error") | |
351 | // << "Failed to open file: " << buspatchmappath << ENDLOG; | |
352 | return false; | |
353 | } | |
354 | ||
355 | # ifdef DEBUG | |
356 | // Logging(kHLTLogError, "AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile", "Trace") | |
357 | // << "Reading bus patch mapping file: " << buspatchmappath << ENDLOG; | |
358 | # endif | |
359 | ||
360 | while (feof(fin)==0) | |
361 | { | |
362 | fgets(getLine,80,fin); | |
363 | sscanf(getLine, "%d\t%d %c %d", &detElem, &minBusPatch, &temp, &maxBusPatch); | |
364 | if (detElem >= 700 && detElem <= 1025) | |
365 | { | |
366 | for(int i = minBusPatch; i <= maxBusPatch; i++) | |
367 | busToDetElem[i] = detElem; | |
368 | } // detElem condn | |
369 | } // while loop for file | |
370 | ||
371 | fclose(fin); | |
372 | return true; | |
373 | } |