forked from sPHENIX-Collaboration/coresoftware
/
Fun4AllUtils.cc
74 lines (70 loc) · 2.41 KB
/
Fun4AllUtils.cc
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
#include "Fun4AllUtils.h"
#include <boost/tokenizer.hpp>
// this is an ugly hack, the gcc optimizer has a bug which
// triggers the uninitialized variable warning which
// stops compilation because of our -Werror
#include <boost/version.hpp> // to get BOOST_VERSION
#if (__GNUC__ == 4 && __GNUC_MINOR__ == 4 && BOOST_VERSION == 105700)
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma message "ignoring bogus gcc warning in boost header lexical_cast.hpp"
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic warning "-Wuninitialized"
#else
#include <boost/lexical_cast.hpp>
#endif
#include <algorithm> // for max
#include <iostream>
#include <vector>
using namespace std;
// relying on our standard filenames ...-<runnumber>-<segment>.<ext>
// extract run number and segment number from filename
std::pair<int, int>
Fun4AllUtils::GetRunSegment(const std::string& filename)
{
int runnumber = 0;
int segment = -9999;
boost::char_separator<char> sep("-.");
boost::tokenizer<boost::char_separator<char> > tok(filename, sep);
// tokenizer does not have reverse iterator, so fill it in vector
// and reverse iterate on vector
vector<string> tokens;
for (auto& t : tok)
{
tokens.push_back(t);
}
tokens.pop_back(); // remove the file extension
// try to extract segment number
try
{
segment = boost::lexical_cast<int>((*(tokens.rbegin())));
}
catch (boost::bad_lexical_cast const&)
{
cout << "Cannot extract segment number from filename "
<< filename << endl;
cout << "Segment string after parsing: input string "
<< *(tokens.rbegin())
<< " is not valid segment number" << endl;
cout << "filename " << filename << " not standard -runnumber-segment.ext"
<< endl;
cout << "using " << segment << " as segment number" << endl;
}
tokens.pop_back(); // remove the segment number
// try to extract run number
try
{
runnumber = boost::lexical_cast<int>((*(tokens.rbegin())));
}
catch (boost::bad_lexical_cast const&)
{
cout << "Cannot extract run number from filename "
<< filename << endl;
cout << "Segment string after parsing: input string "
<< *(tokens.rbegin())
<< " is not valid run number" << endl;
cout << "filename " << filename << " not standard -runnumber-segment.ext"
<< endl;
cout << "returning " << runnumber << " as run number" << endl;
}
return make_pair(runnumber, segment);
}