forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSamplingConditionCustom.cxx
More file actions
86 lines (70 loc) · 2.88 KB
/
DataSamplingConditionCustom.cxx
File metadata and controls
86 lines (70 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file DataSamplingConditionCustom.cxx
/// \brief Implementation of DataSamplingConditionCustom
///
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
#include "Framework/DataSamplingCondition.h"
#include "Framework/DataSamplingConditionFactory.h"
#include "Headers/DataHeader.h"
#include <fairlogger/Logger.h>
#include <TClass.h>
#include <TROOT.h>
#include <TSystem.h>
namespace o2
{
namespace framework
{
/// \brief A DataSamplingCondition which makes decisions based on payload size.
class DataSamplingConditionCustom : public DataSamplingCondition
{
public:
/// \brief Constructor.
DataSamplingConditionCustom() : DataSamplingCondition(){};
/// \brief Default destructor
~DataSamplingConditionCustom() override = default;
/// \brief Instantiates and configures a custom condition based on configuration.
///
/// \param config - it should include 'moduleName', full 'className' with namespaces. Optionally it can contain
/// custom parameters for the loaded condition.
void configure(const boost::property_tree::ptree& config) override
{
std::string libraryName = "lib" + config.get<std::string>("moduleName");
std::string className = config.get<std::string>("className");
int libLoaded = gSystem->Load(libraryName.c_str(), "", true);
if (libLoaded < 0) {
throw std::runtime_error("Failed to load the library: " + libraryName);
}
// it does not seem to be documented anywhere, but this pointer to
// a dictionary should not be deleted - it results in segfaults.
TClass* dictionary = TClass::GetClass(className.c_str());
if (!dictionary) {
throw std::runtime_error("Failed to load the dictionary of the class: " + className + " from the library: " + libraryName);
}
mCondition.reset(static_cast<DataSamplingCondition*>(dictionary->New()));
if (mCondition == nullptr) {
throw std::runtime_error("Failed to instantiate the class: " + className + " from the library: " + libraryName);
}
mCondition->configure(config);
}
/// \brief Invokes decide() of a custom condition
bool decide(const o2::framework::DataRef& dataRef) override
{
return mCondition->decide(dataRef);
}
private:
std::unique_ptr<DataSamplingCondition> mCondition;
};
std::unique_ptr<DataSamplingCondition> DataSamplingConditionFactory::createDataSamplingConditionCustom()
{
return std::make_unique<DataSamplingConditionCustom>();
}
} // namespace framework
} // namespace o2