ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataCont/src/RunLumiRangeMap.cc
Revision: 1.2
Committed: Tue Jun 29 15:51:53 2010 UTC (14 years, 10 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, HEAD
Branch point for: Mit_025c_branch
Changes since 1.1: +38 -11 lines
Log Message:
Add machinery for processed lumi json files

File Contents

# User Rev Content
1 bendavid 1.2 // $Id: RunLumiRangeMap.cc,v 1.1 2010/05/29 18:10:14 bendavid Exp $
2 bendavid 1.1
3     #include "MitAna/DataCont/interface/RunLumiRangeMap.h"
4     #include <boost/property_tree/ptree.hpp>
5     #include <boost/property_tree/json_parser.hpp>
6     #include <boost/lexical_cast.hpp>
7 bendavid 1.2 #include "MitCommon/JSONSpirit/src/json_spirit.h"
8 bendavid 1.1 #include <TClass.h>
9    
10     ClassImp(mithep::RunLumiRangeMap)
11    
12     //--------------------------------------------------------------------------------------------------
13     Bool_t mithep::RunLumiRangeMap::HasRunLumi(const RunLumiPairType &runLumi) const
14     {
15     // Check if a given run,lumi pair is included in the mapped lumi ranges
16    
17     //check if run is included in the map
18     MapType::const_iterator it = fMap.find(runLumi.first);
19     if (it!=fMap.end()) {
20     //check lumis
21     const MapType::mapped_type &lumiPairList = it->second;
22     for (MapType::mapped_type::const_iterator jt = lumiPairList.begin(); jt<lumiPairList.end(); ++jt) {
23     if (runLumi.second >= jt->first && runLumi.second <= jt->second) {
24     //found lumi in accepted range
25     return kTRUE;
26     }
27     }
28     }
29    
30     return kFALSE;
31    
32     }
33    
34     //--------------------------------------------------------------------------------------------------
35     void mithep::RunLumiRangeMap::AddJSONFile(const std::string &filepath)
36     {
37    
38     //read json file into boost property tree
39     boost::property_tree::ptree jsonTree;
40     boost::property_tree::read_json(filepath,jsonTree);
41    
42     //loop through boost property tree and fill the MapType structure with the list of good lumi
43     //ranges for each run
44     for (boost::property_tree::ptree::const_iterator it = jsonTree.begin(); it!=jsonTree.end(); ++it) {
45     UInt_t runNumber = boost::lexical_cast<UInt_t>(it->first);
46     MapType::mapped_type &lumiPairList = fMap[runNumber];
47     boost::property_tree::ptree lumiPairListTree = it->second;
48     for (boost::property_tree::ptree::const_iterator jt = lumiPairListTree.begin(); jt!=lumiPairListTree.end(); ++jt) {
49     boost::property_tree::ptree lumiPairTree = jt->second;
50     if (lumiPairTree.size()==2) {
51     UInt_t firstLumi = boost::lexical_cast<UInt_t>(lumiPairTree.begin()->second.data());
52     UInt_t lastLumi = boost::lexical_cast<UInt_t>((++lumiPairTree.begin())->second.data());
53     lumiPairList.push_back(std::pair<UInt_t,UInt_t>(firstLumi,lastLumi));
54     }
55     }
56     }
57    
58     //dump run and lumi ranges from MapType structure to verify correct json parsing
59     if (0) {
60     printf("Iterating over parsed JSON:\n");
61     for (MapType::const_iterator it = fMap.begin(); it != fMap.end(); ++it) {
62     printf(" Run %u:\n",it->first);
63     for (MapType::mapped_type::const_iterator jt = it->second.begin(); jt < it->second.end(); ++jt) {
64     printf(" Lumis %u - %u\n",jt->first,jt->second);
65     }
66     }
67    
68     }
69    
70     }
71    
72     //--------------------------------------------------------------------------------------------------
73     void mithep::RunLumiRangeMap::DumpJSONFile(const std::string &filepath)
74     {
75    
76 bendavid 1.2 json_spirit::Object jsonTree;
77 bendavid 1.1
78     for (MapType::const_iterator it = fMap.begin(); it!=fMap.end(); ++it) {
79     UInt_t runnum = it->first;
80 bendavid 1.2 json_spirit::Array lumiPairListArray;
81 bendavid 1.1 const MapType::mapped_type &lumiPairList = it->second;
82     for (MapType::mapped_type::const_iterator jt = lumiPairList.begin(); jt<lumiPairList.end(); ++jt) {
83 bendavid 1.2 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     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 bendavid 1.1 }
117 bendavid 1.2
118 bendavid 1.1 }
119     }