-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContext.cxx
130 lines (110 loc) · 2.61 KB
/
Context.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Helper routines for handling the per-thread analysis context
#include "Context.h"
#include "Detector.h"
#include "Variable.h"
#include "Util.h"
#include <iostream>
#include <fstream>
#include <boost/algorithm/string/trim.hpp>
using namespace std;
using namespace boost::algorithm;
Context::Context( int _id )
: id(_id), is_init(false), is_active(false)
{
variables = make_shared<varlst_t>();
}
Context::Context( const Context& )
: is_init(false), is_active(false)
{
}
Context::~Context()
{
assert( !is_active );
}
int Context::Init()
{
// Initialize current context
// Initialize detectors
int err = 0;
for( auto& det : detectors ) {
// Link each of our detectors to our variable list
det->SetVarList(variables);
// Init(shared = false) calls DefineVariables of the Detector
if( int status = det->Init(false); status != 0 ) {
err = status;
cerr << "Error initializing detector " << det->GetName() << endl;
}
}
if( err )
return 1;
// Read output definitions & configure output
outvars.push_back( make_unique<EventNumberVariable>(nev) );
string ofname = cfg.odef_file;
if( ofname.empty() )
return 2;
ifstream inp(ofname);
if( !inp ) {
cerr << "Error opening output definition file " << ofname << endl;
return 2;
}
string line;
while( getline(inp,line) ) {
// Wildcard match variable names, ignoring trailing comments
if( string::size_type pos = line.find('#'); pos != string::npos )
line.erase(pos);
trim(line);
if( line.empty() )
continue;
for( auto& var : *variables ) {
if( WildcardMatch(var->GetName(), line) )
outvars.push_back( make_unique<PlainVariable>(var.get()) );
}
}
line.clear();
inp.close();
if( outvars.empty() ) {
// Noting to do
cerr << "No output variables defined. Check " << ofname << endl;
return 3;
}
#ifndef PPODD_TBB
if( !evbuffer )
evbuffer = make_unique<evbuf_t[]>(MAX_EVTSIZE);
evbuffer[0] = 0;
#endif
is_init = true;
return 0;
}
#ifdef EVTORDER
int Context::fgNactive = 0;
std::mutex Context::fgMutex;
std::condition_variable Context::fgAllDone;
void Context::MarkActive()
{
is_active = true;
std::lock_guard lock(fgMutex);
++fgNactive;
}
void Context::UnmarkActive()
{
is_active = false;
{
std::lock_guard lock(fgMutex);
--fgNactive;
assert( fgNactive >= 0 );
}
if( fgNactive == 0 )
fgAllDone.notify_one();
}
void Context::WaitAllDone()
{
std::unique_lock lock(fgMutex);
while( fgNactive > 0 )
fgAllDone.wait(lock);
}
bool Context::IsSyncEvent()
{
evdata.Preload( evbuffer.get() );
return evdata.IsSyncEvent();
}
#endif