4 |
|
#include <boost/property_tree/ptree.hpp> |
5 |
|
#include <boost/property_tree/json_parser.hpp> |
6 |
|
#include <boost/lexical_cast.hpp> |
7 |
+ |
#include "MitCommon/JSONSpirit/src/json_spirit.h" |
8 |
|
#include <TClass.h> |
9 |
|
|
10 |
|
ClassImp(mithep::RunLumiRangeMap) |
73 |
|
void mithep::RunLumiRangeMap::DumpJSONFile(const std::string &filepath) |
74 |
|
{ |
75 |
|
|
76 |
< |
//read json file into boost property tree |
76 |
< |
boost::property_tree::ptree jsonTree; |
76 |
> |
json_spirit::Object jsonTree; |
77 |
|
|
78 |
– |
//loop through map and fill boost property tree |
78 |
|
for (MapType::const_iterator it = fMap.begin(); it!=fMap.end(); ++it) { |
79 |
|
UInt_t runnum = it->first; |
80 |
< |
//jsonTree.put(boost::lexical_cast<string>(runnum)); |
82 |
< |
//check lumis |
80 |
> |
json_spirit::Array lumiPairListArray; |
81 |
|
const MapType::mapped_type &lumiPairList = it->second; |
82 |
|
for (MapType::mapped_type::const_iterator jt = lumiPairList.begin(); jt<lumiPairList.end(); ++jt) { |
83 |
< |
; |
83 |
> |
json_spirit::Array lumiPairArray; |
84 |
> |
lumiPairArray.push_back(int(jt->first)); |
85 |
> |
lumiPairArray.push_back(int(jt->second)); |
86 |
> |
|
87 |
> |
lumiPairListArray.push_back(lumiPairArray); |
88 |
|
} |
89 |
< |
} |
90 |
< |
|
91 |
< |
//write file |
92 |
< |
boost::property_tree::write_json(filepath,jsonTree); |
89 |
> |
json_spirit::Pair runPair(boost::lexical_cast<std::string>(runnum), lumiPairListArray); |
90 |
> |
jsonTree.push_back(runPair); |
91 |
> |
} |
92 |
> |
|
93 |
> |
ofstream os(filepath.c_str()); |
94 |
> |
json_spirit::write(jsonTree,os); |
95 |
> |
|
96 |
> |
} |
97 |
> |
|
98 |
> |
//-------------------------------------------------------------------------------------------------- |
99 |
> |
void mithep::RunLumiRangeMap::FillRunLumiSet(const RunLumiSet &rlSet) |
100 |
> |
{ |
101 |
> |
fMap.clear(); |
102 |
> |
const RunLumiSet::SetType &theset = rlSet.runLumiSet(); |
103 |
> |
|
104 |
> |
UInt_t firstlumi = 0; |
105 |
> |
for (RunLumiSet::SetType::const_iterator it = theset.begin(); it!=theset.end(); ++it) { |
106 |
> |
|
107 |
> |
if (firstlumi==0) firstlumi = it->second; |
108 |
> |
MapType::mapped_type &lumiPairList = fMap[it->first]; |
109 |
|
|
110 |
+ |
RunLumiSet::SetType::const_iterator itnext = it; |
111 |
+ |
++itnext; |
112 |
+ |
|
113 |
+ |
if ( itnext==theset.end() || itnext->first!=it->first || itnext->second!=(it->second+1) ) { |
114 |
+ |
lumiPairList.push_back(std::pair<UInt_t,UInt_t>(firstlumi,it->second)); |
115 |
+ |
firstlumi = 0; |
116 |
+ |
} |
117 |
+ |
|
118 |
+ |
} |
119 |
|
} |