]>
Commit | Line | Data |
---|---|---|
b0201cbe | 1 | /************************************************************************** |
ffc1a6f6 | 2 | * This file is property of and copyright by the ALICE HLT Project * |
960d54ad | 3 | * All rights reserved. * |
b0201cbe | 4 | * * |
960d54ad | 5 | * Primary Authors: * |
6 | * Indranil Das <indra.das@saha.ac.in> * | |
ffc1a6f6 | 7 | * Artur Szostak <artursz@iafrica.com> * |
b0201cbe | 8 | * * |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
ffc1a6f6 | 14 | * about the suitability of this software for any purpose. It is * |
b0201cbe | 15 | * provided "as is" without express or implied warranty. * |
16 | **************************************************************************/ | |
17 | ||
1d8ae082 | 18 | // $Id$ |
b0201cbe | 19 | |
6253e09b | 20 | /// |
ffc1a6f6 | 21 | /// @file AliHLTMUONHitReconstructorComponent.cxx |
22 | /// @author Indranil Das <indra.das@saha.ac.in> | <indra.ehep@gmail.com>, Artur Szostak <artursz@iafrica.com> | |
23 | /// @date 28 May 2007 | |
24 | /// @brief Implementation of the hit Reconstruction processing component. | |
6253e09b | 25 | /// |
26 | /// The HitRec Component is designed to deal the rawdata inputfiles to findout the | |
27 | /// the reconstructed hits. The output is send to the output block for further | |
28 | /// processing. | |
29 | /// | |
30 | /// Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com ) | |
31 | /// | |
b0201cbe | 32 | |
960d54ad | 33 | #include "AliHLTMUONRecHitsBlockStruct.h" |
b0201cbe | 34 | #include "AliHLTMUONHitReconstructorComponent.h" |
b12fe461 | 35 | #include "AliHLTMUONHitReconstructor.h" |
960d54ad | 36 | #include "AliHLTMUONConstants.h" |
668eee9f | 37 | #include "AliHLTMUONUtils.h" |
5ff5f960 | 38 | #include "AliHLTMUONDataBlockWriter.h" |
a6b16447 | 39 | #include "AliHLTMUONHitReconstructor.h" |
b0201cbe | 40 | #include "AliHLTLogging.h" |
41 | #include "AliHLTSystem.h" | |
42 | #include "AliHLTDefinitions.h" | |
29486e5a | 43 | #include <cstdlib> |
44 | #include <cerrno> | |
45 | #include <cassert> | |
93a75941 | 46 | #include <fstream> |
b0201cbe | 47 | |
ffc1a6f6 | 48 | #include "TMap.h" |
49 | ||
50 | //STEER | |
ee3678d3 | 51 | #include "AliCDBManager.h" |
52 | #include "AliGeomManager.h" | |
53 | ||
54 | //MUON | |
55 | #include "AliMUONGeometryTransformer.h" | |
56 | #include "AliMUONCalibrationData.h" | |
57 | #include "AliMUONVCalibParam.h" | |
58 | ||
a6b16447 | 59 | //MUON/mapping |
ee3678d3 | 60 | #include "AliMpCDB.h" |
61 | #include "AliMpPad.h" | |
62 | #include "AliMpSegmentation.h" | |
63 | #include "AliMpDDLStore.h" | |
64 | #include "AliMpDEIterator.h" | |
65 | #include "AliMpVSegmentation.h" | |
66 | #include "AliMpDEManager.h" | |
67 | #include "AliMpDetElement.h" | |
68 | ||
b0201cbe | 69 | ClassImp(AliHLTMUONHitReconstructorComponent) |
70 | ||
71 | ||
29486e5a | 72 | AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() : |
154cba94 | 73 | AliHLTMUONProcessor(), |
29486e5a | 74 | fHitRec(NULL), |
a6b16447 | 75 | fDDL(-1), |
93a75941 | 76 | fLutSize(0), |
77 | fLut(NULL), | |
ee3678d3 | 78 | fIdToEntry(), |
83d66053 | 79 | fMaxEntryPerBusPatch(), |
90af8855 | 80 | fWarnForUnexpecedBlock(false), |
56f0ccdf | 81 | fUseIdealGain(false), |
82 | fWarnIfPadSkipped(false) | |
b0201cbe | 83 | { |
6253e09b | 84 | /// |
85 | /// Default constructor. | |
86 | /// | |
b0201cbe | 87 | } |
88 | ||
960d54ad | 89 | |
b0201cbe | 90 | AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent() |
91 | { | |
6253e09b | 92 | /// |
93 | /// Default destructor. | |
94 | /// | |
ee3678d3 | 95 | |
96 | if (fHitRec != NULL) | |
97 | { | |
98 | delete fHitRec; | |
99 | } | |
93a75941 | 100 | if (fLut != NULL) |
101 | { | |
878cb83d | 102 | delete [] fLut; |
93a75941 | 103 | } |
960d54ad | 104 | } |
b0201cbe | 105 | |
960d54ad | 106 | const char* AliHLTMUONHitReconstructorComponent::GetComponentID() |
107 | { | |
6253e09b | 108 | /// |
109 | /// Inherited from AliHLTComponent. Returns the component ID. | |
110 | /// | |
111 | ||
29486e5a | 112 | return AliHLTMUONConstants::HitReconstructorId(); |
b0201cbe | 113 | } |
114 | ||
b0201cbe | 115 | |
ffb64d3e | 116 | void AliHLTMUONHitReconstructorComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) |
960d54ad | 117 | { |
6253e09b | 118 | /// |
119 | /// Inherited from AliHLTProcessor. Returns the list of expected input data types. | |
120 | /// | |
121 | ||
29486e5a | 122 | list.clear(); |
668eee9f | 123 | list.push_back( AliHLTMUONConstants::DDLRawDataType() ); |
960d54ad | 124 | } |
b0201cbe | 125 | |
b0201cbe | 126 | |
960d54ad | 127 | AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType() |
128 | { | |
6253e09b | 129 | /// |
130 | /// Inherited from AliHLTComponent. Returns the output data type. | |
131 | /// | |
132 | ||
4d76a068 | 133 | return kAliHLTMultipleDataType; |
134 | } | |
135 | ||
136 | ||
137 | int AliHLTMUONHitReconstructorComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list) | |
138 | { | |
139 | /// Inherited from AliHLTComponent. Returns the output data types. | |
140 | ||
141 | assert( list.empty() ); | |
142 | list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() ); | |
143 | list.push_back( AliHLTMUONConstants::ClusterBlockDataType() ); | |
144 | list.push_back( AliHLTMUONConstants::ChannelBlockDataType() ); | |
145 | return list.size(); | |
960d54ad | 146 | } |
b0201cbe | 147 | |
b0201cbe | 148 | |
ffb64d3e | 149 | void AliHLTMUONHitReconstructorComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier) |
960d54ad | 150 | { |
6253e09b | 151 | /// |
152 | /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size. | |
153 | /// | |
154 | ||
979076f8 | 155 | constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType) + 1024*1024; |
29486e5a | 156 | inputMultiplier = 1; |
960d54ad | 157 | } |
b0201cbe | 158 | |
b0201cbe | 159 | |
960d54ad | 160 | AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn() |
161 | { | |
6253e09b | 162 | /// |
163 | /// Inherited from AliHLTComponent. Creates a new object instance. | |
164 | /// | |
165 | ||
29486e5a | 166 | return new AliHLTMUONHitReconstructorComponent; |
960d54ad | 167 | } |
b0201cbe | 168 | |
b0201cbe | 169 | |
29486e5a | 170 | int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv) |
960d54ad | 171 | { |
6253e09b | 172 | /// |
173 | /// Inherited from AliHLTComponent. | |
174 | /// Parses the command line parameters and initialises the component. | |
175 | /// | |
b0201cbe | 176 | |
ee3678d3 | 177 | HLTInfo("Initialising dHLT hit reconstruction component."); |
ffb64d3e | 178 | |
179 | // Inherit the parents functionality. | |
180 | int result = AliHLTMUONProcessor::DoInit(argc, argv); | |
181 | if (result != 0) return result; | |
960d54ad | 182 | |
93a75941 | 183 | // Must make sure that fHitRec and fLut is deleted if it is still |
184 | // allocated for whatever reason. | |
a6b16447 | 185 | FreeMemory(); |
186 | ||
a6b16447 | 187 | // Initialise fields with default values then parse the command line. |
188 | fDDL = -1; | |
189 | fIdToEntry.clear(); | |
83d66053 | 190 | fMaxEntryPerBusPatch.clear(); |
ee3678d3 | 191 | fWarnForUnexpecedBlock = false; |
90af8855 | 192 | fUseIdealGain = false; |
56f0ccdf | 193 | fWarnIfPadSkipped = false; |
ee3678d3 | 194 | const char* lutFileName = NULL; |
ee3678d3 | 195 | bool useCDB = false; |
a9afae73 | 196 | typedef AliHLTMUONHitReconstructor HR; |
197 | HR::ERecoveryMode recoveryMode = HR::kDontTryRecover; | |
ffc1a6f6 | 198 | AliHLTInt32_t dccut = -1; |
a9afae73 | 199 | bool skipParityErrors = false; |
200 | bool dontPrintParityErrors = false; | |
83d66053 | 201 | bool makeClusters = false; |
202 | bool makeChannels = false; | |
ee3678d3 | 203 | |
204 | for (int i = 0; i < argc; i++) | |
205 | { | |
ffb64d3e | 206 | // To keep the legacy behaviour we need to have the following check |
207 | // for -cdbpath here, before ArgumentAlreadyHandled. | |
208 | if (strcmp(argv[i], "-cdbpath") == 0) | |
209 | { | |
210 | useCDB = true; | |
211 | } | |
212 | ||
213 | if (ArgumentAlreadyHandled(i, argv[i])) continue; | |
ee3678d3 | 214 | |
215 | if (strcmp( argv[i], "-ddl" ) == 0) | |
216 | { | |
ffc1a6f6 | 217 | if (fDDL != -1) |
218 | { | |
219 | HLTWarning("DDL number was already specified." | |
220 | " Will replace previous value given by -ddl or -ddlid." | |
221 | ); | |
222 | } | |
223 | ||
ee3678d3 | 224 | if (argc <= i+1) |
225 | { | |
f064ef44 | 226 | HLTError("The DDL number was not specified. Must be in the range [1..20]."); |
a6b16447 | 227 | return -EINVAL; |
ee3678d3 | 228 | } |
229 | ||
230 | char* cpErr = NULL; | |
231 | unsigned long num = strtoul( argv[i+1], &cpErr, 0 ); | |
232 | if (cpErr == NULL or *cpErr != '\0') | |
233 | { | |
93a75941 | 234 | HLTError("Cannot convert '%s' to DDL a number.", argv[i+1] ); |
a6b16447 | 235 | return -EINVAL; |
ee3678d3 | 236 | } |
f064ef44 | 237 | if (num < 1 or 20 < num) |
ee3678d3 | 238 | { |
f064ef44 | 239 | HLTError("The DDL number must be in the range [1..20]."); |
a6b16447 | 240 | return -EINVAL; |
ee3678d3 | 241 | } |
f064ef44 | 242 | fDDL = num - 1; // convert to range [0..19] |
ee3678d3 | 243 | |
244 | i++; | |
245 | continue; | |
246 | } // -ddl argument | |
247 | ||
a3d4b6ba | 248 | if (strcmp( argv[i], "-ddlid" ) == 0) |
249 | { | |
ffc1a6f6 | 250 | if (fDDL != -1) |
251 | { | |
252 | HLTWarning("DDL number was already specified." | |
253 | " Will replace previous value given by -ddl or -ddlid." | |
254 | ); | |
255 | } | |
256 | ||
a3d4b6ba | 257 | if ( argc <= i+1 ) |
258 | { | |
f064ef44 | 259 | HLTError("DDL equipment ID number not specified. It must be in the range [2560..2579]" ); |
a3d4b6ba | 260 | return -EINVAL; |
261 | } | |
262 | ||
263 | char* cpErr = NULL; | |
264 | unsigned long num = strtoul(argv[i+1], &cpErr, 0); | |
265 | if (cpErr == NULL or *cpErr != '\0') | |
266 | { | |
267 | HLTError("Cannot convert '%s' to a DDL equipment ID Number.", argv[i+1]); | |
a3d4b6ba | 268 | return -EINVAL; |
269 | } | |
270 | fDDL = AliHLTMUONUtils::EquipIdToDDLNumber(num); // Convert to DDL number in the range 0..21 | |
f064ef44 | 271 | if (fDDL < 0 or 19 < fDDL) |
a3d4b6ba | 272 | { |
f064ef44 | 273 | HLTError("The DDL equipment ID number must be in the range [2560..2579]."); |
a3d4b6ba | 274 | return -EINVAL; |
275 | } | |
276 | ||
277 | i++; | |
278 | continue; | |
279 | } | |
280 | ||
ee3678d3 | 281 | if (strcmp( argv[i], "-lut" ) == 0) |
282 | { | |
ffc1a6f6 | 283 | if (lutFileName != NULL) |
284 | { | |
285 | HLTWarning("LUT path was already specified." | |
286 | " Will replace previous value given by -lut." | |
287 | ); | |
288 | } | |
289 | ||
ee3678d3 | 290 | if (argc <= i+1) |
291 | { | |
292 | HLTError("The lookup table filename was not specified."); | |
a6b16447 | 293 | return -EINVAL; |
ee3678d3 | 294 | } |
295 | lutFileName = argv[i+1]; | |
296 | i++; | |
297 | continue; | |
298 | } // -lut argument | |
299 | ||
300 | if (strcmp( argv[i], "-cdb" ) == 0) | |
301 | { | |
302 | useCDB = true; | |
303 | continue; | |
304 | } // -cdb argument | |
305 | ||
ffc1a6f6 | 306 | if (strcmp( argv[i], "-dccut" ) == 0) |
307 | { | |
308 | if (dccut != -1) | |
309 | { | |
310 | HLTWarning("DC cut parameter was already specified." | |
311 | " Will replace previous value given by -dccut." | |
312 | ); | |
313 | } | |
314 | ||
315 | if ( argc <= i+1 ) | |
316 | { | |
317 | HLTError("No DC cut value was specified. It should be a positive integer value." ); | |
ffc1a6f6 | 318 | return -EINVAL; |
319 | } | |
320 | ||
321 | char* cpErr = NULL; | |
322 | dccut = AliHLTInt32_t( strtol(argv[i+1], &cpErr, 0) ); | |
323 | if (cpErr == NULL or *cpErr != '\0' or dccut < 0) | |
324 | { | |
325 | HLTError("Cannot convert '%s' to a valid DC cut value." | |
326 | " Expected a positive integer value.", argv[i+1] | |
327 | ); | |
ffc1a6f6 | 328 | return -EINVAL; |
329 | } | |
330 | ||
331 | i++; | |
332 | continue; | |
333 | } | |
334 | ||
ee3678d3 | 335 | if (strcmp( argv[i], "-warn_on_unexpected_block" ) == 0) |
336 | { | |
337 | fWarnForUnexpecedBlock = true; | |
338 | continue; | |
339 | } | |
a5d4696f | 340 | |
341 | if (strcmp( argv[i], "-tryrecover" ) == 0) | |
342 | { | |
a9afae73 | 343 | if (argc > i+1) |
344 | { | |
345 | // There might be an optional parameter so check | |
346 | // if it is a recognised one. If not then assume it | |
347 | // is the next argument, so no error message. | |
348 | if (strcmp(argv[i+1], "full") == 0) | |
349 | { | |
350 | recoveryMode = HR::kRecoverFull; | |
351 | i++; | |
352 | } | |
353 | else if (strcmp(argv[i+1], "skip") == 0) | |
354 | { | |
355 | recoveryMode = HR::kRecoverJustSkip; | |
356 | i++; | |
357 | } | |
358 | else if (strcmp(argv[i+1], "parityerrors") == 0) | |
359 | { | |
360 | recoveryMode = HR::kRecoverFromParityErrorsOnly; | |
361 | i++; | |
362 | } | |
363 | else | |
364 | { | |
365 | recoveryMode = HR::kRecoverFull; | |
366 | } | |
367 | } | |
368 | else | |
369 | { | |
370 | recoveryMode = HR::kRecoverFull; | |
371 | } | |
372 | continue; | |
373 | } | |
374 | ||
375 | if (strcmp( argv[i], "-skipparityerrors" ) == 0) | |
376 | { | |
377 | skipParityErrors = true; | |
378 | continue; | |
379 | } | |
380 | ||
381 | if (strcmp( argv[i], "-dontprintparityerrors" ) == 0) | |
382 | { | |
383 | dontPrintParityErrors = true; | |
a5d4696f | 384 | continue; |
385 | } | |
90af8855 | 386 | |
387 | if (strcmp( argv[i], "-useidealgain" ) == 0) | |
388 | { | |
389 | fUseIdealGain = true; | |
390 | continue; | |
391 | } | |
83d66053 | 392 | |
393 | if (strcmp( argv[i], "-makeclusters" ) == 0) | |
394 | { | |
395 | makeClusters = true; | |
396 | continue; | |
397 | } | |
398 | ||
399 | if (strcmp( argv[i], "-makechannels" ) == 0) | |
400 | { | |
401 | makeChannels = true; | |
402 | continue; | |
403 | } | |
56f0ccdf | 404 | |
405 | if (strcmp( argv[i], "-warnifpadskipped" ) == 0) | |
406 | { | |
407 | fWarnIfPadSkipped = true; | |
408 | continue; | |
409 | } | |
ee3678d3 | 410 | |
411 | HLTError("Unknown option '%s'", argv[i]); | |
a6b16447 | 412 | return -EINVAL; |
ee3678d3 | 413 | |
414 | } // for loop | |
415 | ||
ffb64d3e | 416 | try |
417 | { | |
418 | fHitRec = new AliHLTMUONHitReconstructor(); | |
419 | } | |
420 | catch (const std::bad_alloc&) | |
421 | { | |
422 | HLTError("Could not allocate more memory for the hit reconstructor component."); | |
423 | return -ENOMEM; | |
424 | } | |
425 | ||
2b7af22a | 426 | if (dccut != -1 and useCDB) |
427 | { | |
428 | HLTWarning("The -cdb or -cdbpath parameter was specified, which indicates that" | |
429 | " this component should read from the CDB, but then the -dccut argument" | |
430 | " was also used. Will override the value from CDB with the command" | |
431 | " line DC cut parameter given." | |
432 | ); | |
433 | } | |
434 | ||
435 | if (lutFileName != NULL and useCDB == true) | |
436 | { | |
437 | HLTWarning("The -cdb or -cdbpath parameter was specified, which indicates that" | |
438 | " this component should read from the CDB, but then the -lut argument" | |
439 | " was also used. Will ignore the -lut option and load from CDB anyway." | |
440 | ); | |
441 | } | |
442 | ||
93a75941 | 443 | if (lutFileName == NULL) useCDB = true; |
444 | ||
ffb64d3e | 445 | if (fDDL == -1 and not DelaySetup()) |
a6b16447 | 446 | { |
447 | HLTWarning("DDL number not specified. Cannot check if incomming data is valid."); | |
448 | } | |
449 | ||
ee3678d3 | 450 | if (useCDB) |
451 | { | |
ffb64d3e | 452 | if (not DelaySetup()) |
ffc1a6f6 | 453 | { |
454 | HLTInfo("Loading lookup table information from CDB for DDL %d (ID = %d).", | |
455 | fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL) | |
456 | ); | |
4e22efc4 | 457 | result = ReadLutFromCDB(); |
ffc1a6f6 | 458 | if (result != 0) |
459 | { | |
460 | // Error messages already generated in ReadLutFromCDB. | |
461 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. | |
462 | return result; | |
463 | } | |
83d66053 | 464 | fHitRec->SetLookUpTable(fLut, &fIdToEntry, &fMaxEntryPerBusPatch); |
ffc1a6f6 | 465 | } |
960d54ad | 466 | } |
ee3678d3 | 467 | else |
468 | { | |
93a75941 | 469 | HLTInfo("Loading lookup table information from file %s.", lutFileName); |
4e22efc4 | 470 | result = ReadLookUpTable(lutFileName); |
ffc1a6f6 | 471 | if (result != 0) |
472 | { | |
473 | // Error messages already generated in ReadLookUpTable. | |
474 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. | |
475 | return result; | |
476 | } | |
83d66053 | 477 | fHitRec->SetLookUpTable(fLut, &fIdToEntry, &fMaxEntryPerBusPatch); |
ee3678d3 | 478 | } |
ffc1a6f6 | 479 | |
480 | if (dccut == -1) | |
ee3678d3 | 481 | { |
ffb64d3e | 482 | if (not DelaySetup()) |
ffc1a6f6 | 483 | { |
484 | HLTInfo("Loading DC cut parameters from CDB for DDL %d (ID = %d).", | |
485 | fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL) | |
486 | ); | |
4e22efc4 | 487 | result = ReadDCCutFromCDB(); |
ffc1a6f6 | 488 | if (result != 0) |
489 | { | |
490 | // Error messages already generated in ReadDCCutFromCDB. | |
491 | FreeMemory(); // Make sure we cleanup to avoid partial initialisation. | |
492 | return result; | |
493 | } | |
2b7af22a | 494 | } |
495 | else | |
496 | { | |
497 | // Print the debug messages here since ReadDCCutFromCDB does not get called, | |
498 | // in-which the debug messages would have been printed. | |
ffc1a6f6 | 499 | HLTDebug("Using DC cut parameter of %d ADC channels.", fHitRec->GetDCCut()); |
500 | } | |
501 | } | |
502 | else | |
503 | { | |
ffc1a6f6 | 504 | fHitRec->SetDCCut(dccut); |
505 | HLTDebug("Using DC cut parameter of %d ADC channels.", fHitRec->GetDCCut()); | |
ee3678d3 | 506 | } |
507 | ||
a9afae73 | 508 | fHitRec->TryRecover(recoveryMode); |
509 | fHitRec->SkipParityErrors(skipParityErrors); | |
510 | fHitRec->DontPrintParityErrors(dontPrintParityErrors); | |
83d66053 | 511 | fHitRec->GenerateClusterInfo(makeClusters); |
512 | fHitRec->GenerateChannelInfo(makeChannels); | |
513 | fHitRec->DDLNumber(fDDL); | |
fd5b812e | 514 | //The DDL number has to be set before the following InitDetElemInDDLArray() method |
515 | fHitRec->InitDetElemInDDLArray(); | |
90af8855 | 516 | HLTDebug("dHLT hit reconstruction component is initialized."); |
ee3678d3 | 517 | return 0; |
b0201cbe | 518 | } |
519 | ||
960d54ad | 520 | |
521 | int AliHLTMUONHitReconstructorComponent::DoDeinit() | |
522 | { | |
6253e09b | 523 | /// |
524 | /// Inherited from AliHLTComponent. Performs a cleanup of the component. | |
525 | /// | |
fd5b812e | 526 | fHitRec->DeInitDetElemInDDLArray(); |
ee3678d3 | 527 | HLTInfo("Deinitialising dHLT hit reconstruction component."); |
a6b16447 | 528 | FreeMemory(); |
ee3678d3 | 529 | return 0; |
b0201cbe | 530 | } |
531 | ||
b0201cbe | 532 | |
ffc1a6f6 | 533 | int AliHLTMUONHitReconstructorComponent::Reconfigure( |
534 | const char* cdbEntry, const char* componentId | |
535 | ) | |
536 | { | |
537 | /// Inherited from AliHLTComponent. This method will reload CDB configuration | |
538 | /// entries for this component from the CDB. | |
539 | /// \param cdbEntry If this is NULL then it is assumed that all CDB entries should | |
540 | /// be reloaded. Otherwise a particular value for 'cdbEntry' will trigger | |
541 | /// reloading of the LUT if the path contains 'MUON/' and reloading of the DC | |
2b7af22a | 542 | /// cut parameter if 'cdbEntry' equals "HLT/ConfigMUON/HitReconstructor". |
543 | /// \param componentId The name of the component in the current chain. | |
544 | ||
ad9d297e | 545 | TString path = cdbEntry; |
546 | bool startsWithMUON = path.Index("MUON/", 5, 0, TString::kExact) == 0; | |
547 | bool givenConfigPath = (path == AliHLTMUONConstants::HitReconstructorCDBPath()); | |
ffc1a6f6 | 548 | |
2b7af22a | 549 | if (cdbEntry == NULL or startsWithMUON or givenConfigPath) |
ffc1a6f6 | 550 | { |
2b7af22a | 551 | HLTInfo("Reading new configuration entries from CDB for component '%s'.", componentId); |
552 | } | |
ffc1a6f6 | 553 | |
2b7af22a | 554 | if (cdbEntry == NULL or startsWithMUON) |
555 | { | |
556 | // First clear the current LUT data and then load in the new values. | |
557 | if (fLut != NULL) | |
ffc1a6f6 | 558 | { |
2b7af22a | 559 | delete [] fLut; |
560 | fLut = NULL; | |
561 | fLutSize = 0; | |
ffc1a6f6 | 562 | } |
563 | ||
2b7af22a | 564 | fIdToEntry.clear(); |
83d66053 | 565 | fMaxEntryPerBusPatch.clear(); |
2b7af22a | 566 | int result = ReadLutFromCDB(); |
567 | if (result != 0) return result; | |
83d66053 | 568 | fHitRec->SetLookUpTable(fLut, &fIdToEntry, &fMaxEntryPerBusPatch); |
2b7af22a | 569 | } |
570 | ||
571 | if (cdbEntry == NULL or not startsWithMUON) | |
572 | { | |
573 | int result = ReadDCCutFromCDB(); | |
574 | if (result != 0) return result; | |
ffc1a6f6 | 575 | } |
576 | ||
577 | return 0; | |
578 | } | |
579 | ||
580 | ||
581 | int AliHLTMUONHitReconstructorComponent::ReadPreprocessorValues(const char* modules) | |
582 | { | |
583 | /// Inherited from AliHLTComponent. | |
584 | /// Updates the configuration of this component if either HLT or MUON have | |
585 | /// been specified in the 'modules' list. | |
586 | ||
587 | TString mods = modules; | |
588 | if (mods.Contains("ALL") or (mods.Contains("HLT") and mods.Contains("MUON"))) | |
589 | { | |
590 | return Reconfigure(NULL, GetComponentID()); | |
591 | } | |
592 | if (mods.Contains("HLT")) | |
593 | { | |
594 | return Reconfigure(AliHLTMUONConstants::HitReconstructorCDBPath(), GetComponentID()); | |
595 | } | |
596 | if (mods.Contains("MUON")) | |
597 | { | |
598 | return Reconfigure("MUON/*", GetComponentID()); | |
599 | } | |
600 | return 0; | |
601 | } | |
602 | ||
603 | ||
960d54ad | 604 | int AliHLTMUONHitReconstructorComponent::DoEvent( |
605 | const AliHLTComponentEventData& evtData, | |
b8d467da | 606 | const AliHLTComponentBlockData* blocks, |
ffb64d3e | 607 | AliHLTComponentTriggerData& trigData, |
b8d467da | 608 | AliHLTUInt8_t* outputPtr, |
960d54ad | 609 | AliHLTUInt32_t& size, |
ffb64d3e | 610 | AliHLTComponentBlockDataList& outputBlocks |
960d54ad | 611 | ) |
612 | { | |
6253e09b | 613 | /// |
614 | /// Inherited from AliHLTProcessor. Processes the new event data. | |
615 | /// | |
ffb64d3e | 616 | |
ffc1a6f6 | 617 | // Initialise the LUT and DC cut parameter from CDB if we were requested |
618 | // to initialise only when the first event was received. | |
ffb64d3e | 619 | if (DelaySetup()) |
ffc1a6f6 | 620 | { |
621 | // Use the specification given by the first data block if we | |
622 | // have not been given a DDL number on the command line. | |
623 | if (fDDL == -1) | |
624 | { | |
48ccb241 | 625 | bool blockFound = false; |
626 | for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt and not blockFound; n++) | |
627 | { | |
628 | if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()) continue; | |
629 | blockFound = true; | |
630 | ||
631 | fDDL = AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification); | |
632 | ||
633 | if (fDDL == -1) | |
634 | { | |
635 | HLTError("Received a data block with a specification (0x%8.8X)" | |
636 | " indicating multiple DDL data sources, but we must only" | |
637 | " receive raw DDL data from one tracking station DDL.", | |
638 | blocks[n].fSpecification | |
639 | ); | |
640 | return -EPROTO; | |
641 | } | |
642 | } | |
643 | ||
644 | if (not blockFound) | |
ffc1a6f6 | 645 | { |
646 | HLTError("The initialisation from CDB of the component has" | |
647 | " been delayed to the first received event. However," | |
48ccb241 | 648 | " no raw DDL data blocks have been found in the first event." |
ffc1a6f6 | 649 | ); |
650 | return -ENOENT; | |
651 | } | |
ffc1a6f6 | 652 | } |
653 | ||
654 | // Check that the LUT was not already loaded in DoInit. | |
655 | if (fLut == NULL) | |
656 | { | |
657 | HLTInfo("Loading lookup table information from CDB for DDL %d (ID = %d).", | |
658 | fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL) | |
659 | ); | |
660 | int result = ReadLutFromCDB(); | |
661 | if (result != 0) return result; | |
662 | ||
83d66053 | 663 | fHitRec->SetLookUpTable(fLut, &fIdToEntry, &fMaxEntryPerBusPatch); |
ffc1a6f6 | 664 | } |
665 | ||
666 | // Check that the DC cut was not already loaded in DoInit. | |
667 | if (fHitRec->GetDCCut() == -1) | |
668 | { | |
669 | HLTInfo("Loading DC cut parameters from CDB for DDL %d (ID = %d).", | |
670 | fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL) | |
671 | ); | |
672 | int result = ReadDCCutFromCDB(); | |
673 | if (result != 0) return result; | |
ffc1a6f6 | 674 | } |
675 | ||
ffb64d3e | 676 | DoneDelayedSetup(); |
ffc1a6f6 | 677 | } |
678 | ||
679 | if (fLut == NULL) | |
680 | { | |
681 | HLTFatal("Lookup table not loaded! Cannot continue processing data."); | |
682 | return -ENOENT; | |
683 | } | |
684 | ||
29486e5a | 685 | // Process an event |
686 | unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. | |
b0201cbe | 687 | |
29486e5a | 688 | HLTDebug("Processing event %llu with %u input data blocks.", |
689 | evtData.fEventID, evtData.fBlockCnt | |
690 | ); | |
691 | ||
692 | // Loop over all input blocks in the event | |
450e0b36 | 693 | for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++) |
5ff5f960 | 694 | { |
450e0b36 | 695 | HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.", |
696 | n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize | |
5ff5f960 | 697 | ); |
29486e5a | 698 | |
668eee9f | 699 | if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType() |
700 | or not AliHLTMUONUtils::IsTrackerDDL(blocks[n].fSpecification) | |
701 | ) | |
29486e5a | 702 | { |
703 | // Log a message indicating that we got a data block that we | |
704 | // do not know how to handle. | |
29486e5a | 705 | if (fWarnForUnexpecedBlock) |
450e0b36 | 706 | HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X", |
707 | DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification | |
29486e5a | 708 | ); |
4e22efc4 | 709 | #ifdef __DEBUG |
29486e5a | 710 | else |
450e0b36 | 711 | HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X", |
712 | DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification | |
29486e5a | 713 | ); |
4e22efc4 | 714 | #endif |
29486e5a | 715 | |
716 | continue; | |
717 | } | |
718 | ||
a6b16447 | 719 | if (fDDL != -1) |
ee3678d3 | 720 | { |
a3d4b6ba | 721 | AliHLTInt32_t receivedDDL = AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification); |
722 | if (receivedDDL != fDDL) | |
a6b16447 | 723 | { |
a3d4b6ba | 724 | HLTWarning("Received raw data from DDL %d (ID = %d)," |
725 | " but expect data only from DDL %d (ID = %d).", | |
726 | receivedDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(receivedDDL), | |
727 | fDDL+1, AliHLTMUONUtils::DDLNumberToEquipId(fDDL) | |
728 | ); | |
a6b16447 | 729 | } |
ee3678d3 | 730 | } |
731 | ||
29486e5a | 732 | // Create a new output data block and initialise the header. |
733 | AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize); | |
734 | if (not block.InitCommonHeader()) | |
735 | { | |
8bade2be | 736 | HLTError("There is not enough space in the output buffer for the new data block." |
29486e5a | 737 | " We require at least %u bytes, but have %u bytes left.", |
738 | sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType), | |
739 | block.BufferSize() | |
740 | ); | |
741 | break; | |
742 | } | |
743 | ||
744 | AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); | |
745 | AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize(); | |
3240b3ce | 746 | AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) |
747 | + fHitRec->GetkDDLHeaderSize(); | |
29486e5a | 748 | AliHLTUInt32_t nofHit = block.MaxNumberOfEntries(); |
749 | ||
ee3678d3 | 750 | #ifdef DEBUG |
29486e5a | 751 | HLTDebug("=========== Dumping DDL payload buffer =========="); |
752 | for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++) | |
753 | HLTDebug("buffer[%d] : %x",j,buffer[j]); | |
754 | HLTDebug("================== End of dump ================="); | |
ee3678d3 | 755 | #endif // DEBUG |
29486e5a | 756 | |
757 | if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit)) | |
758 | { | |
154cba94 | 759 | HLTError("Error while processing the hit reconstruction algorithm."); |
ffb64d3e | 760 | if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks); |
29486e5a | 761 | size = totalSize; // Must tell the framework how much buffer space was used. |
a6b16447 | 762 | return -EIO; |
29486e5a | 763 | } |
764 | ||
765 | // nofHit should now contain the number of reconstructed hits actually found | |
766 | // and filled into the output data block, so we can set this number. | |
767 | assert( nofHit <= block.MaxNumberOfEntries() ); | |
768 | block.SetNumberOfEntries(nofHit); | |
769 | ||
770 | HLTDebug("Number of reconstructed hits found is %d", nofHit); | |
771 | ||
772 | // Fill a block data structure for our output block. | |
773 | AliHLTComponentBlockData bd; | |
774 | FillBlockData(bd); | |
775 | bd.fPtr = outputPtr; | |
776 | // This block's start (offset) is after all other blocks written so far. | |
777 | bd.fOffset = totalSize; | |
778 | bd.fSize = block.BytesUsed(); | |
779 | bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType(); | |
780 | bd.fSpecification = blocks[n].fSpecification; | |
781 | outputBlocks.push_back(bd); | |
782 | ||
783 | // Increase the total amount of data written so far to our output memory | |
784 | totalSize += block.BytesUsed(); | |
83d66053 | 785 | |
786 | if (fHitRec->GenerateClusterInfo()) | |
787 | { | |
788 | // Create a new output clusters data block and initialise the header. | |
789 | AliHLTMUONClustersBlockWriter clustblock(outputPtr+totalSize, size-totalSize); | |
790 | if (not clustblock.InitCommonHeader()) | |
791 | { | |
792 | HLTError("There is not enough space in the output buffer for the new clusters data block." | |
793 | " We require at least %u bytes, but have %u bytes left.", | |
794 | sizeof(AliHLTMUONClustersBlockWriter::HeaderType), | |
795 | clustblock.BufferSize() | |
796 | ); | |
797 | break; | |
798 | } | |
799 | ||
800 | AliHLTUInt32_t nofClusters = clustblock.MaxNumberOfEntries(); | |
801 | bool filledOk = fHitRec->FillClusterData(clustblock.GetArray(), nofClusters); | |
802 | // nofClusters should now contain the number of clusters filled. | |
803 | assert( nofClusters <= clustblock.MaxNumberOfEntries() ); | |
804 | clustblock.SetNumberOfEntries(nofClusters); | |
805 | ||
806 | // Fill a block data structure for our output block. | |
807 | AliHLTComponentBlockData bdc; | |
808 | FillBlockData(bdc); | |
809 | bdc.fPtr = outputPtr; | |
810 | // This block's start (offset) is after all other blocks written so far. | |
811 | bdc.fOffset = totalSize; | |
812 | bdc.fSize = clustblock.BytesUsed(); | |
813 | bdc.fDataType = AliHLTMUONConstants::ClusterBlockDataType(); | |
814 | bdc.fSpecification = blocks[n].fSpecification; | |
815 | outputBlocks.push_back(bdc); | |
816 | ||
817 | // Increase the total amount of data written so far to our output memory | |
818 | totalSize += clustblock.BytesUsed(); | |
819 | ||
820 | if (not filledOk) | |
821 | { | |
822 | HLTError("We have overflowed the output buffer space for the new clusters data block."); | |
823 | break; | |
824 | } | |
825 | } | |
826 | ||
827 | if (fHitRec->GenerateChannelInfo()) | |
828 | { | |
829 | // Create a new output channels data block and initialise the header. | |
830 | AliHLTMUONChannelsBlockWriter channelblock(outputPtr+totalSize, size-totalSize); | |
831 | if (not channelblock.InitCommonHeader()) | |
832 | { | |
833 | HLTError("There is not enough space in the output buffer for the new channels data block." | |
834 | " We require at least %u bytes, but have %u bytes left.", | |
835 | sizeof(AliHLTMUONChannelsBlockWriter::HeaderType), | |
836 | channelblock.BufferSize() | |
837 | ); | |
838 | break; | |
839 | } | |
840 | ||
841 | AliHLTUInt32_t nofChannels = channelblock.MaxNumberOfEntries(); | |
842 | bool filledOk = fHitRec->FillChannelData(channelblock.GetArray(), nofChannels); | |
843 | // nofChannels should now contain the number of channels filled. | |
844 | assert( nofChannels <= channelblock.MaxNumberOfEntries() ); | |
845 | channelblock.SetNumberOfEntries(nofChannels); | |
846 | ||
847 | // Fill a block data structure for our output block. | |
848 | AliHLTComponentBlockData bdc; | |
849 | FillBlockData(bdc); | |
850 | bdc.fPtr = outputPtr; | |
851 | // This block's start (offset) is after all other blocks written so far. | |
852 | bdc.fOffset = totalSize; | |
853 | bdc.fSize = channelblock.BytesUsed(); | |
854 | bdc.fDataType = AliHLTMUONConstants::ChannelBlockDataType(); | |
855 | bdc.fSpecification = blocks[n].fSpecification; | |
856 | outputBlocks.push_back(bdc); | |
857 | ||
858 | // Increase the total amount of data written so far to our output memory | |
859 | totalSize += channelblock.BytesUsed(); | |
860 | ||
861 | if (not filledOk) | |
862 | { | |
863 | HLTError("We have overflowed the output buffer space for the new channels data block."); | |
864 | break; | |
865 | } | |
866 | } | |
5ff5f960 | 867 | } |
29486e5a | 868 | // Finally we set the total size of output memory we consumed. |
869 | size = totalSize; | |
870 | ||
871 | return 0; | |
b0201cbe | 872 | } |
873 | ||
874 | ||
a6b16447 | 875 | void AliHLTMUONHitReconstructorComponent::FreeMemory() |
876 | { | |
877 | /// Deletes any allocated objects if they are allocated else nothing is | |
878 | /// done for objects not yet allocated. | |
879 | /// This is used as a helper method to make sure the corresponding pointers | |
93a75941 | 880 | /// are NULL and we get back to a well defined state. |
a6b16447 | 881 | |
882 | if (fHitRec != NULL) | |
883 | { | |
884 | delete fHitRec; | |
885 | fHitRec = NULL; | |
886 | } | |
93a75941 | 887 | if (fLut != NULL) |
888 | { | |
878cb83d | 889 | delete [] fLut; |
93a75941 | 890 | fLut = NULL; |
891 | fLutSize = 0; | |
892 | } | |
a6b16447 | 893 | |
894 | fIdToEntry.clear(); | |
83d66053 | 895 | fMaxEntryPerBusPatch.clear(); |
a6b16447 | 896 | } |
897 | ||
898 | ||
93a75941 | 899 | int AliHLTMUONHitReconstructorComponent::ReadLookUpTable(const char* lutFileName) |
ee3678d3 | 900 | { |
93a75941 | 901 | /// Read in the lookup table from a text file. |
902 | /// Note that this method could leave fLut allocated which is cleaned up | |
903 | /// by DoInit with a call to FreeMemory(). | |
904 | ||
905 | assert( fLut == NULL ); | |
906 | assert( fLutSize == 0 ); | |
907 | assert( fIdToEntry.empty() ); | |
83d66053 | 908 | assert( fMaxEntryPerBusPatch.empty() ); |
93a75941 | 909 | |
910 | std::ifstream file(lutFileName); | |
911 | if (not file.good()) | |
912 | { | |
913 | HLTError("Could not open the LUT file %s", lutFileName); | |
914 | return -ENOENT; | |
915 | } | |
916 | ||
917 | // First count the number of lines of text in the LUT file before decoding. | |
918 | // This is not the most optimal. It would be better to read and decode at the | |
919 | // same time but we are not allowed to use STL and ROOT containers are too | |
920 | // heavy for this task. At least this is done only at the start of run. | |
921 | std::string str; | |
922 | AliHLTUInt32_t lineCount = 0; | |
923 | while (std::getline(file, str)) lineCount++; | |
924 | if (not file.eof()) | |
925 | { | |
926 | HLTError("There was a problem reading the LUT file %s", lutFileName); | |
927 | return -EIO; | |
928 | } | |
929 | if (lineCount == 0) | |
930 | { | |
931 | HLTWarning("The LUT file %s was empty.", lutFileName); | |
932 | } | |
933 | ||
934 | // Add one extra LUT line for the first element which is used as a sentinel value. | |
935 | lineCount++; | |
936 | ||
937 | try | |
938 | { | |
939 | fLut = new AliHLTMUONHitRecoLutRow[lineCount]; | |
940 | fLutSize = lineCount; | |
941 | } | |
942 | catch (const std::bad_alloc&) | |
943 | { | |
944 | HLTError("Could not allocate more memory for the lookuptable."); | |
945 | return -ENOMEM; | |
946 | } | |
947 | ||
948 | // Initialise the sentinel value. | |
949 | fLut[0].fDetElemId = 0; | |
950 | fLut[0].fIX = 0; | |
951 | fLut[0].fIY = 0; | |
952 | fLut[0].fRealX = 0.0; | |
953 | fLut[0].fRealY = 0.0; | |
954 | fLut[0].fRealZ = 0.0; | |
955 | fLut[0].fHalfPadSize = 0.0; | |
956 | fLut[0].fPlane = -1; | |
957 | fLut[0].fPed = -1; | |
958 | fLut[0].fSigma = -1; | |
959 | fLut[0].fA0 = -1; | |
960 | fLut[0].fA1 = -1; | |
961 | fLut[0].fThres = -1; | |
962 | fLut[0].fSat = -1; | |
963 | ||
964 | // Clear the eof flag and start reading from the beginning of the file again. | |
965 | file.clear(); | |
966 | file.seekg(0, std::ios::beg); | |
967 | if (not file.good()) | |
968 | { | |
969 | HLTError("There was a problem seeking in the LUT file %s", lutFileName); | |
970 | return -EIO; | |
971 | } | |
972 | ||
83d66053 | 973 | AliHLTInt32_t idManuChannel,buspatchId; |
93a75941 | 974 | for (AliHLTUInt32_t i = 1; i < fLutSize; i++) |
975 | { | |
976 | if (std::getline(file, str).fail()) | |
977 | { | |
978 | HLTError("There was a problem reading line %d of LUT file %s", i, lutFileName); | |
979 | return -EIO; | |
980 | } | |
981 | ||
982 | int result = sscanf( | |
5533735a | 983 | str.c_str(), "%14d\t%14d\t%14d\t%14d\t%23e\t%23e\t%23e\t%23e\t%14d\t%23e\t%23e\t%23e\t%23e\t%14d\t%14d", |
93a75941 | 984 | &idManuChannel, &fLut[i].fDetElemId, &fLut[i].fIX, |
985 | &fLut[i].fIY, &fLut[i].fRealX, | |
986 | &fLut[i].fRealY, &fLut[i].fRealZ, | |
987 | &fLut[i].fHalfPadSize, &fLut[i].fPlane, | |
988 | &fLut[i].fPed, &fLut[i].fSigma, &fLut[i].fA0, | |
989 | &fLut[i].fA1, &fLut[i].fThres, &fLut[i].fSat | |
990 | ); | |
991 | ||
992 | if (result != 15) | |
993 | { | |
994 | HLTError("Line %d in LUT file %s does not contain 15 elements.", i, lutFileName); | |
995 | return -EIO; | |
996 | } | |
83d66053 | 997 | buspatchId = (idManuChannel>>17) & 0x7FF; |
93a75941 | 998 | fIdToEntry[idManuChannel] = i; |
83d66053 | 999 | fMaxEntryPerBusPatch[buspatchId] = fMaxEntryPerBusPatch[buspatchId] + 1; |
1000 | ||
1001 | } | |
1002 | ||
1003 | MaxEntryPerBusPatch::iterator it; | |
fd5b812e | 1004 | for(it=fMaxEntryPerBusPatch.begin(); it!=fMaxEntryPerBusPatch.end(); it++){ |
1005 | HLTDebug("fMaxEntryPerBusPatch[%d] : %d",it->first,it->second); | |
1006 | fMaxEntryPerBusPatch[it->first] = AliHLTInt32_t(0.05*(it->second));///< for 10% occupancy | |
1007 | HLTDebug("fMaxEntryPerBusPatch[%d] : %d",it->first,it->second); | |
93a75941 | 1008 | } |
1009 | ||
1010 | return 0; | |
ee3678d3 | 1011 | } |
1012 | ||
1013 | ||
ffc1a6f6 | 1014 | int AliHLTMUONHitReconstructorComponent::ReadLutFromCDB() |
b0201cbe | 1015 | { |
dba14d7d | 1016 | /// Reads LUT from CDB. |
ffc1a6f6 | 1017 | /// To override the default CDB path and / or run number the |
1018 | /// SetCDBPathAndRunNo(cdbPath, run) method should be called before this | |
1019 | /// method. | |
93a75941 | 1020 | |
1021 | assert( fLut == NULL ); | |
1022 | assert( fLutSize == 0 ); | |
1023 | assert( fIdToEntry.empty() ); | |
83d66053 | 1024 | assert( fMaxEntryPerBusPatch.empty() ); |
93a75941 | 1025 | |
a3d4b6ba | 1026 | if (fDDL == -1) |
1027 | { | |
1028 | HLTError("No DDL number specified for which to load LUT data from CDB."); | |
1029 | return -EINVAL; | |
1030 | } | |
1031 | ||
93a75941 | 1032 | std::vector<AliHLTMUONHitRecoLutRow> lutList; |
1033 | AliHLTMUONHitRecoLutRow lut; | |
1034 | AliHLTUInt32_t iEntry = 0; | |
1035 | ||
ffc1a6f6 | 1036 | int result = FetchMappingStores(); |
dba14d7d | 1037 | // Error message already generated in FetchMappingStores. |
1038 | if (result != 0) return result; | |
93a75941 | 1039 | AliMpDDLStore* ddlStore = AliMpDDLStore::Instance(); |
dba14d7d | 1040 | |
93a75941 | 1041 | AliMpSegmentation* mpSegFactory = AliMpSegmentation::Instance(); |
1042 | if (mpSegFactory == NULL) | |
1043 | { | |
1044 | HLTError("Could not find segmentation mapping (AliMpSegmentation) instance."); | |
1045 | return -EIO; | |
1046 | } | |
1047 | ||
61d982d3 | 1048 | // Only load geometry if not already loaded. |
1049 | if (AliGeomManager::GetGeometry() == NULL) | |
1050 | { | |
1051 | AliGeomManager::LoadGeometry(); | |
1052 | } | |
93a75941 | 1053 | AliMUONGeometryTransformer chamberGeometryTransformer; |
1054 | if (not chamberGeometryTransformer.LoadGeometryData()) | |
1055 | { | |
1056 | HLTError("Failed to load geomerty data."); | |
1057 | return -ENOENT; | |
1058 | } | |
fd5b812e | 1059 | |
ffc1a6f6 | 1060 | AliMUONCalibrationData calibData(AliCDBManager::Instance()->GetRun()); |
93a75941 | 1061 | |
56f0ccdf | 1062 | bool skippedPads = false; |
93a75941 | 1063 | Int_t chamberId; |
1064 | ||
75a65a51 | 1065 | for(Int_t iCh = 0; iCh < 10; iCh++) |
93a75941 | 1066 | { |
1067 | chamberId = iCh; | |
1068 | ||
1069 | AliMpDEIterator it; | |
1070 | for ( it.First(chamberId); ! it.IsDone(); it.Next() ) | |
1071 | { | |
1072 | Int_t detElemId = it.CurrentDEId(); | |
1073 | int iDDL = ddlStore->GetDetElement(detElemId)->GetDdlId(); | |
1074 | if (iDDL != fDDL) continue; | |
1075 | ||
1076 | for (Int_t iCath = 0 ; iCath <= 1 ; iCath++) | |
1077 | { | |
1078 | AliMp::CathodType cath; | |
1079 | ||
1080 | if(iCath == 0) | |
1081 | cath = AliMp::kCath0; | |
1082 | else | |
1083 | cath = AliMp::kCath1; | |
1084 | ||
1085 | const AliMpVSegmentation* seg = mpSegFactory->GetMpSegmentation(detElemId, cath); | |
1086 | AliMp::PlaneType plane = seg->PlaneType(); | |
1087 | Int_t maxIX = seg->MaxPadIndexX(); | |
1088 | Int_t maxIY = seg->MaxPadIndexY(); | |
1089 | ||
1090 | Int_t idManuChannel, manuId, channelId, buspatchId; | |
1091 | AliHLTFloat32_t padSizeX, padSizeY; | |
1092 | AliHLTFloat32_t halfPadSize; | |
fd5b812e | 1093 | AliHLTFloat32_t padSizeXY; |
93a75941 | 1094 | Double_t realX, realY, realZ; |
1095 | Double_t localX, localY, localZ; | |
1096 | Float_t calibA0Coeff,calibA1Coeff,pedestal,sigma; | |
56f0ccdf | 1097 | Float_t thresold,saturation; |
93a75941 | 1098 | |
1099 | // Pad Info of a slat to print in lookuptable | |
1100 | for (Int_t iX = 0; iX<= maxIX ; iX++) | |
1101 | for (Int_t iY = 0; iY<= maxIY ; iY++) | |
1102 | { | |
53eb3786 | 1103 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
168e9c4d | 1104 | if (not seg->HasPadByIndices(iX,iY)) continue; |
53eb3786 | 1105 | #else // old AliMpPad functionality < r 31742 |
1106 | if (not seg->HasPad(AliMpIntPair(iX,iY))) continue; | |
1107 | #endif | |
93a75941 | 1108 | |
53eb3786 | 1109 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
168e9c4d | 1110 | AliMpPad pad = seg->PadByIndices(iX,iY, kFALSE); |
53eb3786 | 1111 | #else // old AliMpPad functionality < r 31742 |
1112 | AliMpPad pad = seg->PadByIndices(AliMpIntPair(iX,iY), kFALSE); | |
1113 | #endif | |
93a75941 | 1114 | |
1115 | // Getting Manu id | |
53eb3786 | 1116 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
168e9c4d | 1117 | manuId = pad.GetManuId(); |
53eb3786 | 1118 | #else // old AliMpPad functionality < r 31742 |
1119 | manuId = pad.GetLocation().GetFirst(); | |
1120 | #endif | |
93a75941 | 1121 | manuId &= 0x7FF; // 11 bits |
56f0ccdf | 1122 | if (calibData.Gains(detElemId, manuId) == NULL) continue; |
1123 | if (calibData.Pedestals(detElemId, manuId) == NULL) continue; | |
93a75941 | 1124 | |
1125 | buspatchId = ddlStore->GetBusPatchId(detElemId,manuId); | |
1126 | ||
1127 | // Getting channel id | |
53eb3786 | 1128 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
168e9c4d | 1129 | channelId = pad.GetManuChannel(); |
53eb3786 | 1130 | #else // old AliMpPad functionality < r 31742 |
1131 | channelId = pad.GetLocation().GetSecond(); | |
1132 | #endif | |
93a75941 | 1133 | channelId &= 0x3F; // 6 bits |
1134 | ||
1135 | idManuChannel = buspatchId << 11; | |
1136 | idManuChannel = (idManuChannel | manuId) << 6; | |
1137 | idManuChannel |= channelId; | |
1138 | ||
53eb3786 | 1139 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
6e97fbb8 | 1140 | localX = pad.GetPositionX(); |
1141 | localY = pad.GetPositionY(); | |
53eb3786 | 1142 | #else // old AliMpPad functionality < r 31769 |
1143 | localX = pad.Position().X(); | |
1144 | localY = pad.Position().Y(); | |
1145 | #endif //HAVE_NOT_MUON_ALIMPPAD_GETPOSITION | |
93a75941 | 1146 | localZ = 0.0; |
1147 | ||
1148 | chamberGeometryTransformer.Local2Global( | |
1149 | detElemId,localX,localY,localZ, | |
1150 | realX,realY,realZ | |
1151 | ); | |
1152 | ||
53eb3786 | 1153 | #ifndef HAVE_NOT_MUON_ALIMPPAD_GETPOSITION |
6e97fbb8 | 1154 | padSizeX = AliHLTFloat32_t( pad.GetDimensionX() ); |
1155 | padSizeY = AliHLTFloat32_t( pad.GetDimensionY() ); | |
53eb3786 | 1156 | #else // old AliMpPad functionality < r 31769 |
1157 | padSizeX = AliHLTFloat32_t( pad.Dimensions().X() ); | |
1158 | padSizeY = AliHLTFloat32_t( pad.Dimensions().Y() ); | |
1159 | #endif //HAVE_NOT_MUON_ALIMPPAD_GETPOSITION | |
93a75941 | 1160 | |
90af8855 | 1161 | if (fUseIdealGain) |
1162 | { | |
1163 | calibA0Coeff = 1.0; | |
1164 | calibA1Coeff = 0.0; | |
1165 | thresold = 0; | |
1166 | saturation = 0; | |
1167 | } | |
1168 | else | |
1169 | { | |
1170 | calibA0Coeff = (calibData.Gains(detElemId, manuId))->ValueAsFloat(channelId, 0); | |
1171 | calibA1Coeff = (calibData.Gains(detElemId, manuId))->ValueAsFloat(channelId, 1); | |
56f0ccdf | 1172 | thresold = (calibData.Gains(detElemId, manuId))->ValueAsFloat(channelId, 2); |
1173 | saturation = (calibData.Gains(detElemId, manuId))->ValueAsFloat(channelId, 4); | |
90af8855 | 1174 | } |
93a75941 | 1175 | |
1176 | pedestal = (calibData.Pedestals(detElemId, manuId))->ValueAsFloat(channelId, 0); | |
1177 | sigma = (calibData.Pedestals(detElemId, manuId))->ValueAsFloat(channelId, 1); | |
1178 | ||
e5ff2d6f | 1179 | // Check if any of the values fetched from the calibration data are |
1180 | // invalid. If they are then skip this pad. | |
1181 | if (calibA0Coeff == AliMUONVCalibParam::InvalidFloatValue() or | |
1182 | calibA1Coeff == AliMUONVCalibParam::InvalidFloatValue() or | |
1183 | thresold == AliMUONVCalibParam::InvalidFloatValue() or | |
1184 | saturation == AliMUONVCalibParam::InvalidFloatValue() or | |
1185 | pedestal == AliMUONVCalibParam::InvalidFloatValue() or | |
1186 | sigma == AliMUONVCalibParam::InvalidFloatValue() | |
1187 | ) | |
1188 | { | |
56f0ccdf | 1189 | if (fWarnIfPadSkipped) |
1190 | { | |
1191 | HLTWarning("Skipping pad on detection element %d, MANU %d, channel %d, since" | |
1192 | " the calibration data contains invalid values in that channel.", | |
1193 | detElemId, manuId, channelId | |
1194 | ); | |
1195 | } | |
1196 | skippedPads = true; | |
e5ff2d6f | 1197 | continue; |
1198 | } | |
1199 | ||
fd5b812e | 1200 | |
1201 | if (plane == 0){ | |
93a75941 | 1202 | halfPadSize = padSizeX; |
fd5b812e | 1203 | padSizeXY = padSizeY; |
1204 | }else{ | |
93a75941 | 1205 | halfPadSize = padSizeY; |
fd5b812e | 1206 | padSizeXY = padSizeX; |
1207 | } | |
1208 | ||
93a75941 | 1209 | fIdToEntry[idManuChannel] = iEntry+1; |
83d66053 | 1210 | fMaxEntryPerBusPatch[buspatchId] = fMaxEntryPerBusPatch[buspatchId] + 1; |
1211 | ||
93a75941 | 1212 | lut.fDetElemId = detElemId; |
1213 | lut.fIX = iX; | |
1214 | lut.fIY = iY; | |
1215 | lut.fRealX = realX; | |
1216 | lut.fRealY = realY; | |
1217 | lut.fRealZ = realZ; | |
1218 | lut.fHalfPadSize = halfPadSize; | |
fd5b812e | 1219 | lut.fPadSizeXY = padSizeXY; |
93a75941 | 1220 | lut.fPlane = plane; |
1221 | lut.fPed = pedestal; | |
1222 | lut.fSigma = sigma; | |
1223 | lut.fA0 = calibA0Coeff; | |
1224 | lut.fA1 = calibA1Coeff; | |
56f0ccdf | 1225 | lut.fThres = Int_t(thresold); |
1226 | lut.fSat = Int_t(saturation); | |
93a75941 | 1227 | |
90af8855 | 1228 | HLTDebug("lut : detele : %d, id : %d, manu : %d, channel : %d, iX : %d, iY: %d, (X,Y) : (%f, %f), padsize : %f, plane : %d, ped : %f, sigma : %f", |
1229 | lut.fDetElemId,idManuChannel,manuId,channelId,lut.fIX,lut.fIY,lut.fRealX,lut.fRealY,lut.fHalfPadSize,lut.fPlane,lut.fPed,lut.fSigma | |
1230 | ); | |
1231 | ||
93a75941 | 1232 | lutList.push_back(lut); |
1233 | iEntry++; | |
1234 | } // iX, iY loop | |
1235 | } // iCath loop | |
1236 | } // detElemId loop | |
1237 | } // ichamber loop | |
56f0ccdf | 1238 | |
1239 | if (skippedPads and not fWarnIfPadSkipped) | |
1240 | { | |
1241 | HLTWarning("Skipped pads since they contained invalid calibration values." | |
1242 | " Use the -warnifpadskipped argument to generate detailed information" | |
1243 | " about which pads were skipped." | |
1244 | ); | |
1245 | } | |
93a75941 | 1246 | |
1247 | try | |
1248 | { | |
1249 | // Use iEntry+1 since we add one extra LUT line for the first element | |
1250 | // which is used as a sentinel value. | |
1251 | fLut = new AliHLTMUONHitRecoLutRow[iEntry+1]; | |
1252 | fLutSize = iEntry+1; | |
90af8855 | 1253 | HLTDebug("Address of new LUT buffer at fLut = %p", fLut); |
93a75941 | 1254 | } |
1255 | catch (const std::bad_alloc&) | |
1256 | { | |
1257 | HLTError("Could not allocate more memory for the lookuptable."); | |
90af8855 | 1258 | //lutList.clear(); not necessary, implicitly done during stack cleanup. |
93a75941 | 1259 | return -ENOMEM; |
1260 | } | |
1261 | ||
1262 | // Initialise the sentinel value. | |
1263 | fLut[0].fDetElemId = 0; | |
1264 | fLut[0].fIX = 0; | |
1265 | fLut[0].fIY = 0; | |
1266 | fLut[0].fRealX = 0.0; | |
1267 | fLut[0].fRealY = 0.0; | |
1268 | fLut[0].fRealZ = 0.0; | |
1269 | fLut[0].fHalfPadSize = 0.0; | |
fd5b812e | 1270 | fLut[0].fPadSizeXY = 0.0; |
93a75941 | 1271 | fLut[0].fPlane = -1; |
1272 | fLut[0].fPed = -1; | |
1273 | fLut[0].fSigma = -1; | |
1274 | fLut[0].fA0 = -1; | |
1275 | fLut[0].fA1 = -1; | |
1276 | fLut[0].fThres = -1; | |
1277 | fLut[0].fSat = -1; | |
1278 | ||
1279 | for (AliHLTUInt32_t i = 0; i < iEntry; i++) | |
1280 | fLut[i+1] = lutList[i]; | |
83d66053 | 1281 | lutList.clear(); |
1282 | ||
1283 | MaxEntryPerBusPatch::iterator it; | |
fd5b812e | 1284 | for(it=fMaxEntryPerBusPatch.begin(); it!=fMaxEntryPerBusPatch.end(); it++){ |
1285 | HLTDebug("fMaxEntryPerBusPatch[%d] : %d",it->first,it->second); | |
1286 | fMaxEntryPerBusPatch[it->first] = AliHLTInt32_t(0.05*(it->second));///< for 10% occupancy | |
1287 | HLTDebug("fMaxEntryPerBusPatch[%d] : %d",it->first,it->second); | |
83d66053 | 1288 | } |
1289 | ||
93a75941 | 1290 | return 0; |
b0201cbe | 1291 | } |
1292 | ||
b0201cbe | 1293 | |
2b7af22a | 1294 | int AliHLTMUONHitReconstructorComponent::ReadDCCutFromCDB() |
ffc1a6f6 | 1295 | { |
1296 | /// Reads the DC cut parameter from the CDB. | |
1297 | ||
1298 | const char* pathToEntry = AliHLTMUONConstants::HitReconstructorCDBPath(); | |
ffc1a6f6 | 1299 | |
1300 | TMap* map = NULL; | |
1301 | int result = FetchTMapFromCDB(pathToEntry, map); | |
1302 | if (result != 0) return result; | |
1303 | ||
1304 | Int_t value = 0; | |
1305 | result = GetPositiveIntFromTMap(map, "dccut", value, pathToEntry, "DC cut"); | |
1306 | if (result != 0) return result; | |
1307 | ||
1308 | assert(fHitRec != NULL); | |
1309 | fHitRec->SetDCCut(value); | |
1310 | ||
2b7af22a | 1311 | HLTDebug("Using DC cut parameter of %d ADC channels.", fHitRec->GetDCCut()); |
1312 | ||
ffc1a6f6 | 1313 | return 0; |
1314 | } | |
1315 | ||
1316 | ||
93a75941 | 1317 | bool AliHLTMUONHitReconstructorComponent::GenerateLookupTable( |
1318 | AliHLTInt32_t ddl, const char* filename, | |
ee3678d3 | 1319 | const char* cdbPath, Int_t run |
1320 | ) | |
b0201cbe | 1321 | { |
93a75941 | 1322 | /// Generates a ASCII text file containing the lookup table (LUT) from |
1323 | /// the CDB, which can be used for the hit reconstructor component later. | |
1324 | /// @param ddl Must be the DDL for which to generate the DDL, | |
f064ef44 | 1325 | /// in the range [0..19]. |
93a75941 | 1326 | /// @param filename The name of the LUT file to generate. |
1327 | /// @param cdbPath The CDB path to use. | |
1328 | /// @param run The run number to use for the CDB. | |
1329 | /// @return True if the generation of the LUT file succeeded. | |
1330 | ||
1331 | AliHLTMUONHitReconstructorComponent comp; | |
1332 | ||
f064ef44 | 1333 | if (ddl < 0 or 19 < ddl) |
93a75941 | 1334 | { |
f064ef44 | 1335 | std::cerr << "ERROR: the DDL number must be in the range [0..19]." << std::endl; |
93a75941 | 1336 | return false; |
1337 | } | |
1338 | ||
1339 | comp.fDDL = ddl; | |
ffc1a6f6 | 1340 | if (comp.SetCDBPathAndRunNo(cdbPath, run) != 0) return false; |
1341 | if (comp.ReadLutFromCDB() != 0) return false; | |
93a75941 | 1342 | |
1343 | char str[1024*4]; | |
1344 | std::fstream file(filename, std::ios::out); | |
1345 | if (not file) | |
1346 | { | |
1347 | std::cerr << "ERROR: could not open file: " << filename << std::endl; | |
1348 | return false; | |
1349 | } | |
1350 | ||
1351 | assert( comp.fLut != NULL ); | |
1352 | ||
1353 | for (IdManuChannelToEntry::iterator id = comp.fIdToEntry.begin(); | |
1354 | id != comp.fIdToEntry.end(); | |
1355 | id++ | |
1356 | ) | |
1357 | { | |
1358 | AliHLTInt32_t idManuChannel = id->first; | |
1359 | AliHLTInt32_t row = id->second; | |
ee3678d3 | 1360 | |
ffc1a6f6 | 1361 | assert( AliHLTUInt32_t(row) < comp.fLutSize ); |
ee3678d3 | 1362 | |
93a75941 | 1363 | sprintf(str, "%d\t%d\t%d\t%d\t%.15e\t%.15e\t%.15e\t%.15e\t%d\t%.15e\t%.15e\t%.15e\t%.15e\t%d\t%d", |
1364 | idManuChannel, comp.fLut[row].fDetElemId, comp.fLut[row].fIX, | |
1365 | comp.fLut[row].fIY, comp.fLut[row].fRealX, | |
1366 | comp.fLut[row].fRealY, comp.fLut[row].fRealZ, | |
1367 | comp.fLut[row].fHalfPadSize, comp.fLut[row].fPlane, | |
1368 | comp.fLut[row].fPed, comp.fLut[row].fSigma, comp.fLut[row].fA0, | |
1369 | comp.fLut[row].fA1, comp.fLut[row].fThres, comp.fLut[row].fSat | |
1370 | ); | |
ee3678d3 | 1371 | |
93a75941 | 1372 | file << str << endl; |
1373 | if (file.fail()) | |
1374 | { | |
1375 | std::cerr << "ERROR: There was an I/O error when writing to the file: " | |
1376 | << filename << std::endl; | |
1377 | return false; | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | return true; | |
b0201cbe | 1382 | } |