forked from UCATLAS/xAODAnaHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm.cxx
108 lines (88 loc) · 2.81 KB
/
Algorithm.cxx
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <xAODAnaHelpers/Algorithm.h>
// RCU include for throwing an exception+message
#include <RootCoreUtils/ThrowMsg.h>
// for isMC()
#include <xAODAnaHelpers/HelperFunctions.h>
#include "xAODEventInfo/EventInfo.h"
std::map<std::string, int> xAH::Algorithm::m_instanceRegistry = {};
// this is needed to distribute the algorithm to the workers
ClassImp(xAH::Algorithm)
xAH::Algorithm::Algorithm(std::string className) :
m_name(""),
m_debug(false),
m_verbose(false),
m_systName(""),
m_systVal(0),
m_eventInfoContainerName("EventInfo"),
m_isMC(-1),
m_event(nullptr),
m_store(nullptr),
m_className(className)
{
}
xAH::Algorithm::~Algorithm()
{
}
StatusCode xAH::Algorithm::algInitialize(){
registerInstance();
return StatusCode::SUCCESS;
}
StatusCode xAH::Algorithm::algFinalize(){
unregisterInstance();
return StatusCode::SUCCESS;
}
xAH::Algorithm* xAH::Algorithm::setName(std::string name){
m_name = name;
// call the TNamed
this->SetName(name.c_str());
return this;
}
xAH::Algorithm* xAH::Algorithm::setLevel(int level){
m_debug = level & 1;
m_verbose = (level >> 1)&1;
return this;
}
StatusCode xAH::Algorithm::parseSystValVector(){
std::stringstream ss(m_systValVectorString);
float systVal;
while( ss >> systVal ){
m_systValVector.push_back(systVal);
if (ss.peek() == ',')
ss.ignore();
}
ss.str("");
return StatusCode::SUCCESS;
}
int xAH::Algorithm::isMC(){
// first override if need to
if(m_isMC == 0 || m_isMC == 1) return m_isMC;
const xAOD::EventInfo* ei(nullptr);
// couldn't retrieve it
if(!HelperFunctions::retrieve(ei, m_eventInfoContainerName, m_event, m_store).isSuccess()){
if(m_debug) Warning("isMC()", "Could not retrieve eventInfo container: %s", m_eventInfoContainerName.c_str());
return -1;
}
static SG::AuxElement::ConstAccessor<uint32_t> eventType("eventTypeBitmask");
if(!eventType.isAvailable(*ei)){
if(m_debug) Warning("isMC()", "eventType is not available.");
return -1;
}
// reached here, return 0 or 1 since we have all we need
return (static_cast<uint32_t>(eventType(*ei)) & xAOD::EventInfo::IS_SIMULATION);
}
void xAH::Algorithm::registerInstance(){
m_instanceRegistry[m_className]++;
}
int xAH::Algorithm::numInstances(){
if(m_instanceRegistry.find(m_className) == m_instanceRegistry.end()){
printf("numInstances: we seem to have recorded zero instances of %s. This should not happen.", m_className.c_str());
return 0;
}
return m_instanceRegistry.at(m_className);
}
void xAH::Algorithm::unregisterInstance(){
if(m_instanceRegistry.find(m_className) == m_instanceRegistry.end()){
printf("unregisterInstance: we seem to have recorded zero instances of %s. This should not happen.", m_className.c_str());
}
m_instanceRegistry[m_className]--;
}