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