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