ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataCont/src/RunLumiRangeMap.cc
Revision: 1.1
Committed: Sat May 29 18:10:14 2010 UTC (14 years, 11 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_014b, Mit_014a, Mit_014
Log Message:
Refactor lumi selection code a bit

File Contents

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