b0201cbe |
1 | /************************************************************************** |
960d54ad |
2 | * This file is property of and copyright by the ALICE HLT Project * |
3 | * All rights reserved. * |
b0201cbe |
4 | * * |
960d54ad |
5 | * Primary Authors: * |
6 | * Indranil Das <indra.das@saha.ac.in> * |
b0201cbe |
7 | * * |
8 | * Permission to use, copy, modify and distribute this software and its * |
9 | * documentation strictly for non-commercial purposes is hereby granted * |
10 | * without fee, provided that the above copyright notice appears in all * |
11 | * copies and that both the copyright notice and this permission notice * |
12 | * appear in the supporting documentation. The authors make no claims * |
960d54ad |
13 | * about the suitability of this software for any purpose. It is * |
b0201cbe |
14 | * provided "as is" without express or implied warranty. * |
15 | **************************************************************************/ |
16 | |
17 | /* $Id$ */ |
18 | |
6253e09b |
19 | /// |
20 | /// |
21 | /// The HitRec Component is designed to deal the rawdata inputfiles to findout the |
22 | /// the reconstructed hits. The output is send to the output block for further |
23 | /// processing. |
24 | /// |
25 | /// Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com ) |
26 | /// |
b0201cbe |
27 | |
960d54ad |
28 | #include "AliHLTMUONRecHitsBlockStruct.h" |
b0201cbe |
29 | #include "AliHLTMUONHitReconstructorComponent.h" |
b12fe461 |
30 | #include "AliHLTMUONHitReconstructor.h" |
960d54ad |
31 | #include "AliHLTMUONConstants.h" |
668eee9f |
32 | #include "AliHLTMUONUtils.h" |
5ff5f960 |
33 | #include "AliHLTMUONDataBlockWriter.h" |
a6b16447 |
34 | #include "AliHLTMUONHitReconstructor.h" |
b0201cbe |
35 | #include "AliHLTLogging.h" |
36 | #include "AliHLTSystem.h" |
37 | #include "AliHLTDefinitions.h" |
29486e5a |
38 | #include <cstdlib> |
39 | #include <cerrno> |
40 | #include <cassert> |
b0201cbe |
41 | |
ee3678d3 |
42 | //STEER |
43 | #include "AliCDBManager.h" |
44 | #include "AliGeomManager.h" |
45 | |
46 | //MUON |
47 | #include "AliMUONGeometryTransformer.h" |
48 | #include "AliMUONCalibrationData.h" |
49 | #include "AliMUONVCalibParam.h" |
50 | |
a6b16447 |
51 | //MUON/mapping |
ee3678d3 |
52 | #include "AliMpCDB.h" |
53 | #include "AliMpPad.h" |
54 | #include "AliMpSegmentation.h" |
55 | #include "AliMpDDLStore.h" |
56 | #include "AliMpDEIterator.h" |
57 | #include "AliMpVSegmentation.h" |
58 | #include "AliMpDEManager.h" |
59 | #include "AliMpDetElement.h" |
60 | |
b0201cbe |
61 | ClassImp(AliHLTMUONHitReconstructorComponent) |
62 | |
63 | |
29486e5a |
64 | AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() : |
6253e09b |
65 | AliHLTProcessor(), |
29486e5a |
66 | fHitRec(NULL), |
a6b16447 |
67 | fDDL(-1), |
ee3678d3 |
68 | fIdToEntry(), |
29486e5a |
69 | fWarnForUnexpecedBlock(false) |
b0201cbe |
70 | { |
6253e09b |
71 | /// |
72 | /// Default constructor. |
73 | /// |
b0201cbe |
74 | } |
75 | |
960d54ad |
76 | |
b0201cbe |
77 | AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() |
78 | { |
6253e09b |
79 | /// |
80 | /// Default destructor. |
81 | /// |
ee3678d3 |
82 | |
83 | if (fHitRec != NULL) |
84 | { |
85 | delete fHitRec; |
86 | } |
960d54ad |
87 | } |
b0201cbe |
88 | |
960d54ad |
89 | const char* AliHLTMUONHitReconstructorComponent::GetComponentID() |
90 | { |
6253e09b |
91 | /// |
92 | /// Inherited from AliHLTComponent. Returns the component ID. |
93 | /// |
94 | |
29486e5a |
95 | return AliHLTMUONConstants::HitReconstructorId(); |
b0201cbe |
96 | } |
97 | |
b0201cbe |
98 | |
960d54ad |
99 | void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list) |
100 | { |
6253e09b |
101 | /// |
102 | /// Inherited from AliHLTProcessor. Returns the list of expected input data types. |
103 | /// |
104 | |
29486e5a |
105 | list.clear(); |
668eee9f |
106 | list.push_back( AliHLTMUONConstants::DDLRawDataType() ); |
960d54ad |
107 | } |
b0201cbe |
108 | |
b0201cbe |
109 | |
960d54ad |
110 | AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType() |
111 | { |
6253e09b |
112 | /// |
113 | /// Inherited from AliHLTComponent. Returns the output data type. |
114 | /// |
115 | |
29486e5a |
116 | return AliHLTMUONConstants::RecHitsBlockDataType(); |
960d54ad |
117 | } |
b0201cbe |
118 | |
b0201cbe |
119 | |
960d54ad |
120 | void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) |
121 | { |
6253e09b |
122 | /// |
123 | /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size. |
124 | /// |
125 | |
13f09bc1 |
126 | constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType); |
29486e5a |
127 | inputMultiplier = 1; |
960d54ad |
128 | } |
b0201cbe |
129 | |
b0201cbe |
130 | |
960d54ad |
131 | AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn() |
132 | { |
6253e09b |
133 | /// |
134 | /// Inherited from AliHLTComponent. Creates a new object instance. |
135 | /// |
136 | |
29486e5a |
137 | return new AliHLTMUONHitReconstructorComponent; |
960d54ad |
138 | } |
b0201cbe |
139 | |
b0201cbe |
140 | |
29486e5a |
141 | int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv) |
960d54ad |
142 | { |
6253e09b |
143 | /// |
144 | /// Inherited from AliHLTComponent. |
145 | /// Parses the command line parameters and initialises the component. |
146 | /// |
b0201cbe |
147 | |
ee3678d3 |
148 | HLTInfo("Initialising dHLT hit reconstruction component."); |
960d54ad |
149 | |
a6b16447 |
150 | // Must make sure that fHitRec is deleted if it is still allocated for |
151 | // whatever reason. |
152 | FreeMemory(); |
153 | |
ee3678d3 |
154 | try |
155 | { |
156 | fHitRec = new AliHLTMUONHitReconstructor(); |
960d54ad |
157 | } |
ee3678d3 |
158 | catch (const std::bad_alloc&) |
b8d467da |
159 | { |
ee3678d3 |
160 | HLTError("Could not allocate more memory for the hit reconstructor component."); |
161 | return -ENOMEM; |
b8d467da |
162 | } |
960d54ad |
163 | |
a6b16447 |
164 | // Initialise fields with default values then parse the command line. |
165 | fDDL = -1; |
166 | fIdToEntry.clear(); |
ee3678d3 |
167 | fWarnForUnexpecedBlock = false; |
a6b16447 |
168 | |
ee3678d3 |
169 | const char* lutFileName = NULL; |
170 | const char* cdbPath = NULL; |
171 | Int_t run = -1; |
172 | bool useCDB = false; |
173 | |
174 | for (int i = 0; i < argc; i++) |
175 | { |
176 | HLTDebug("argv[%d] == %s", i, argv[i]); |
177 | |
178 | if (strcmp( argv[i], "-ddl" ) == 0) |
179 | { |
180 | if (argc <= i+1) |
181 | { |
182 | HLTError("The DDL number was not specified. Must be in the range [13..20]."); |
a6b16447 |
183 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
184 | return -EINVAL; |
ee3678d3 |
185 | } |
186 | |
187 | char* cpErr = NULL; |
188 | unsigned long num = strtoul( argv[i+1], &cpErr, 0 ); |
189 | if (cpErr == NULL or *cpErr != '\0') |
190 | { |
191 | HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] ); |
a6b16447 |
192 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
193 | return -EINVAL; |
ee3678d3 |
194 | } |
195 | if (num < 13 or 20 < num) |
196 | { |
197 | HLTError("The DDL number must be in the range [13..20]."); |
a6b16447 |
198 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
199 | return -EINVAL; |
ee3678d3 |
200 | } |
201 | fDDL = num - 1; |
202 | |
203 | i++; |
204 | continue; |
205 | } // -ddl argument |
206 | |
207 | if (strcmp( argv[i], "-lut" ) == 0) |
208 | { |
209 | if (argc <= i+1) |
210 | { |
211 | HLTError("The lookup table filename was not specified."); |
a6b16447 |
212 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
213 | return -EINVAL; |
ee3678d3 |
214 | } |
215 | lutFileName = argv[i+1]; |
216 | i++; |
217 | continue; |
218 | } // -lut argument |
219 | |
220 | if (strcmp( argv[i], "-cdb" ) == 0) |
221 | { |
222 | useCDB = true; |
223 | continue; |
224 | } // -cdb argument |
225 | |
226 | if (strcmp( argv[i], "-cdbpath" ) == 0) |
227 | { |
228 | if ( argc <= i+1 ) |
229 | { |
230 | HLTError("The CDB path was not specified." ); |
a6b16447 |
231 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
232 | return -EINVAL; |
ee3678d3 |
233 | } |
234 | cdbPath = argv[i+1]; |
235 | useCDB = true; |
236 | i++; |
237 | continue; |
238 | } // -cdb argument |
239 | |
240 | if (strcmp( argv[i], "-run" ) == 0) |
241 | { |
242 | if ( argc <= i+1 ) |
243 | { |
244 | HLTError("The RUN number was not specified." ); |
a6b16447 |
245 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
246 | return -EINVAL; |
ee3678d3 |
247 | } |
248 | |
249 | char* cpErr = NULL; |
250 | run = Int_t( strtoul(argv[i+1], &cpErr, 0) ); |
251 | if (cpErr == NULL or *cpErr != '\0') |
252 | { |
253 | HLTError("Cannot convert '%s' to a valid run number." |
254 | " Expected an integer value.", argv[i+1] |
255 | ); |
a6b16447 |
256 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
257 | return -EINVAL; |
ee3678d3 |
258 | } |
259 | |
260 | i++; |
261 | continue; |
262 | } // -run argument |
263 | |
264 | if (strcmp( argv[i], "-warn_on_unexpected_block" ) == 0) |
265 | { |
266 | fWarnForUnexpecedBlock = true; |
267 | continue; |
268 | } |
269 | |
270 | HLTError("Unknown option '%s'", argv[i]); |
a6b16447 |
271 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
272 | return -EINVAL; |
ee3678d3 |
273 | |
274 | } // for loop |
275 | |
a6b16447 |
276 | if (fDDL == -1) |
277 | { |
278 | HLTWarning("DDL number not specified. Cannot check if incomming data is valid."); |
279 | } |
280 | |
ee3678d3 |
281 | if (lutFileName == NULL) useCDB = true; |
282 | |
a6b16447 |
283 | AliHLTMUONHitRecoLutRow* lookupTable = NULL; |
ee3678d3 |
284 | |
285 | if (useCDB) |
286 | { |
a6b16447 |
287 | if (not ReadCDB(lookupTable,cdbPath,run)) |
ee3678d3 |
288 | { |
289 | HLTError("Failed to read cdb, cdb cannot be read, DoInit"); |
a6b16447 |
290 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
291 | if (lookupTable != NULL) |
292 | delete [] lookupTable; |
293 | return -ENOENT; |
ee3678d3 |
294 | } |
960d54ad |
295 | } |
ee3678d3 |
296 | else |
297 | { |
298 | AliHLTUInt32_t lutLine; |
a6b16447 |
299 | if (not GetLutLine(lutFileName, lutLine)) |
ee3678d3 |
300 | { |
301 | HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit"); |
a6b16447 |
302 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
303 | return -EIO; |
ee3678d3 |
304 | } |
305 | |
306 | try |
307 | { |
308 | lookupTable = new AliHLTMUONHitRecoLutRow[lutLine]; |
309 | } |
310 | catch(const std::bad_alloc&) |
311 | { |
312 | HLTError("Dynamic memory allocation failed for lookuptable, DoInit"); |
a6b16447 |
313 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
314 | return -ENOMEM; |
ee3678d3 |
315 | } |
316 | |
a6b16447 |
317 | if (not ReadLookUpTable(lookupTable, lutFileName)) |
ee3678d3 |
318 | { |
319 | HLTError("Failed to read lut, lut cannot be read, DoInit"); |
a6b16447 |
320 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
321 | if (lookupTable != NULL) |
322 | delete [] lookupTable; |
323 | return -ENOENT; |
ee3678d3 |
324 | } |
960d54ad |
325 | } |
960d54ad |
326 | |
a6b16447 |
327 | if (not fHitRec->SetIdManuChannelToEntry(fIdToEntry)) |
ee3678d3 |
328 | { |
329 | HLTError("Failed to set fIdToEntry mapping, DoInit"); |
a6b16447 |
330 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
331 | if (lookupTable != NULL) |
332 | delete [] lookupTable; |
333 | return -ENOENT; |
ee3678d3 |
334 | } |
335 | |
a6b16447 |
336 | if (not fHitRec->LoadLookUpTable(lookupTable, fDDL)) |
ee3678d3 |
337 | { |
338 | HLTError("Cannot Laod hitrec lookuptable , DoInit"); |
a6b16447 |
339 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. |
340 | if (lookupTable != NULL) |
341 | delete [] lookupTable; |
342 | return -ENOENT; |
ee3678d3 |
343 | } |
344 | |
345 | delete [] lookupTable; |
346 | |
347 | return 0; |
b0201cbe |
348 | } |
349 | |
960d54ad |
350 | |
351 | int AliHLTMUONHitReconstructorComponent::DoDeinit() |
352 | { |
6253e09b |
353 | /// |
354 | /// Inherited from AliHLTComponent. Performs a cleanup of the component. |
355 | /// |
356 | |
ee3678d3 |
357 | HLTInfo("Deinitialising dHLT hit reconstruction component."); |
a6b16447 |
358 | FreeMemory(); |
ee3678d3 |
359 | return 0; |
b0201cbe |
360 | } |
361 | |
b0201cbe |
362 | |
960d54ad |
363 | int AliHLTMUONHitReconstructorComponent::DoEvent( |
364 | const AliHLTComponentEventData& evtData, |
b8d467da |
365 | const AliHLTComponentBlockData* blocks, |
366 | AliHLTComponentTriggerData& /*trigData*/, |
367 | AliHLTUInt8_t* outputPtr, |
960d54ad |
368 | AliHLTUInt32_t& size, |
369 | std::vector<AliHLTComponentBlockData>& outputBlocks |
370 | ) |
371 | { |
6253e09b |
372 | /// |
373 | /// Inherited from AliHLTProcessor. Processes the new event data. |
374 | /// |
375 | |
29486e5a |
376 | // Process an event |
377 | unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. |
b0201cbe |
378 | |
29486e5a |
379 | HLTDebug("Processing event %llu with %u input data blocks.", |
380 | evtData.fEventID, evtData.fBlockCnt |
381 | ); |
382 | |
383 | // Loop over all input blocks in the event |
384 | for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) |
5ff5f960 |
385 | { |
29486e5a |
386 | #ifdef __DEBUG |
387 | char id[kAliHLTComponentDataTypefIDsize+1]; |
388 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) |
389 | id[i] = blocks[n].fDataType.fID[i]; |
390 | id[kAliHLTComponentDataTypefIDsize] = '\0'; |
391 | char origin[kAliHLTComponentDataTypefOriginSize+1]; |
392 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) |
393 | origin[i] = blocks[n].fDataType.fOrigin[i]; |
394 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; |
395 | #endif // __DEBUG |
396 | HLTDebug("Handling block: %u, with fDataType.fID = '%s'," |
397 | " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.", |
398 | n, static_cast<char*>(id), static_cast<char*>(origin), |
399 | blocks[n].fPtr, blocks[n].fSize |
5ff5f960 |
400 | ); |
29486e5a |
401 | |
668eee9f |
402 | if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType() |
403 | or not AliHLTMUONUtils::IsTrackerDDL(blocks[n].fSpecification) |
404 | ) |
29486e5a |
405 | { |
406 | // Log a message indicating that we got a data block that we |
407 | // do not know how to handle. |
408 | char id[kAliHLTComponentDataTypefIDsize+1]; |
409 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) |
410 | id[i] = blocks[n].fDataType.fID[i]; |
411 | id[kAliHLTComponentDataTypefIDsize] = '\0'; |
412 | char origin[kAliHLTComponentDataTypefOriginSize+1]; |
413 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) |
414 | origin[i] = blocks[n].fDataType.fOrigin[i]; |
415 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; |
416 | |
417 | if (fWarnForUnexpecedBlock) |
668eee9f |
418 | HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X", |
419 | static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification |
29486e5a |
420 | ); |
421 | else |
668eee9f |
422 | HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X", |
423 | static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification |
29486e5a |
424 | ); |
425 | |
426 | continue; |
427 | } |
428 | |
a6b16447 |
429 | if (fDDL != -1) |
ee3678d3 |
430 | { |
a6b16447 |
431 | bool ddl[22]; |
432 | AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl); |
433 | if (not ddl[fDDL]) |
434 | { |
435 | HLTWarning("Received raw data from an unexpected DDL."); |
436 | } |
ee3678d3 |
437 | } |
438 | |
29486e5a |
439 | // Create a new output data block and initialise the header. |
440 | AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); |
441 | if (not block.InitCommonHeader()) |
442 | { |
443 | HLTError("There is not enough space in the output buffer for the new data block.", |
444 | " We require at least %u bytes, but have %u bytes left.", |
445 | sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), |
446 | block.BufferSize() |
447 | ); |
448 | break; |
449 | } |
450 | |
451 | AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); |
452 | AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); |
453 | AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) |
454 | + fHitRec->GetkDDLHeaderSize(); |
455 | AliHLTUInt32_t nofHit = block.MaxNumberOfEntries(); |
456 | |
ee3678d3 |
457 | #ifdef DEBUG |
29486e5a |
458 | HLTDebug("=========== Dumping DDL payload buffer =========="); |
459 | for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++) |
460 | HLTDebug("buffer[%d] : %x",j,buffer[j]); |
461 | HLTDebug("================== End of dump ================="); |
ee3678d3 |
462 | #endif // DEBUG |
29486e5a |
463 | |
464 | if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit)) |
465 | { |
466 | HLTError("Error while processing of hit reconstruction algorithm."); |
467 | size = totalSize; // Must tell the framework how much buffer space was used. |
a6b16447 |
468 | return -EIO; |
29486e5a |
469 | } |
470 | |
471 | // nofHit should now contain the number of reconstructed hits actually found |
472 | // and filled into the output data block, so we can set this number. |
473 | assert( nofHit <= block.MaxNumberOfEntries() ); |
474 | block.SetNumberOfEntries(nofHit); |
475 | |
476 | HLTDebug("Number of reconstructed hits found is %d", nofHit); |
477 | |
478 | // Fill a block data structure for our output block. |
479 | AliHLTComponentBlockData bd; |
480 | FillBlockData(bd); |
481 | bd.fPtr = outputPtr; |
482 | // This block's start (offset) is after all other blocks written so far. |
483 | bd.fOffset = totalSize; |
484 | bd.fSize = block.BytesUsed(); |
485 | bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); |
486 | bd.fSpecification = blocks[n].fSpecification; |
487 | outputBlocks.push_back(bd); |
488 | |
489 | // Increase the total amount of data written so far to our output memory |
490 | totalSize += block.BytesUsed(); |
5ff5f960 |
491 | } |
29486e5a |
492 | // Finally we set the total size of output memory we consumed. |
493 | size = totalSize; |
494 | |
495 | return 0; |
b0201cbe |
496 | } |
497 | |
498 | |
a6b16447 |
499 | void AliHLTMUONHitReconstructorComponent::FreeMemory() |
500 | { |
501 | /// Deletes any allocated objects if they are allocated else nothing is |
502 | /// done for objects not yet allocated. |
503 | /// This is used as a helper method to make sure the corresponding pointers |
504 | /// are NULL and we are back to a well defined state. |
505 | |
506 | if (fHitRec != NULL) |
507 | { |
508 | delete fHitRec; |
509 | fHitRec = NULL; |
510 | } |
511 | |
512 | fIdToEntry.clear(); |
513 | } |
514 | |
515 | |
ee3678d3 |
516 | bool AliHLTMUONHitReconstructorComponent::GetLutLine( |
a6b16447 |
517 | const char* lutFileName, AliHLTUInt32_t& iLine |
ee3678d3 |
518 | ) |
519 | { |
520 | // Reads LUT from CDB. |
521 | // TODO: combine this with ReadLookUpTable(). |
522 | |
523 | ifstream fin(lutFileName); |
524 | |
525 | if(!fin){ |
526 | HLTError("Failed to open file '%s' ",lutFileName); |
527 | return false; |
528 | } |
529 | |
530 | string s; |
531 | iLine = 0; |
532 | while(getline(fin,s)){ |
533 | iLine++; |
534 | } |
535 | |
536 | fin.close(); |
537 | |
538 | return true; |
539 | } |
540 | |
541 | |
542 | bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable( |
543 | AliHLTMUONHitRecoLutRow* lookupTable, const char* lutFileName |
544 | ) |
b0201cbe |
545 | { |
6253e09b |
546 | /// |
547 | /// Read in the lookup table from a text file. |
548 | /// |
ee3678d3 |
549 | |
960d54ad |
550 | if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() || |
ee3678d3 |
551 | fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()) |
552 | { |
960d54ad |
553 | HLTError("DDL number is out of range"); |
554 | return false; |
555 | } |
556 | |
ee3678d3 |
557 | AliHLTUInt32_t lutLine; |
a6b16447 |
558 | if(!GetLutLine(lutFileName, lutLine)){ |
ee3678d3 |
559 | HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit"); |
560 | |
960d54ad |
561 | return false; |
562 | } |
563 | |
ee3678d3 |
564 | int idManuChannel; |
565 | fIdToEntry.clear(); |
960d54ad |
566 | |
ee3678d3 |
567 | FILE *fin = fopen(lutFileName,"r"); |
568 | if(fin == NULL){ |
569 | printf("Failed to open file %s\n",lutFileName); |
570 | return false; |
571 | }else{ |
572 | for(AliHLTUInt32_t i=0;i<lutLine;i++){ |
573 | fscanf(fin,"%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%d\t%f\t%f\t%f\t%f\t%d\t%d\n", |
574 | &idManuChannel,&lookupTable[i].fDetElemId,&lookupTable[i].fIX, |
575 | &lookupTable[i].fIY,&lookupTable[i].fRealX, |
576 | &lookupTable[i].fRealY,&lookupTable[i].fRealZ, |
577 | &lookupTable[i].fHalfPadSize,&lookupTable[i].fPlane, |
578 | &lookupTable[i].fPed,&lookupTable[i].fSigma,&lookupTable[i].fA0, |
579 | &lookupTable[i].fA1,&lookupTable[i].fThres,&lookupTable[i].fSat); |
580 | |
581 | fIdToEntry[idManuChannel] = i+1; |
582 | |
583 | |
584 | } |
585 | } |
586 | |
960d54ad |
587 | fclose(fin); |
ee3678d3 |
588 | |
960d54ad |
589 | return true; |
b0201cbe |
590 | } |
591 | |
b0201cbe |
592 | |
ee3678d3 |
593 | bool AliHLTMUONHitReconstructorComponent::ReadCDB( |
594 | AliHLTMUONHitRecoLutRow*& lookupTable, |
595 | const char* cdbPath, Int_t run |
596 | ) |
b0201cbe |
597 | { |
ee3678d3 |
598 | // Reads LUT from CDB. |
599 | // TODO: merge this with CreateHitRecoLookupTables.C, make this static and use in the macro for example. |
600 | |
601 | vector<AliHLTMUONHitRecoLutRow> lutList; |
602 | lutList.clear(); |
603 | AliHLTMUONHitRecoLutRow lut; |
604 | int iEntry = 0; |
605 | |
606 | Bool_t warn = kTRUE; |
607 | |
608 | AliCDBManager* cdbManager = AliCDBManager::Instance(); |
609 | if (cdbPath != NULL) cdbManager->SetDefaultStorage(cdbPath); |
610 | if (run != -1) cdbManager->SetRun(run); |
611 | |
612 | if (! AliMpCDB::LoadDDLStore(warn)){ |
613 | HLTError("Failed to Load DDLStore specified for CDBPath '%s', and Run : '%d'",cdbPath,run); |
614 | return false; |
615 | } |
616 | |
617 | AliMpSegmentation *mpSegFactory = AliMpSegmentation::Instance(); |
618 | AliGeomManager::LoadGeometry(); |
619 | AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer(); |
620 | if(! chamberGeometryTransformer->LoadGeometryData()){ |
621 | HLTError("Failed to Load Geomerty Data "); |
622 | return false; |
623 | } |
960d54ad |
624 | |
ee3678d3 |
625 | AliMUONCalibrationData calibData(run); |
626 | |
627 | int totMaxIX = -1; |
628 | int totMaxIY = -1; |
629 | Int_t chamberId; |
630 | |
631 | for(Int_t iCh = 6; iCh < 10; iCh++){ // max 4 |
632 | |
633 | chamberId = iCh ; |
634 | |
635 | AliMpDEIterator it; |
636 | for ( it.First(chamberId); ! it.IsDone(); it.Next() ) { |
637 | |
638 | Int_t detElemId = it.CurrentDEId(); |
639 | int iDDL = AliMpDDLStore::Instance()->GetDetElement(detElemId)->GetDdlId() + 1; |
640 | if(iDDL == fDDL){ |
641 | |
642 | for(Int_t iCath = 0 ; iCath <= 1 ; iCath++){ |
643 | |
644 | AliMp::CathodType cath; |
645 | |
646 | if(iCath == 0) |
647 | cath = AliMp::kCath0 ; |
648 | else |
649 | cath = AliMp::kCath1 ; |
650 | |
651 | const AliMpVSegmentation* seg = mpSegFactory->GetMpSegmentation(detElemId, cath); |
652 | AliMp::PlaneType plane = seg->PlaneType(); |
653 | Int_t maxIX = seg->MaxPadIndexX(); |
654 | Int_t maxIY = seg->MaxPadIndexY(); |
655 | if(maxIX > totMaxIX) |
656 | totMaxIX = maxIX; |
657 | if(maxIY > totMaxIY) |
658 | totMaxIY = maxIY; |
659 | |
660 | Int_t idManuChannel, manuId, channelId, buspatchId; |
661 | float padSizeX, padSizeY; |
662 | float halfPadSize ; |
663 | Double_t realX, realY, realZ; |
664 | Double_t localX, localY, localZ; |
665 | Float_t calibA0Coeff,calibA1Coeff,pedestal,sigma; |
666 | Int_t thresold,saturation; |
667 | |
668 | // cout<<"Running for detElemId :"<<detElemId<<", and plane : "<<plane<<endl; |
669 | //Pad Info of a segment to print in lookuptable |
670 | for(Int_t iX = 0; iX<= maxIX ; iX++){ |
671 | for(Int_t iY = 0; iY<= maxIY ; iY++){ |
672 | if(seg->HasPad(AliMpIntPair(iX,iY))){ |
673 | AliMpPad pad = seg->PadByIndices(AliMpIntPair(iX,iY),kFALSE); |
674 | |
675 | // Getting Manu id |
676 | manuId = pad.GetLocation().GetFirst(); |
677 | manuId &= 0x7FF; // 11 bits |
678 | |
679 | buspatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId); |
680 | |
681 | // Getting channel id |
682 | channelId = pad.GetLocation().GetSecond(); |
683 | channelId &= 0x3F; // 6 bits |
684 | |
685 | idManuChannel &= 0x0; |
686 | idManuChannel = (idManuChannel|buspatchId)<<11; |
687 | idManuChannel = (idManuChannel|manuId)<<6 ; |
688 | idManuChannel |= channelId ; |
689 | |
690 | localX = pad.Position().X(); |
691 | localY = pad.Position().Y(); |
692 | localZ = 0.0; |
693 | |
694 | chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ, |
695 | realX,realY,realZ); |
696 | |
697 | padSizeX = pad.Dimensions().X(); |
698 | padSizeY = pad.Dimensions().Y(); |
699 | |
700 | calibA0Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,0) ; |
701 | calibA1Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,1) ; |
702 | thresold = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,2) ; |
703 | saturation = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,4) ; |
704 | |
705 | pedestal = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,0); |
706 | sigma = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,1); |
707 | |
708 | if(plane==0) |
709 | halfPadSize = padSizeX; |
710 | else |
711 | halfPadSize = padSizeY; |
712 | |
713 | fIdToEntry[idManuChannel] = iEntry+1; |
714 | |
715 | lut.fDetElemId = detElemId; |
716 | lut.fIX = iX; |
717 | lut.fIY = iY; |
718 | lut.fRealX = realX; |
719 | lut.fRealY = realY; |
720 | lut.fRealZ = realZ; |
721 | lut.fHalfPadSize = halfPadSize; |
722 | lut.fPlane = plane; |
723 | lut.fPed = pedestal; |
724 | lut.fSigma = sigma; |
725 | lut.fA0 = calibA0Coeff; |
726 | lut.fA1 = calibA1Coeff; |
727 | lut.fThres = thresold; |
728 | lut.fSat = saturation; |
729 | |
730 | lutList.push_back(lut); |
731 | iEntry++; |
732 | }// HasPad Condn |
733 | }// iY loop |
734 | }// iX loop |
735 | |
736 | }// iPlane |
737 | }// iDDL |
738 | } // detElemId loop |
739 | |
740 | }// ichamber loop |
741 | |
742 | AliHLTMUONHitRecoLutRow *temp; |
743 | |
744 | try{ |
745 | temp = new AliHLTMUONHitRecoLutRow[iEntry]; |
746 | } |
747 | catch(const std::bad_alloc&){ |
748 | HLTError("Dynamic memory allocation failed for temp"); |
749 | |
960d54ad |
750 | return false; |
751 | } |
752 | |
ee3678d3 |
753 | for(int iterm = 0; iterm < iEntry ;iterm++) |
754 | temp[iterm] = lutList.at(iterm); |
960d54ad |
755 | |
ee3678d3 |
756 | lookupTable = temp; |
757 | |
960d54ad |
758 | return true; |
b0201cbe |
759 | } |