]>
Commit | Line | Data |
---|---|---|
154cba94 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: * | |
6 | * Artur Szostak <artursz@iafrica.com> * | |
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 * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
1d8ae082 | 17 | // $Id: $ |
154cba94 | 18 | |
19 | /// | |
20 | /// @file AliHLTMUONProcessor.cxx | |
21 | /// @author Artur Szostak <artursz@iafrica.com> | |
dba14d7d | 22 | /// @date 19 May 2008 |
154cba94 | 23 | /// @brief Implementation of the abstract base dHLT processor component. |
24 | /// | |
25 | /// This component is the abstract base class of dHLT specific components. | |
26 | /// It implements some common methods used by all the dHLT components. | |
27 | /// | |
28 | ||
29 | #include "AliHLTMUONProcessor.h" | |
bc5cb6d6 | 30 | #include "AliHLTMUONConstants.h" |
17d68f2a | 31 | #include "AliMUONRecoParam.h" |
dba14d7d | 32 | #include "AliCDBManager.h" |
33 | #include "AliCDBStorage.h" | |
ffc1a6f6 | 34 | #include "AliCDBEntry.h" |
bc5cb6d6 | 35 | #include "AliGRPManager.h" |
36 | #include "AliGRPObject.h" | |
37 | #include "AliMagF.h" | |
dba14d7d | 38 | #include "AliMpCDB.h" |
39 | #include "AliMpDDLStore.h" | |
40 | #include "AliMpDEStore.h" | |
bc5cb6d6 | 41 | #include "TGeoGlobalMagField.h" |
ffc1a6f6 | 42 | #include "TMap.h" |
43 | #include "TObjString.h" | |
44 | #include "TString.h" | |
ffb64d3e | 45 | #include <string> |
46 | #include <cstdlib> | |
47 | #include <fstream> | |
48 | ||
154cba94 | 49 | |
50 | ClassImp(AliHLTMUONProcessor) | |
51 | ||
dba14d7d | 52 | |
ffb64d3e | 53 | AliHLTMUONProcessor::AliHLTMUONProcessor() : |
54 | AliHLTProcessor(), | |
55 | fWarnForUnexpecedBlock(false), | |
56 | fDelaySetup(false), | |
57 | fDumpDataOnError(false), | |
58 | fDumpPath("./") | |
59 | { | |
60 | /// Default constructor. | |
61 | } | |
62 | ||
63 | ||
64 | int AliHLTMUONProcessor::DoInit(int argc, const char** argv) | |
65 | { | |
66 | /// Parses common dHLT component arguments. | |
67 | ||
68 | // Set the default values for various arguments comming from the command line. | |
69 | fDelaySetup = false; | |
70 | fDumpDataOnError = false; | |
71 | fDumpPath = "./"; | |
72 | const char* cdbPath = NULL; | |
73 | Int_t run = -1; | |
74 | ||
75 | for (int i = 0; i < argc; i++) | |
76 | { | |
77 | // Ignore the argument if the child class indicates to do so. | |
78 | if (IgnoreArgument(argv[i])) continue; | |
79 | ||
80 | if (strcmp(argv[i], "-cdbpath") == 0) | |
81 | { | |
82 | if (cdbPath != NULL) | |
83 | { | |
84 | HLTWarning("CDB path was already specified. Will" | |
85 | " replace previous value given by -cdbpath." | |
86 | ); | |
87 | } | |
88 | if (argc <= i+1) | |
89 | { | |
90 | HLTError("The CDB path was not specified." ); | |
91 | return -EINVAL; | |
92 | } | |
93 | cdbPath = argv[i+1]; | |
94 | i++; | |
95 | continue; | |
96 | } | |
97 | ||
98 | if (strcmp(argv[i], "-run") == 0) | |
99 | { | |
100 | if (run != -1) | |
101 | { | |
102 | HLTWarning("Run number was already specified. Will" | |
103 | " replace previous value given by -run." | |
104 | ); | |
105 | } | |
106 | if (argc <= i+1) | |
107 | { | |
108 | HLTError("The run number was not specified."); | |
109 | return -EINVAL; | |
110 | } | |
111 | ||
112 | char* cpErr = NULL; | |
113 | run = Int_t( strtol(argv[i+1], &cpErr, 0) ); | |
114 | if (cpErr == NULL or *cpErr != '\0' or run < 0) | |
115 | { | |
116 | HLTError("Cannot convert '%s' to a valid run number." | |
117 | " Expected a positive integer value.", argv[i+1] | |
118 | ); | |
119 | return -EINVAL; | |
120 | } | |
121 | ||
122 | i++; | |
123 | continue; | |
124 | } | |
125 | ||
126 | if (strcmp(argv[i], "-delaysetup") == 0) | |
127 | { | |
128 | fDelaySetup = true; | |
129 | continue; | |
130 | } | |
131 | ||
132 | if (strcmp(argv[i], "-dumponerror") == 0) | |
133 | { | |
134 | fDumpDataOnError = true; | |
135 | continue; | |
136 | } | |
137 | ||
138 | if (strcmp(argv[i], "-dumppath") == 0) | |
139 | { | |
140 | if (fDumpPath != NULL) | |
141 | { | |
142 | HLTWarning("The dump path was already specified. Will" | |
143 | " replace previous value given by -dumppath." | |
144 | ); | |
145 | } | |
146 | if (argc <= i+1) | |
147 | { | |
148 | HLTError("The dump path was not specified."); | |
149 | return -EINVAL; | |
150 | } | |
151 | fDumpPath = argv[i+1]; | |
152 | i++; | |
153 | continue; | |
154 | } | |
155 | } | |
156 | ||
157 | if (cdbPath != NULL or run != -1) | |
158 | { | |
159 | int result = SetCDBPathAndRunNo(cdbPath, run); | |
160 | if (result != 0) | |
161 | { | |
162 | // Error messages already generated in SetCDBPathAndRunNo. | |
163 | return result; | |
164 | } | |
165 | } | |
166 | ||
167 | return 0; | |
168 | } | |
169 | ||
170 | ||
171 | bool AliHLTMUONProcessor::ArgumentAlreadyHandled(int& i, const char* argi) const | |
172 | { | |
173 | /// This method can be used by the derivind child class to check if a particular | |
174 | /// argument in argv was already processed. | |
175 | ||
176 | if (strcmp(argi, "-cdbpath") == 0) | |
177 | { | |
178 | if (IgnoreArgument(argi)) return false; | |
a63da6d6 | 179 | i++; // argument takes one parameter |
ffb64d3e | 180 | return true; |
181 | } | |
182 | ||
183 | if (strcmp(argi, "-run") == 0) | |
184 | { | |
185 | if (IgnoreArgument(argi)) return false; | |
a63da6d6 | 186 | i++; // argument takes one parameter |
ffb64d3e | 187 | return true; |
188 | } | |
189 | ||
190 | if (strcmp(argi, "-delaysetup") == 0) | |
191 | { | |
192 | if (IgnoreArgument(argi)) return false; | |
193 | return true; | |
194 | } | |
195 | ||
196 | if (strcmp(argi, "-dumponerror") == 0) | |
197 | { | |
198 | if (IgnoreArgument(argi)) return false; | |
199 | return true; | |
200 | } | |
201 | ||
202 | if (strcmp(argi, "-dumppath") == 0) | |
203 | { | |
204 | if (IgnoreArgument(argi)) return false; | |
a63da6d6 | 205 | i++; // argument takes one parameter |
ffb64d3e | 206 | return true; |
207 | } | |
208 | ||
209 | return false; | |
210 | } | |
211 | ||
212 | ||
ffc1a6f6 | 213 | int AliHLTMUONProcessor::SetCDBPathAndRunNo( |
dba14d7d | 214 | const char* cdbPath, Int_t run, bool useDefault |
215 | ) const | |
216 | { | |
ffc1a6f6 | 217 | /// Sets the CDB path and run number to read from. |
dba14d7d | 218 | /// \param cdbPath The CDB path to use. If set to NULL and the path has |
219 | /// not been set in the CDB manager then the default path | |
162637e4 | 220 | /// "local://$ALICE_ROOT/OCDB" is used if the 'useDefault' flag is also true. |
dba14d7d | 221 | /// \param run The run number to use. If set to -1 and the run number has |
222 | /// not been set in the CDB manager then a value of zero is used if | |
223 | /// the 'useDefault' flag is also true. | |
ffc1a6f6 | 224 | /// \param useDefault If set to true then a default CDB path and/or run number |
dba14d7d | 225 | /// is used if they have not been set and 'cdbPath' == NULL or |
ffc1a6f6 | 226 | /// 'run' == -1. |
227 | /// \return Zero if the object could be loaded. Otherwise an error code, | |
228 | /// compatible with the HLT framework, is returned. | |
dba14d7d | 229 | |
162637e4 | 230 | const char* defaultPath = "local://$ALICE_ROOT/OCDB"; |
dba14d7d | 231 | Int_t defaultRun = 0; |
232 | ||
233 | AliCDBManager* cdbManager = AliCDBManager::Instance(); | |
234 | if (cdbManager == NULL) | |
235 | { | |
236 | HLTError("CDB manager instance does not exist."); | |
237 | return -EIO; | |
238 | } | |
239 | ||
240 | // Setup the CDB path. | |
dba14d7d | 241 | if (cdbPath != NULL) |
242 | { | |
243 | cdbManager->SetDefaultStorage(cdbPath); | |
dba14d7d | 244 | } |
ffc1a6f6 | 245 | else if (not cdbManager->IsDefaultStorageSet() and useDefault) |
dba14d7d | 246 | { |
ffc1a6f6 | 247 | cdbManager->SetDefaultStorage(defaultPath); |
dba14d7d | 248 | } |
249 | ||
250 | // Now setup the run number. | |
251 | if (run != -1) | |
252 | { | |
253 | cdbManager->SetRun(run); | |
254 | } | |
255 | else | |
256 | { | |
257 | if (useDefault) cdbManager->SetRun(defaultRun); | |
258 | } | |
ffc1a6f6 | 259 | |
260 | return 0; | |
261 | } | |
262 | ||
263 | ||
264 | int AliHLTMUONProcessor::FetchMappingStores() const | |
265 | { | |
266 | /// Fetches the DDL and detector element store objects for MUON mapping. | |
267 | /// \return Zero if the objects could be loaded. Otherwise an error code, | |
268 | /// which is compatible with the HLT framework, is returned. | |
269 | /// \note AliMpDDLStore::Instance() and AliMpDEStore::Instance() must be used | |
270 | /// to fetch the objects after this method returns a code equal to zero. | |
271 | ||
272 | Bool_t warn = kFALSE; | |
273 | ||
274 | // Check if the objects are already loaded. If they are then exit early, | |
275 | // otherwise we need to try load the objects. | |
276 | if (AliMpDDLStore::Instance(warn) != NULL and AliMpDEStore::Instance(warn) != NULL) | |
277 | return 0; | |
278 | ||
279 | AliCDBManager* cdbManager = AliCDBManager::Instance(); | |
280 | if (cdbManager == NULL) | |
281 | { | |
282 | HLTError("CDB manager instance does not exist."); | |
283 | return -EIO; | |
284 | } | |
285 | ||
286 | const char* cdbPathUsed = "unknown (not set)"; | |
287 | AliCDBStorage* store = cdbManager->GetDefaultStorage(); | |
288 | if (store != NULL) cdbPathUsed = store->GetURI().Data(); | |
289 | ||
dba14d7d | 290 | Int_t runUsed = cdbManager->GetRun(); |
291 | ||
292 | // Now we can try load the DDL and DE store objects. | |
dba14d7d | 293 | if (not AliMpCDB::LoadDDLStore(warn)) |
294 | { | |
295 | HLTError("Failed to load DDL or detector element store specified" | |
296 | " for CDB path '%s' and run no. %d.", | |
297 | cdbPathUsed, runUsed | |
298 | ); | |
299 | return -ENOENT; | |
300 | } | |
301 | ||
550ea228 | 302 | if (AliMpDDLStore::Instance(warn) == NULL or AliMpDEStore::Instance(warn) == NULL) |
dba14d7d | 303 | { |
304 | HLTError("Could not find or load the DDL or detector element store instance."); | |
305 | return -EIO; | |
306 | } | |
307 | ||
308 | return 0; | |
309 | } | |
310 | ||
ffc1a6f6 | 311 | |
312 | int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) const | |
313 | { | |
314 | /// Fetches a TMap object from the CDB. | |
315 | /// [in] \param pathToEntry The relative path to the entry in the CDB to fetch. | |
316 | /// [out] \param map This will be filled with the TMap object found if | |
317 | /// a successful status code is returned. Otherwise it will be unchanged. | |
318 | /// \return Zero if the object could be found. Otherwise an error code, | |
319 | /// which is compatible with the HLT framework, is returned. | |
320 | ||
321 | assert(AliCDBManager::Instance() != NULL); | |
322 | ||
21b32623 | 323 | AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage(); |
324 | if (store == NULL) | |
325 | { | |
326 | HLTError("Could not get the the default storage for the CDB."); | |
327 | return -EIO; | |
328 | } | |
329 | ||
330 | Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo()); | |
331 | Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version); | |
332 | AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion); | |
ffc1a6f6 | 333 | if (entry == NULL) |
334 | { | |
335 | HLTError("Could not get the CDB entry for \"%s\".", pathToEntry); | |
336 | return -EIO; | |
337 | } | |
338 | ||
339 | TObject* obj = entry->GetObject(); | |
340 | if (obj == NULL) | |
341 | { | |
342 | HLTError("Configuration object for \"%s\" is missing.", pathToEntry); | |
343 | return -ENOENT; | |
344 | } | |
345 | ||
346 | if (obj->IsA() != TMap::Class()) | |
347 | { | |
348 | HLTError("Wrong type for configuration object in \"%s\". Found a %s but we need a TMap.", | |
349 | pathToEntry, obj->ClassName() | |
350 | ); | |
351 | return -EPROTO; | |
352 | } | |
353 | map = dynamic_cast<TMap*>(obj); | |
354 | ||
355 | return 0; | |
356 | } | |
357 | ||
358 | ||
359 | int AliHLTMUONProcessor::GetValueFromTMap( | |
360 | TMap* map, const char* paramName, TString& value, | |
361 | const char* pathToEntry, const char* prettyName | |
362 | ) const | |
363 | { | |
364 | /// Tries to find the string value associated with a certain parameter in a TMap. | |
365 | /// [in] \param map The TMap object to search in. | |
366 | /// [in] \param paramName The name of the parameter to search for. | |
367 | /// [out] \param value Will be filled with the object found. | |
368 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
369 | /// Used when printing error messages. If set to NULL then a string of | |
370 | /// "(unknown)" is used. (default is NULL). | |
371 | /// [in] \param prettyName Should be the name of the parameter which will | |
372 | /// be used when printing error messages. If this is set to NULL then | |
373 | /// the paramName will be used instead (default is NULL). | |
374 | /// \return Zero if the object could be found. Otherwise an error code, | |
375 | /// which is compatible with the HLT framework, is returned. | |
376 | ||
377 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
378 | if (prettyName == NULL) prettyName = paramName; | |
379 | ||
380 | TPair* pair = static_cast<TPair*>(map->FindObject(paramName)); | |
381 | if (pair == NULL) | |
382 | { | |
383 | HLTError("Configuration object for \"%s\" does not contain the %s value.", | |
384 | pathToEntry, prettyName | |
385 | ); | |
386 | return -ENOENT; | |
387 | } | |
388 | TObject* valueObj = pair->Value(); | |
389 | if (valueObj->IsA() != TObjString::Class()) | |
390 | { | |
391 | HLTError("The %s parameter found in configuration object \"%s\"" | |
392 | " is not a TObjString. Found an object of type %s instead.", | |
393 | prettyName, pathToEntry, valueObj->ClassName() | |
394 | ); | |
395 | return -EPROTO; | |
396 | } | |
397 | value = dynamic_cast<TObjString*>(valueObj)->GetString(); | |
398 | ||
399 | return 0; | |
400 | } | |
401 | ||
402 | ||
403 | int AliHLTMUONProcessor::GetIntFromTMap( | |
404 | TMap* map, const char* paramName, Int_t& value, | |
405 | const char* pathToEntry, const char* prettyName | |
406 | ) const | |
407 | { | |
408 | /// Tries to find a certain parameter in the TMap object and convert it to | |
409 | /// an integer value. | |
410 | /// [in] \param map The TMap object to search in. | |
411 | /// [in] \param paramName The name of the parameter to search for. | |
412 | /// [out] \param value Will be filled with the integer value for the parameter, | |
413 | /// if it was found and it was an integer value. | |
414 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
415 | /// Used when printing error messages. If set to NULL then a string of | |
416 | /// "(unknown)" is used. (default is NULL). | |
417 | /// [in] \param prettyName Should be the name of the parameter which will | |
418 | /// be used when printing error messages. If this is set to NULL then | |
419 | /// the paramName will be used instead (default is NULL). | |
420 | /// \return Zero if the object could be found and is valid. Otherwise an | |
421 | /// error code, which is compatible with the HLT framework, is returned. | |
422 | ||
423 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
424 | if (prettyName == NULL) prettyName = paramName; | |
425 | ||
426 | TString valueStr; | |
2b7af22a | 427 | int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName); |
ffc1a6f6 | 428 | if (result != 0) return result; |
429 | ||
430 | if (not valueStr.IsDigit()) | |
431 | { | |
432 | HLTError("The %s parameter found in configuration object \"%s\"" | |
433 | "is not a valid integer number string; found \"%s\".", | |
434 | prettyName, pathToEntry, valueStr.Data() | |
435 | ); | |
436 | return -EPROTO; | |
437 | } | |
438 | value = valueStr.Atoi(); | |
439 | ||
440 | return 0; | |
441 | } | |
442 | ||
443 | ||
444 | int AliHLTMUONProcessor::GetPositiveIntFromTMap( | |
445 | TMap* map, const char* paramName, Int_t& value, | |
446 | const char* pathToEntry, const char* prettyName | |
447 | ) const | |
448 | { | |
449 | /// Tries to find a certain parameter in the TMap object and convert it to | |
450 | /// a positive integer value. | |
451 | /// [in] \param map The TMap object to search in. | |
452 | /// [in] \param paramName The name of the parameter to search for. | |
453 | /// [out] \param value Will be filled with the integer value for the parameter, | |
454 | /// if it was found and it was a positive integer value. | |
455 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
456 | /// Used when printing error messages. If set to NULL then a string of | |
457 | /// "(unknown)" is used. (default is NULL). | |
458 | /// [in] \param prettyName Should be the name of the parameter which will | |
459 | /// be used when printing error messages. If this is set to NULL then | |
460 | /// the paramName will be used instead (default is NULL). | |
461 | /// \return Zero if the object could be found and is valid. Otherwise an | |
462 | /// error code, which is compatible with the HLT framework, is returned. | |
463 | ||
464 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
465 | if (prettyName == NULL) prettyName = paramName; | |
466 | ||
467 | TString valueStr; | |
2b7af22a | 468 | int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName); |
ffc1a6f6 | 469 | if (result != 0) return result; |
470 | ||
471 | if (not valueStr.IsDigit()) | |
472 | { | |
473 | HLTError("The %s parameter found in configuration object \"%s\"" | |
474 | "is not a valid integer number string; found \"%s\".", | |
475 | prettyName, pathToEntry, valueStr.Data() | |
476 | ); | |
477 | return -EPROTO; | |
478 | } | |
479 | Int_t val = valueStr.Atoi(); | |
480 | if (val < 0) | |
481 | { | |
482 | HLTError("The %s parameter found in configuration object \"%s\"" | |
483 | "is not a positive integer number; found \"%d\".", | |
484 | prettyName, pathToEntry, val | |
485 | ); | |
486 | return -EPROTO; | |
487 | } | |
488 | value = val; | |
489 | ||
490 | return 0; | |
491 | } | |
492 | ||
493 | ||
494 | int AliHLTMUONProcessor::GetFloatFromTMap( | |
495 | TMap* map, const char* paramName, Double_t& value, | |
496 | const char* pathToEntry, const char* prettyName | |
497 | ) const | |
498 | { | |
499 | /// Tries to find a certain parameter in the TMap object and convert it to | |
500 | /// an floating point value. | |
501 | /// [in] \param map The TMap object to search in. | |
502 | /// [in] \param paramName The name of the parameter to search for. | |
503 | /// [out] \param value Will be filled with the floating point value for the | |
504 | /// parameter, if it was found and it was a floating point value. | |
505 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
506 | /// Used when printing error messages. If set to NULL then a string of | |
507 | /// "(unknown)" is used. (default is NULL). | |
508 | /// [in] \param prettyName Should be the name of the parameter which will | |
509 | /// be used when printing error messages. If this is set to NULL then | |
510 | /// the paramName will be used instead (default is NULL). | |
511 | /// \return Zero if the object could be found and is valid. Otherwise an | |
512 | /// error code, which is compatible with the HLT framework, is returned. | |
513 | ||
514 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
515 | if (prettyName == NULL) prettyName = paramName; | |
516 | ||
517 | TString valueStr; | |
2b7af22a | 518 | int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName); |
ffc1a6f6 | 519 | if (result != 0) return result; |
520 | ||
521 | if (not valueStr.IsFloat()) | |
522 | { | |
523 | HLTError("The %s parameter found in configuration object \"%s\"" | |
524 | "is not a valid floating point number string; found \"%s\".", | |
525 | prettyName, pathToEntry, valueStr.Data() | |
526 | ); | |
527 | return -EPROTO; | |
528 | } | |
529 | value = valueStr.Atof(); | |
530 | ||
531 | return 0; | |
532 | } | |
533 | ||
534 | ||
535 | int AliHLTMUONProcessor::GetPositiveFloatFromTMap( | |
536 | TMap* map, const char* paramName, Double_t& value, | |
537 | const char* pathToEntry, const char* prettyName | |
538 | ) const | |
539 | { | |
540 | /// Tries to find a certain parameter in the TMap object and convert it to | |
541 | /// an positive floating point value. | |
542 | /// [in] \param map The TMap object to search in. | |
543 | /// [in] \param paramName The name of the parameter to search for. | |
544 | /// [out] \param value Will be filled with the floating point value for the | |
545 | /// parameter, if it was found and it was a positive floating point value. | |
546 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
547 | /// Used when printing error messages. If set to NULL then a string of | |
548 | /// "(unknown)" is used. (default is NULL). | |
549 | /// [in] \param prettyName Should be the name of the parameter which will | |
550 | /// be used when printing error messages. If this is set to NULL then | |
551 | /// the paramName will be used instead (default is NULL). | |
552 | /// \return Zero if the object could be found and is valid. Otherwise an | |
553 | /// error code, which is compatible with the HLT framework, is returned. | |
554 | ||
555 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
556 | if (prettyName == NULL) prettyName = paramName; | |
557 | ||
558 | TString valueStr; | |
2b7af22a | 559 | int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName); |
ffc1a6f6 | 560 | if (result != 0) return result; |
561 | ||
562 | if (not valueStr.IsFloat()) | |
563 | { | |
564 | HLTError("The %s parameter found in configuration object \"%s\"" | |
565 | "is not a valid floating point number string; found \"%s\".", | |
566 | prettyName, pathToEntry, valueStr.Data() | |
567 | ); | |
568 | return -EPROTO; | |
569 | } | |
570 | Double_t val = valueStr.Atof(); | |
571 | if (val < 0) | |
572 | { | |
573 | HLTError("The %s parameter found in configuration object \"%s\"" | |
574 | "is not a positive floating point number; found \"%d\".", | |
575 | prettyName, pathToEntry, val | |
576 | ); | |
577 | return -EPROTO; | |
578 | } | |
579 | value = val; | |
580 | ||
581 | return 0; | |
582 | } | |
17d68f2a | 583 | |
584 | ||
bc5cb6d6 | 585 | int AliHLTMUONProcessor::FetchFieldIntegral(Double_t& bfieldintegral) const |
586 | { | |
587 | // Fetches the correct dipole magnetic field integral to use. | |
588 | ||
589 | Float_t currentL3 = 0; | |
590 | Float_t currentDip = 0; | |
591 | ||
592 | if (TGeoGlobalMagField::Instance() == NULL or | |
593 | (TGeoGlobalMagField::Instance() != NULL and TGeoGlobalMagField::Instance()->GetField() == NULL) | |
594 | ) | |
595 | { | |
596 | HLTWarning("The magnetic field has not been set in TGeoGlobalMagField." | |
597 | " Will try and load the GRP entry directly." | |
598 | ); | |
599 | ||
600 | AliGRPManager grpman; | |
601 | if (not grpman.ReadGRPEntry() or grpman.GetGRPData() == NULL) | |
602 | { | |
603 | HLTError("GRP entry could not be loaded."); | |
604 | return -EIO; | |
605 | } | |
606 | ||
607 | const AliGRPObject* grp = grpman.GetGRPData(); | |
608 | Char_t polarityL3 = grp->GetL3Polarity(); | |
609 | Char_t polarityDip = grp->GetDipolePolarity(); | |
610 | currentL3 = grp->GetL3Current(AliGRPObject::kMean); | |
611 | currentDip = grp->GetDipoleCurrent(AliGRPObject::kMean); | |
612 | if (polarityL3 == AliGRPObject::GetInvalidChar()) | |
613 | { | |
614 | HLTError("L3 polarity in GRP is invalid."); | |
615 | return -EPROTO; | |
616 | } | |
617 | if (polarityDip == AliGRPObject::GetInvalidChar()) | |
618 | { | |
619 | HLTError("Dipole polarity in GRP is invalid."); | |
620 | return -EPROTO; | |
621 | } | |
622 | if (currentL3 == AliGRPObject::GetInvalidFloat()) | |
623 | { | |
624 | HLTError("L3 current in GRP is invalid."); | |
625 | return -EPROTO; | |
626 | } | |
627 | if (currentDip == AliGRPObject::GetInvalidFloat()) | |
628 | { | |
629 | HLTError("Dipole current in GRP is invalid."); | |
630 | return -EPROTO; | |
631 | } | |
632 | if (grp->IsPolarityConventionLHC()) | |
633 | { | |
634 | currentL3 *= (polarityL3 ? -1:1); | |
635 | currentDip *= (polarityDip ? -1:1); | |
636 | } | |
637 | else | |
638 | { | |
639 | currentL3 *= (polarityL3 ? -1:1); | |
640 | currentDip *= (polarityDip ? 1:-1); | |
641 | } | |
642 | } | |
643 | else | |
644 | { | |
645 | TVirtualMagField* vfield = TGeoGlobalMagField::Instance()->GetField(); | |
646 | AliMagF* field = dynamic_cast<AliMagF*>(vfield); | |
647 | if (vfield->IsA() != AliMagF::Class() and field != NULL) | |
648 | { | |
649 | HLTError(Form( | |
650 | "The magnetic field is not of type AliMagF." | |
651 | " Do not know how to handle class of type '%s'.", | |
652 | vfield->ClassName() | |
653 | )); | |
654 | return -EPROTO; | |
655 | } | |
656 | currentL3 = field->GetCurrentSol(); | |
657 | currentDip = field->GetCurrentDip(); | |
658 | } | |
659 | ||
660 | const char* path = AliHLTMUONConstants::FieldIntegralsCDBPath(); | |
661 | TMap* map = NULL; | |
662 | int result = FetchTMapFromCDB(path, map); | |
663 | if (result != 0) return result; | |
664 | const char* paramName = Form("L3_current=%0.2e;Dipole_current=%0.2e", currentL3, currentDip); | |
665 | Double_t value; | |
666 | result = GetFloatFromTMap(map, paramName, value, path); | |
667 | if (result != 0) return result; | |
668 | bfieldintegral = value; | |
669 | return 0; | |
670 | } | |
671 | ||
672 | ||
17d68f2a | 673 | int AliHLTMUONProcessor::LoadRecoParamsFromCDB(AliMUONRecoParam*& params) const |
674 | { | |
675 | /// Fetches the reconstruction parameters object from the CDB for MUON. | |
676 | /// [out] \param params This will be filled with the reconstruction | |
677 | /// parameters object found if a successful status code is returned. | |
678 | /// Otherwise it will be unchanged. | |
679 | /// \return Zero if the object could be found. Otherwise an error code, | |
680 | /// which is compatible with the HLT framework, is returned. | |
681 | ||
682 | assert(AliCDBManager::Instance() != NULL); | |
21b32623 | 683 | |
684 | AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage(); | |
685 | if (store == NULL) | |
686 | { | |
687 | HLTError("Could not get the the default storage for the CDB."); | |
688 | return -EIO; | |
689 | } | |
690 | ||
17d68f2a | 691 | const char* pathToEntry = "MUON/Calib/RecoParam"; |
21b32623 | 692 | Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo()); |
693 | Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version); | |
694 | AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion); | |
17d68f2a | 695 | if (entry == NULL) |
696 | { | |
697 | HLTError("Could not get the CDB entry for \"%s\".", pathToEntry); | |
698 | return -EIO; | |
699 | } | |
700 | ||
701 | TObject* obj = entry->GetObject(); | |
702 | if (obj == NULL) | |
703 | { | |
704 | HLTError("Reconstruction parameters object for \"%s\" is missing.", pathToEntry); | |
705 | return -ENOENT; | |
706 | } | |
707 | ||
708 | TObjArray* objarr = dynamic_cast<TObjArray*>(obj); | |
709 | if (objarr != NULL) | |
710 | { | |
711 | obj = objarr->Last(); | |
712 | } | |
713 | ||
714 | AliMUONRecoParam* par = dynamic_cast<AliMUONRecoParam*>(obj); | |
715 | if (par == NULL) | |
716 | { | |
717 | HLTError("No AliMUONRecoParam class found for entry \"%s\". Found a %s class instead.", | |
718 | pathToEntry, obj->ClassName() | |
719 | ); | |
720 | return -EPROTO; | |
721 | } | |
722 | ||
723 | params = par; | |
724 | return 0; | |
725 | } | |
726 | ||
ffb64d3e | 727 | |
728 | void AliHLTMUONProcessor::DumpBuffer( | |
729 | const void* buffer, AliHLTUInt32_t size, const char* filename | |
730 | ) const | |
731 | { | |
732 | /// Dumps the data contained in a buffer to file as is. | |
733 | ||
734 | using std::fstream; | |
735 | ||
736 | fstream file(filename, fstream::out | fstream::trunc | fstream::binary); | |
737 | if (file.good()) | |
738 | { | |
739 | file.write(reinterpret_cast<const char*>(buffer), size); | |
740 | if (file.fail()) | |
741 | { | |
742 | HLTError("Could not write data block to file %s during" | |
743 | " dumping operation!", | |
744 | filename | |
745 | ); | |
746 | } | |
747 | } | |
748 | else | |
749 | { | |
750 | HLTError("Could not open file %s for dumping data block!", filename); | |
751 | } | |
752 | } | |
753 | ||
754 | ||
755 | void AliHLTMUONProcessor::DumpBlock( | |
756 | const AliHLTComponentBlockData* block, const char* fileNamePrefix | |
757 | ) const | |
758 | { | |
759 | /// Dumps the data block and meta information to file. | |
760 | ||
761 | std::string filename = fDumpPath; | |
762 | filename += fileNamePrefix; | |
763 | filename += "-blockmeta.bin"; | |
764 | DumpBuffer(block, sizeof(AliHLTComponentBlockData), filename.c_str()); | |
765 | filename = fDumpPath; | |
766 | filename += fileNamePrefix; | |
767 | filename += "-data.bin"; | |
768 | DumpBuffer(block->fPtr, block->fSize, filename.c_str()); | |
769 | } | |
770 | ||
771 | ||
772 | void AliHLTMUONProcessor::DumpEvent( | |
773 | const AliHLTComponentEventData& evtData, | |
774 | const AliHLTComponentBlockData* blocks, | |
775 | AliHLTComponentTriggerData& trigData, | |
776 | AliHLTUInt8_t* outputPtr, | |
777 | AliHLTUInt32_t& size, | |
778 | AliHLTComponentBlockDataList& outputBlocks | |
779 | ) const | |
780 | { | |
781 | /// Dumps the event information to files in the dump path given by the | |
782 | /// method DumpPath, which can be set by the command line argument -dumppath. | |
783 | ||
784 | using std::fstream; | |
785 | char strbuf[1024]; | |
786 | ||
787 | std::string filename = fDumpPath; | |
788 | sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID); | |
789 | filename += strbuf; | |
790 | fstream logfile(filename.c_str(), fstream::out | fstream::trunc); | |
791 | if (logfile.fail()) | |
792 | { | |
793 | HLTError("Could not open log file '%s' for dump information.", filename.c_str()); | |
794 | return; | |
795 | } | |
796 | ||
797 | filename = fDumpPath; | |
798 | sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID); | |
799 | filename += strbuf; | |
800 | logfile << "Dumping event data structure to file: " << filename << std::endl; | |
801 | DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str()); | |
802 | ||
803 | filename = fDumpPath; | |
804 | sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID); | |
805 | filename += strbuf; | |
806 | logfile << "Dumping trigger data structure to file: " << filename << std::endl; | |
807 | DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str()); | |
808 | ||
809 | for (unsigned int n = 0; n < evtData.fBlockCnt; n++) | |
810 | { | |
811 | sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, n); | |
812 | filename = strbuf; | |
813 | sprintf(strbuf, "0x%8.8X", blocks[n].fSpecification); | |
814 | logfile << "Found block with data type = " << DataType2Text(blocks[n].fDataType) | |
815 | << ", specification = " << strbuf << ". Dumping to file: " | |
816 | << filename << "-data.bin" << std::endl; | |
817 | DumpBlock(&blocks[n], filename.c_str()); | |
818 | } | |
819 | ||
820 | filename = fDumpPath; | |
821 | sprintf(strbuf, "dump_event-0x%16.16llX-output-buffer.bin", evtData.fEventID); | |
822 | filename += strbuf; | |
823 | logfile << "Dumping output buffer to file: " << filename << std::endl; | |
824 | DumpBuffer(outputPtr, size, filename.c_str()); | |
825 | ||
826 | for (size_t i = 0; i < outputBlocks.size(); i++) | |
827 | { | |
828 | sprintf(strbuf, "dump_event-0x%16.16llX-output-block-0x%8.8X", evtData.fEventID, int(i)); | |
829 | filename = strbuf; | |
830 | sprintf(strbuf, "0x%8.8X", outputBlocks[i].fSpecification); | |
831 | logfile << "Generated output data block with type = " | |
832 | << DataType2Text(outputBlocks[i].fDataType) | |
833 | << ", specification = " << strbuf << ". Dumping to file: " | |
834 | << filename << "-data.bin" << std::endl; | |
835 | DumpBlock(&outputBlocks[i], filename.c_str()); | |
836 | } | |
837 | } | |
838 | ||
839 | ||
840 | void AliHLTMUONProcessor::DumpEvent( | |
841 | const AliHLTComponentEventData& evtData, | |
842 | AliHLTComponentTriggerData& trigData | |
843 | ) const | |
844 | { | |
845 | /// Dumps the event information to files in the dump path given by the | |
846 | /// method DumpPath, which can be set by the command line argument -dumppath. | |
847 | ||
848 | using std::fstream; | |
849 | char strbuf[1024]; | |
850 | ||
851 | std::string filename = fDumpPath; | |
852 | sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID); | |
853 | filename += strbuf; | |
854 | fstream logfile(filename.c_str(), fstream::out | fstream::trunc); | |
855 | if (logfile.fail()) | |
856 | { | |
857 | HLTError("Could not open log file '%s' for dump information.", filename.c_str()); | |
858 | return; | |
859 | } | |
860 | ||
861 | filename = fDumpPath; | |
862 | sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID); | |
863 | filename += strbuf; | |
864 | logfile << "Dumping event data structure to file: " << filename << std::endl; | |
865 | DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str()); | |
866 | ||
867 | filename = fDumpPath; | |
868 | sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID); | |
869 | filename += strbuf; | |
870 | logfile << "Dumping trigger data structure to file: " << filename << std::endl; | |
871 | DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str()); | |
872 | ||
873 | for (int i = 0; i < GetNumberOfInputBlocks(); i++) | |
874 | { | |
875 | const AliHLTComponentBlockData* block = GetInputBlock(i); | |
876 | sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, i); | |
877 | filename = strbuf; | |
878 | sprintf(strbuf, "0x%8.8X", block->fSpecification); | |
879 | logfile << "Found block with data type = " << DataType2Text(block->fDataType) | |
880 | << ", specification = " << strbuf << ". Dumping to file: " | |
881 | << filename << "-data.bin" << std::endl; | |
882 | DumpBlock(block, filename.c_str()); | |
883 | } | |
884 | } | |
885 |