1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
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 **************************************************************************/
20 /// @file AliHLTMUONProcessor.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
23 /// @brief Implementation of the abstract base dHLT processor component.
25 /// This component is the abstract base class of dHLT specific components.
26 /// It implements some common methods used by all the dHLT components.
29 #include "AliHLTMUONProcessor.h"
30 #include "AliMUONRecoParam.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBStorage.h"
33 #include "AliCDBEntry.h"
35 #include "AliMpDDLStore.h"
36 #include "AliMpDEStore.h"
38 #include "TObjString.h"
45 ClassImp(AliHLTMUONProcessor)
48 AliHLTMUONProcessor::AliHLTMUONProcessor() :
50 fWarnForUnexpecedBlock(false),
52 fDumpDataOnError(false),
55 /// Default constructor.
59 int AliHLTMUONProcessor::DoInit(int argc, const char** argv)
61 /// Parses common dHLT component arguments.
63 // Set the default values for various arguments comming from the command line.
65 fDumpDataOnError = false;
67 const char* cdbPath = NULL;
70 for (int i = 0; i < argc; i++)
72 // Ignore the argument if the child class indicates to do so.
73 if (IgnoreArgument(argv[i])) continue;
75 if (strcmp(argv[i], "-cdbpath") == 0)
79 HLTWarning("CDB path was already specified. Will"
80 " replace previous value given by -cdbpath."
85 HLTError("The CDB path was not specified." );
93 if (strcmp(argv[i], "-run") == 0)
97 HLTWarning("Run number was already specified. Will"
98 " replace previous value given by -run."
103 HLTError("The run number was not specified.");
108 run = Int_t( strtol(argv[i+1], &cpErr, 0) );
109 if (cpErr == NULL or *cpErr != '\0' or run < 0)
111 HLTError("Cannot convert '%s' to a valid run number."
112 " Expected a positive integer value.", argv[i+1]
121 if (strcmp(argv[i], "-delaysetup") == 0)
127 if (strcmp(argv[i], "-dumponerror") == 0)
129 fDumpDataOnError = true;
133 if (strcmp(argv[i], "-dumppath") == 0)
135 if (fDumpPath != NULL)
137 HLTWarning("The dump path was already specified. Will"
138 " replace previous value given by -dumppath."
143 HLTError("The dump path was not specified.");
146 fDumpPath = argv[i+1];
152 if (cdbPath != NULL or run != -1)
154 int result = SetCDBPathAndRunNo(cdbPath, run);
157 // Error messages already generated in SetCDBPathAndRunNo.
166 bool AliHLTMUONProcessor::ArgumentAlreadyHandled(int& i, const char* argi) const
168 /// This method can be used by the derivind child class to check if a particular
169 /// argument in argv was already processed.
171 if (strcmp(argi, "-cdbpath") == 0)
173 if (IgnoreArgument(argi)) return false;
174 i++; // argument takes one parameter
178 if (strcmp(argi, "-run") == 0)
180 if (IgnoreArgument(argi)) return false;
181 i++; // argument takes one parameter
185 if (strcmp(argi, "-delaysetup") == 0)
187 if (IgnoreArgument(argi)) return false;
191 if (strcmp(argi, "-dumponerror") == 0)
193 if (IgnoreArgument(argi)) return false;
197 if (strcmp(argi, "-dumppath") == 0)
199 if (IgnoreArgument(argi)) return false;
200 i++; // argument takes one parameter
208 int AliHLTMUONProcessor::SetCDBPathAndRunNo(
209 const char* cdbPath, Int_t run, bool useDefault
212 /// Sets the CDB path and run number to read from.
213 /// \param cdbPath The CDB path to use. If set to NULL and the path has
214 /// not been set in the CDB manager then the default path
215 /// "local://$ALICE_ROOT/OCDB" is used if the 'useDefault' flag is also true.
216 /// \param run The run number to use. If set to -1 and the run number has
217 /// not been set in the CDB manager then a value of zero is used if
218 /// the 'useDefault' flag is also true.
219 /// \param useDefault If set to true then a default CDB path and/or run number
220 /// is used if they have not been set and 'cdbPath' == NULL or
222 /// \return Zero if the object could be loaded. Otherwise an error code,
223 /// compatible with the HLT framework, is returned.
225 const char* defaultPath = "local://$ALICE_ROOT/OCDB";
226 Int_t defaultRun = 0;
228 AliCDBManager* cdbManager = AliCDBManager::Instance();
229 if (cdbManager == NULL)
231 HLTError("CDB manager instance does not exist.");
235 // Setup the CDB path.
238 cdbManager->SetDefaultStorage(cdbPath);
240 else if (not cdbManager->IsDefaultStorageSet() and useDefault)
242 cdbManager->SetDefaultStorage(defaultPath);
245 // Now setup the run number.
248 cdbManager->SetRun(run);
252 if (useDefault) cdbManager->SetRun(defaultRun);
259 int AliHLTMUONProcessor::FetchMappingStores() const
261 /// Fetches the DDL and detector element store objects for MUON mapping.
262 /// \return Zero if the objects could be loaded. Otherwise an error code,
263 /// which is compatible with the HLT framework, is returned.
264 /// \note AliMpDDLStore::Instance() and AliMpDEStore::Instance() must be used
265 /// to fetch the objects after this method returns a code equal to zero.
267 Bool_t warn = kFALSE;
269 // Check if the objects are already loaded. If they are then exit early,
270 // otherwise we need to try load the objects.
271 if (AliMpDDLStore::Instance(warn) != NULL and AliMpDEStore::Instance(warn) != NULL)
274 AliCDBManager* cdbManager = AliCDBManager::Instance();
275 if (cdbManager == NULL)
277 HLTError("CDB manager instance does not exist.");
281 const char* cdbPathUsed = "unknown (not set)";
282 AliCDBStorage* store = cdbManager->GetDefaultStorage();
283 if (store != NULL) cdbPathUsed = store->GetURI().Data();
285 Int_t runUsed = cdbManager->GetRun();
287 // Now we can try load the DDL and DE store objects.
288 if (not AliMpCDB::LoadDDLStore(warn))
290 HLTError("Failed to load DDL or detector element store specified"
291 " for CDB path '%s' and run no. %d.",
297 if (AliMpDDLStore::Instance(warn) == NULL or AliMpDEStore::Instance(warn) == NULL)
299 HLTError("Could not find or load the DDL or detector element store instance.");
307 int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) const
309 /// Fetches a TMap object from the CDB.
310 /// [in] \param pathToEntry The relative path to the entry in the CDB to fetch.
311 /// [out] \param map This will be filled with the TMap object found if
312 /// a successful status code is returned. Otherwise it will be unchanged.
313 /// \return Zero if the object could be found. Otherwise an error code,
314 /// which is compatible with the HLT framework, is returned.
316 assert(AliCDBManager::Instance() != NULL);
318 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
321 HLTError("Could not get the the default storage for the CDB.");
325 Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo());
326 Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version);
327 AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion);
330 HLTError("Could not get the CDB entry for \"%s\".", pathToEntry);
334 TObject* obj = entry->GetObject();
337 HLTError("Configuration object for \"%s\" is missing.", pathToEntry);
341 if (obj->IsA() != TMap::Class())
343 HLTError("Wrong type for configuration object in \"%s\". Found a %s but we need a TMap.",
344 pathToEntry, obj->ClassName()
348 map = dynamic_cast<TMap*>(obj);
354 int AliHLTMUONProcessor::GetValueFromTMap(
355 TMap* map, const char* paramName, TString& value,
356 const char* pathToEntry, const char* prettyName
359 /// Tries to find the string value associated with a certain parameter in a TMap.
360 /// [in] \param map The TMap object to search in.
361 /// [in] \param paramName The name of the parameter to search for.
362 /// [out] \param value Will be filled with the object found.
363 /// [in] \param pathToEntry The relative path to the entry in the CDB.
364 /// Used when printing error messages. If set to NULL then a string of
365 /// "(unknown)" is used. (default is NULL).
366 /// [in] \param prettyName Should be the name of the parameter which will
367 /// be used when printing error messages. If this is set to NULL then
368 /// the paramName will be used instead (default is NULL).
369 /// \return Zero if the object could be found. Otherwise an error code,
370 /// which is compatible with the HLT framework, is returned.
372 if (pathToEntry == NULL) pathToEntry = "(unknown)";
373 if (prettyName == NULL) prettyName = paramName;
375 TPair* pair = static_cast<TPair*>(map->FindObject(paramName));
378 HLTError("Configuration object for \"%s\" does not contain the %s value.",
379 pathToEntry, prettyName
383 TObject* valueObj = pair->Value();
384 if (valueObj->IsA() != TObjString::Class())
386 HLTError("The %s parameter found in configuration object \"%s\""
387 " is not a TObjString. Found an object of type %s instead.",
388 prettyName, pathToEntry, valueObj->ClassName()
392 value = dynamic_cast<TObjString*>(valueObj)->GetString();
398 int AliHLTMUONProcessor::GetIntFromTMap(
399 TMap* map, const char* paramName, Int_t& value,
400 const char* pathToEntry, const char* prettyName
403 /// Tries to find a certain parameter in the TMap object and convert it to
404 /// an integer value.
405 /// [in] \param map The TMap object to search in.
406 /// [in] \param paramName The name of the parameter to search for.
407 /// [out] \param value Will be filled with the integer value for the parameter,
408 /// if it was found and it was an integer value.
409 /// [in] \param pathToEntry The relative path to the entry in the CDB.
410 /// Used when printing error messages. If set to NULL then a string of
411 /// "(unknown)" is used. (default is NULL).
412 /// [in] \param prettyName Should be the name of the parameter which will
413 /// be used when printing error messages. If this is set to NULL then
414 /// the paramName will be used instead (default is NULL).
415 /// \return Zero if the object could be found and is valid. Otherwise an
416 /// error code, which is compatible with the HLT framework, is returned.
418 if (pathToEntry == NULL) pathToEntry = "(unknown)";
419 if (prettyName == NULL) prettyName = paramName;
422 int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
423 if (result != 0) return result;
425 if (not valueStr.IsDigit())
427 HLTError("The %s parameter found in configuration object \"%s\""
428 "is not a valid integer number string; found \"%s\".",
429 prettyName, pathToEntry, valueStr.Data()
433 value = valueStr.Atoi();
439 int AliHLTMUONProcessor::GetPositiveIntFromTMap(
440 TMap* map, const char* paramName, Int_t& value,
441 const char* pathToEntry, const char* prettyName
444 /// Tries to find a certain parameter in the TMap object and convert it to
445 /// a positive integer value.
446 /// [in] \param map The TMap object to search in.
447 /// [in] \param paramName The name of the parameter to search for.
448 /// [out] \param value Will be filled with the integer value for the parameter,
449 /// if it was found and it was a positive integer value.
450 /// [in] \param pathToEntry The relative path to the entry in the CDB.
451 /// Used when printing error messages. If set to NULL then a string of
452 /// "(unknown)" is used. (default is NULL).
453 /// [in] \param prettyName Should be the name of the parameter which will
454 /// be used when printing error messages. If this is set to NULL then
455 /// the paramName will be used instead (default is NULL).
456 /// \return Zero if the object could be found and is valid. Otherwise an
457 /// error code, which is compatible with the HLT framework, is returned.
459 if (pathToEntry == NULL) pathToEntry = "(unknown)";
460 if (prettyName == NULL) prettyName = paramName;
463 int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
464 if (result != 0) return result;
466 if (not valueStr.IsDigit())
468 HLTError("The %s parameter found in configuration object \"%s\""
469 "is not a valid integer number string; found \"%s\".",
470 prettyName, pathToEntry, valueStr.Data()
474 Int_t val = valueStr.Atoi();
477 HLTError("The %s parameter found in configuration object \"%s\""
478 "is not a positive integer number; found \"%d\".",
479 prettyName, pathToEntry, val
489 int AliHLTMUONProcessor::GetFloatFromTMap(
490 TMap* map, const char* paramName, Double_t& value,
491 const char* pathToEntry, const char* prettyName
494 /// Tries to find a certain parameter in the TMap object and convert it to
495 /// an floating point value.
496 /// [in] \param map The TMap object to search in.
497 /// [in] \param paramName The name of the parameter to search for.
498 /// [out] \param value Will be filled with the floating point value for the
499 /// parameter, if it was found and it was a floating point value.
500 /// [in] \param pathToEntry The relative path to the entry in the CDB.
501 /// Used when printing error messages. If set to NULL then a string of
502 /// "(unknown)" is used. (default is NULL).
503 /// [in] \param prettyName Should be the name of the parameter which will
504 /// be used when printing error messages. If this is set to NULL then
505 /// the paramName will be used instead (default is NULL).
506 /// \return Zero if the object could be found and is valid. Otherwise an
507 /// error code, which is compatible with the HLT framework, is returned.
509 if (pathToEntry == NULL) pathToEntry = "(unknown)";
510 if (prettyName == NULL) prettyName = paramName;
513 int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
514 if (result != 0) return result;
516 if (not valueStr.IsFloat())
518 HLTError("The %s parameter found in configuration object \"%s\""
519 "is not a valid floating point number string; found \"%s\".",
520 prettyName, pathToEntry, valueStr.Data()
524 value = valueStr.Atof();
530 int AliHLTMUONProcessor::GetPositiveFloatFromTMap(
531 TMap* map, const char* paramName, Double_t& value,
532 const char* pathToEntry, const char* prettyName
535 /// Tries to find a certain parameter in the TMap object and convert it to
536 /// an positive floating point value.
537 /// [in] \param map The TMap object to search in.
538 /// [in] \param paramName The name of the parameter to search for.
539 /// [out] \param value Will be filled with the floating point value for the
540 /// parameter, if it was found and it was a positive floating point value.
541 /// [in] \param pathToEntry The relative path to the entry in the CDB.
542 /// Used when printing error messages. If set to NULL then a string of
543 /// "(unknown)" is used. (default is NULL).
544 /// [in] \param prettyName Should be the name of the parameter which will
545 /// be used when printing error messages. If this is set to NULL then
546 /// the paramName will be used instead (default is NULL).
547 /// \return Zero if the object could be found and is valid. Otherwise an
548 /// error code, which is compatible with the HLT framework, is returned.
550 if (pathToEntry == NULL) pathToEntry = "(unknown)";
551 if (prettyName == NULL) prettyName = paramName;
554 int result = GetValueFromTMap(map, paramName, valueStr, pathToEntry, prettyName);
555 if (result != 0) return result;
557 if (not valueStr.IsFloat())
559 HLTError("The %s parameter found in configuration object \"%s\""
560 "is not a valid floating point number string; found \"%s\".",
561 prettyName, pathToEntry, valueStr.Data()
565 Double_t val = valueStr.Atof();
568 HLTError("The %s parameter found in configuration object \"%s\""
569 "is not a positive floating point number; found \"%d\".",
570 prettyName, pathToEntry, val
580 int AliHLTMUONProcessor::LoadRecoParamsFromCDB(AliMUONRecoParam*& params) const
582 /// Fetches the reconstruction parameters object from the CDB for MUON.
583 /// [out] \param params This will be filled with the reconstruction
584 /// parameters object found if a successful status code is returned.
585 /// Otherwise it will be unchanged.
586 /// \return Zero if the object could be found. Otherwise an error code,
587 /// which is compatible with the HLT framework, is returned.
589 assert(AliCDBManager::Instance() != NULL);
591 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
594 HLTError("Could not get the the default storage for the CDB.");
598 const char* pathToEntry = "MUON/Calib/RecoParam";
599 Int_t version = store->GetLatestVersion(pathToEntry, GetRunNo());
600 Int_t subVersion = store->GetLatestSubVersion(pathToEntry, GetRunNo(), version);
601 AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry, GetRunNo(), version, subVersion);
604 HLTError("Could not get the CDB entry for \"%s\".", pathToEntry);
608 TObject* obj = entry->GetObject();
611 HLTError("Reconstruction parameters object for \"%s\" is missing.", pathToEntry);
615 TObjArray* objarr = dynamic_cast<TObjArray*>(obj);
618 obj = objarr->Last();
621 AliMUONRecoParam* par = dynamic_cast<AliMUONRecoParam*>(obj);
624 HLTError("No AliMUONRecoParam class found for entry \"%s\". Found a %s class instead.",
625 pathToEntry, obj->ClassName()
635 void AliHLTMUONProcessor::DumpBuffer(
636 const void* buffer, AliHLTUInt32_t size, const char* filename
639 /// Dumps the data contained in a buffer to file as is.
643 fstream file(filename, fstream::out | fstream::trunc | fstream::binary);
646 file.write(reinterpret_cast<const char*>(buffer), size);
649 HLTError("Could not write data block to file %s during"
650 " dumping operation!",
657 HLTError("Could not open file %s for dumping data block!", filename);
662 void AliHLTMUONProcessor::DumpBlock(
663 const AliHLTComponentBlockData* block, const char* fileNamePrefix
666 /// Dumps the data block and meta information to file.
668 std::string filename = fDumpPath;
669 filename += fileNamePrefix;
670 filename += "-blockmeta.bin";
671 DumpBuffer(block, sizeof(AliHLTComponentBlockData), filename.c_str());
672 filename = fDumpPath;
673 filename += fileNamePrefix;
674 filename += "-data.bin";
675 DumpBuffer(block->fPtr, block->fSize, filename.c_str());
679 void AliHLTMUONProcessor::DumpEvent(
680 const AliHLTComponentEventData& evtData,
681 const AliHLTComponentBlockData* blocks,
682 AliHLTComponentTriggerData& trigData,
683 AliHLTUInt8_t* outputPtr,
684 AliHLTUInt32_t& size,
685 AliHLTComponentBlockDataList& outputBlocks
688 /// Dumps the event information to files in the dump path given by the
689 /// method DumpPath, which can be set by the command line argument -dumppath.
694 std::string filename = fDumpPath;
695 sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID);
697 fstream logfile(filename.c_str(), fstream::out | fstream::trunc);
700 HLTError("Could not open log file '%s' for dump information.", filename.c_str());
704 filename = fDumpPath;
705 sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID);
707 logfile << "Dumping event data structure to file: " << filename << std::endl;
708 DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str());
710 filename = fDumpPath;
711 sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID);
713 logfile << "Dumping trigger data structure to file: " << filename << std::endl;
714 DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str());
716 for (unsigned int n = 0; n < evtData.fBlockCnt; n++)
718 sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, n);
720 sprintf(strbuf, "0x%8.8X", blocks[n].fSpecification);
721 logfile << "Found block with data type = " << DataType2Text(blocks[n].fDataType)
722 << ", specification = " << strbuf << ". Dumping to file: "
723 << filename << "-data.bin" << std::endl;
724 DumpBlock(&blocks[n], filename.c_str());
727 filename = fDumpPath;
728 sprintf(strbuf, "dump_event-0x%16.16llX-output-buffer.bin", evtData.fEventID);
730 logfile << "Dumping output buffer to file: " << filename << std::endl;
731 DumpBuffer(outputPtr, size, filename.c_str());
733 for (size_t i = 0; i < outputBlocks.size(); i++)
735 sprintf(strbuf, "dump_event-0x%16.16llX-output-block-0x%8.8X", evtData.fEventID, int(i));
737 sprintf(strbuf, "0x%8.8X", outputBlocks[i].fSpecification);
738 logfile << "Generated output data block with type = "
739 << DataType2Text(outputBlocks[i].fDataType)
740 << ", specification = " << strbuf << ". Dumping to file: "
741 << filename << "-data.bin" << std::endl;
742 DumpBlock(&outputBlocks[i], filename.c_str());
747 void AliHLTMUONProcessor::DumpEvent(
748 const AliHLTComponentEventData& evtData,
749 AliHLTComponentTriggerData& trigData
752 /// Dumps the event information to files in the dump path given by the
753 /// method DumpPath, which can be set by the command line argument -dumppath.
758 std::string filename = fDumpPath;
759 sprintf(strbuf, "dump_event-0x%16.16llX.log", evtData.fEventID);
761 fstream logfile(filename.c_str(), fstream::out | fstream::trunc);
764 HLTError("Could not open log file '%s' for dump information.", filename.c_str());
768 filename = fDumpPath;
769 sprintf(strbuf, "dump_event-0x%16.16llX-eventdata.bin", evtData.fEventID);
771 logfile << "Dumping event data structure to file: " << filename << std::endl;
772 DumpBuffer(&evtData, sizeof(AliHLTComponentEventData), filename.c_str());
774 filename = fDumpPath;
775 sprintf(strbuf, "dump_event-0x%16.16llX-triggerdata.bin", evtData.fEventID);
777 logfile << "Dumping trigger data structure to file: " << filename << std::endl;
778 DumpBuffer(&trigData, sizeof(AliHLTComponentTriggerData), filename.c_str());
780 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
782 const AliHLTComponentBlockData* block = GetInputBlock(i);
783 sprintf(strbuf, "dump_event-0x%16.16llX-block-0x%8.8X", evtData.fEventID, i);
785 sprintf(strbuf, "0x%8.8X", block->fSpecification);
786 logfile << "Found block with data type = " << DataType2Text(block->fDataType)
787 << ", specification = " << strbuf << ". Dumping to file: "
788 << filename << "-data.bin" << std::endl;
789 DumpBlock(block, filename.c_str());