babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
in_json.cc
Go to the documentation of this file.
1 //in_json: function to filter cfA using JSON File.
2 //Create Vector of Run and Lumi by calling vector< vector<int> > VRunLumi = MakeVRunLumi("Golden") before the event loop.
3 //You can print of a list of Lumiblock by calling CheckVRunLumi(VRunLumi);
4 //Check if your run is inJSON by calling bool inJSON(VRunLumi,run,lumiblock) in the event loop..
5 
6 #include <iostream>
7 #include <fstream>
8 #include <string>
9 #include <vector>
12 
13 using namespace std;
14 using namespace utilities;
15 
16 std::vector< std::vector<int> > MakeVRunLumi(std::string input){
17  std::ifstream orgJSON;
18  std::string command("printf ${CMSSW_BASE}/src/babymaker/data/");
19  std::string fullpath = execute(command.c_str());
20  if(input == "golden"){
21  fullpath += "json/golden_Cert_246908-258714_13TeV_PromptReco_Collisions15_25ns_JSON.json";
22  } else if(input == "nonblind"){
23  fullpath += "json/golden_Cert_271036-274240_13TeV_PromptReco_Collisions16_JSON.json";
24  } else if(input == "json2p6"){
25  fullpath += "json/golden_Cert_271036-274443_13TeV_PromptReco_Collisions16.json";
26  } else{
27  fullpath = input;
28  }
29  orgJSON.open(fullpath.c_str());
30  std::vector<int> VRunLumi;
31  if(orgJSON.is_open()){
32  char inChar;
33  int inInt;
34  std::string str;
35  while(!orgJSON.eof()){
36  char next = orgJSON.peek();
37  if( next == '1' || next == '2' || next == '3' ||
38  next == '4' || next == '5' || next == '6' ||
39  next == '7' || next == '8' || next == '9' ||
40  next == '0'){
41  orgJSON >>inInt;
42  VRunLumi.push_back(inInt);
43  }
44  else if(next == ' '){
45  getline(orgJSON,str,' ');
46  }
47  else{
48  orgJSON>>inChar;
49  }
50  }
51  }//check if the file opened.
52  else{
53  std::cout<<"Invalid JSON File:"<<fullpath<<"!\n";
54  }
55  orgJSON.close();
56  if(VRunLumi.size() == 0){
57  std::cout<<"No Lumiblock found in JSON file\n";
58  }
59  std::vector< std::vector<int> > VVRunLumi;
60  for(unsigned int i = 0; i+2 < VRunLumi.size();){
61  if(VRunLumi[i] > 130000){
62  std::vector<int> RunLumi;
63  RunLumi.push_back(VRunLumi[i]);
64  while(VRunLumi[i+1] < 130000 && i+1 < VRunLumi.size()){
65  RunLumi.push_back(VRunLumi[i+1]);
66  ++i;
67  }
68  VVRunLumi.push_back(RunLumi);
69  ++i;
70  }
71  }
72  return VVRunLumi;
73 }
74 
75 bool inJSON(std::vector< std::vector<int> > VVRunLumi, int Run, int LS){
76  bool answer = false;
77  if(Run < 120000){
78  answer = true;
79  }
80  else{
81  for(unsigned int i = 0; i < VVRunLumi.size();++i){
82  if(Run == VVRunLumi[i][0]){
83  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
84  if(LS >= VVRunLumi[i][j] && LS <= VVRunLumi[i][j+1]){
85  answer = true;
86  }
87  }
88  }
89  }
90  }
91  return answer;
92 }
93 
94 void CheckVRunLumi(std::vector< std::vector<int> > VVRunLumi){
95  for(unsigned int i = 0; i < VVRunLumi.size();++i){
96  std::cout<<"Run:"<<VVRunLumi[i][0]<<" LS: ";
97  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
98  std::cout<<VVRunLumi[i][j]<<"-"<<VVRunLumi[i][j+1]<<" ";
99  }
100  std::cout<<std::endl;
101  }
102 }
103 
104 void CheckVRunLumi2(std::vector< std::vector<int> > VVRunLumi){
105  for(unsigned int i = 0; i < VVRunLumi.size();++i){
106  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
107  if(VVRunLumi[i][j] == VVRunLumi[i][j+1]){
108  std::cout<<VVRunLumi[i][0]<<" "<<VVRunLumi[i][j]<<std::endl;
109  }
110  else{
111  for(int k=VVRunLumi[i][j];k<=VVRunLumi[i][j+1];++k){
112  std::cout<<VVRunLumi[i][0]<<" "<<k<<std::endl;
113  }
114  }
115  }
116  std::cout<<std::endl;
117  }
118 }
void CheckVRunLumi(std::vector< std::vector< int > > VVRunLumi)
Definition: in_json.cc:94
std::vector< std::vector< int > > MakeVRunLumi(std::string input)
Definition: in_json.cc:16
void CheckVRunLumi2(std::vector< std::vector< int > > VVRunLumi)
Definition: in_json.cc:104
STL namespace.
bool inJSON(std::vector< std::vector< int > > VVRunLumi, int Run, int LS)
Definition: in_json.cc:75
std::string execute(const std::string &cmd)