|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | +// |
| 11 | + |
| 12 | +/// |
| 13 | +/// \author Piotr Konopka |
| 14 | +/// \file RootClassFactory.h |
| 15 | +/// |
| 16 | +#ifndef QUALITYCONTROL_ROOTCLASSFACTORY_H |
| 17 | +#define QUALITYCONTROL_ROOTCLASSFACTORY_H |
| 18 | + |
| 19 | +#include <string> |
| 20 | +// O2 |
| 21 | +#include <Common/Exceptions.h> |
| 22 | +// ROOT |
| 23 | +#include <TClass.h> |
| 24 | +#include <TROOT.h> |
| 25 | +#include <TSystem.h> |
| 26 | +// Boost |
| 27 | +#include <boost/filesystem/path.hpp> |
| 28 | +// QC |
| 29 | +#include "QualityControl/QcInfoLogger.h" |
| 30 | + |
| 31 | +namespace bfs = boost::filesystem; |
| 32 | + |
| 33 | +namespace o2::quality_control::core |
| 34 | +{ |
| 35 | + |
| 36 | +namespace root_class_factory |
| 37 | +{ |
| 38 | + |
| 39 | +using FatalException = AliceO2::Common::FatalException; |
| 40 | +using errinfo_details = AliceO2::Common::errinfo_details; |
| 41 | + |
| 42 | +template <typename T> |
| 43 | +T* create(std::string moduleName, std::string className) |
| 44 | +{ |
| 45 | + T* result = nullptr; |
| 46 | + QcInfoLogger& logger = QcInfoLogger::GetInstance(); |
| 47 | + |
| 48 | + // Load the library |
| 49 | + std::string library = bfs::path(moduleName).is_absolute() ? moduleName : "lib" + moduleName; |
| 50 | + logger << "Loading library " << library << AliceO2::InfoLogger::InfoLogger::endm; |
| 51 | + int libLoaded = gSystem->Load(library.c_str(), "", true); |
| 52 | + if (libLoaded < 0) { |
| 53 | + BOOST_THROW_EXCEPTION(FatalException() << errinfo_details("Failed to load Detector Publisher Library")); |
| 54 | + } |
| 55 | + |
| 56 | + // Get the class and instantiate |
| 57 | + logger << "Loading class " << className << AliceO2::InfoLogger::InfoLogger::endm; |
| 58 | + TClass* cl = TClass::GetClass(className.c_str()); |
| 59 | + std::string tempString("Failed to instantiate Quality Control Module"); |
| 60 | + if (!cl) { |
| 61 | + tempString += " because no dictionary for class named \""; |
| 62 | + tempString += className; |
| 63 | + tempString += "\" could be retrieved"; |
| 64 | + BOOST_THROW_EXCEPTION(FatalException() << errinfo_details(tempString)); |
| 65 | + } |
| 66 | + logger << "Instantiating class " << className << " (" << cl << ")" |
| 67 | + << AliceO2::InfoLogger::InfoLogger::endm; |
| 68 | + result = static_cast<T*>(cl->New()); |
| 69 | + if (!result) { |
| 70 | + BOOST_THROW_EXCEPTION(FatalException() << errinfo_details(tempString)); |
| 71 | + } |
| 72 | + logger << "QualityControl Module " << moduleName << " loaded " << AliceO2::InfoLogger::InfoLogger::endm; |
| 73 | + |
| 74 | + return result; |
| 75 | +} |
| 76 | + |
| 77 | +} // namespace root_class_factory |
| 78 | + |
| 79 | +} // namespace o2::quality_control::core |
| 80 | + |
| 81 | +#endif //QUALITYCONTROL_ROOTCLASSFACTORY_H |
0 commit comments