susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
in_json_2012.cpp
Go to the documentation of this file.
1 #include "in_json_2012.hpp"
2 
3 //root function to filter cfA using JSON File.
4 //Usage: #include "/afs/cern.ch/user/w/wto/public/scripts/inJSON2012.h"
5 //Create Vector of Run and Lumi by calling vector< vector<int> > VRunLumi = MakeVRunLumi("Golden") before the event loop.
6 //You can print of a list of Lumiblock by calling CheckVRunLumi(VRunLumi);
7 //Check if your run is inJSON by calling bool inJSON(VRunLumi,run,lumiblock) in the event loop..
8 // 13Jul files contain most of 2012 A and B runs, while 06Aug files contain
9 // five runs only (namely 190782-190949) which suffered from data corruption
10 // (different conditions needed for those runs, the corresponding lumi is 82/pb.)
11 
12 #include <iostream>
13 #include <fstream>
14 #include <string>
15 #include <vector>
16 
17 //using namespace std;
18 std::vector< std::vector<int> > MakeVRunLumi(std::string input){
19  std::ifstream orgJSON;
20  if(input == "Golden" || input == "Prompt"){
21  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Prompt/Cert_190456-208686_8TeV_PromptReco_Collisions12_JSON.txt");
22  }
23  else if(input == "13Jul" || input == "Jul13"){
24  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Reprocessing/Cert_190456-196531_8TeV_13Jul2012ReReco_Collisions12_JSON_v2.txt");
25  }
26  else if(input == "06Aug" || input == "Aug06" || input == "Aug6"){
27  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Reprocessing/Cert_190782-190949_8TeV_06Aug2012ReReco_Collisions12_JSON.txt");
28  }
29  else if(input == "24Aug" || input == "Aug24"){
30  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Reprocessing/Cert_198022-198523_8TeV_24Aug2012ReReco_Collisions12_JSON.txt");
31  }
32  else if(input == "MuonPhys" || input == "Muon"){
33  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Prompt/Cert_190456-204567_8TeV_PromptReco_Collisions12_JSON_MuonPhys.txt");
34  }
35  else if(input == "DCS" || input == "DCSOnly"){
36  orgJSON.open("/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/DCSOnly/json_DCSONLY.txt");
37  }
38  else if(input == "2015golden"){
39  orgJSON.open("txt/json/Cert_246908-256869_13TeV_PromptReco_Collisions15_25ns.json"); //Run C
40  }
41  else if(input == "2015dcs"){
42  // orgJSON.open("txt/json/dcs_DCSONLY_Run2015B_15_07_24.json");
43  orgJSON.open("txt/json/dcs_DCSONLY_15_09_25.json");
44  }
45  else{
46  orgJSON.open(input.c_str());
47  }
48  std::vector<int> VRunLumi;
49  if(orgJSON.is_open()){
50  char inChar;
51  int inInt;
52  std::string str;
53  while(!orgJSON.eof()){
54  char next = orgJSON.peek();
55  if( next == '1' || next == '2' || next == '3' ||
56  next == '4' || next == '5' || next == '6' ||
57  next == '7' || next == '8' || next == '9' ||
58  next == '0'){
59  orgJSON >>inInt;
60  VRunLumi.push_back(inInt);
61  }
62  else if(next == ' '){
63  getline(orgJSON,str,' ');
64  }
65  else{
66  orgJSON>>inChar;
67  }
68  }
69  }//check if the file opened.
70  else{
71  std::cout<<"Invalid JSON File!\n";
72  }
73  orgJSON.close();
74  if(VRunLumi.size() == 0){
75  std::cout<<"No Lumiblock found in JSON file\n";
76  }
77  std::vector< std::vector<int> > VVRunLumi;
78  for(unsigned int i = 0; i+2 < VRunLumi.size();){
79  if(VRunLumi[i] > 130000){
80  std::vector<int> RunLumi;
81  RunLumi.push_back(VRunLumi[i]);
82  while(VRunLumi[i+1] < 130000 && i+1 < VRunLumi.size()){
83  RunLumi.push_back(VRunLumi[i+1]);
84  ++i;
85  }
86  VVRunLumi.push_back(RunLumi);
87  ++i;
88  }
89  }
90  return VVRunLumi;
91 }
92 
93 bool inJSON(std::vector< std::vector<int> > VVRunLumi, int Run, int LS){
94  bool answer = false;
95  if(Run < 120000){
96  answer = true;
97  }
98  else{
99  for(unsigned int i = 0; i < VVRunLumi.size();++i){
100  if(Run == VVRunLumi[i][0]){
101  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
102  if(LS >= VVRunLumi[i][j] && LS <= VVRunLumi[i][j+1]){
103  answer = true;
104  }
105  }
106  }
107  }
108  }
109  return answer;
110 }
111 
112 void CheckVRunLumi(std::vector< std::vector<int> > VVRunLumi){
113  for(unsigned int i = 0; i < VVRunLumi.size();++i){
114  std::cout<<"Run:"<<VVRunLumi[i][0]<<" LS: ";
115  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
116  std::cout<<VVRunLumi[i][j]<<"-"<<VVRunLumi[i][j+1]<<" ";
117  }
118  std::cout<<std::endl;
119  }
120 }
121 
122 void CheckVRunLumi2(std::vector< std::vector<int> > VVRunLumi){
123  for(unsigned int i = 0; i < VVRunLumi.size();++i){
124  for(unsigned int j = 1; j+1 < VVRunLumi[i].size();j=j+2){
125  if(VVRunLumi[i][j] == VVRunLumi[i][j+1]){
126  std::cout<<VVRunLumi[i][0]<<" "<<VVRunLumi[i][j]<<std::endl;
127  }
128  else{
129  for(int k=VVRunLumi[i][j];k<=VVRunLumi[i][j+1];++k){
130  std::cout<<VVRunLumi[i][0]<<" "<<k<<std::endl;
131  }
132  }
133  }
134  std::cout<<std::endl;
135  }
136 }
std::vector< std::vector< int > > MakeVRunLumi(std::string input)
void CheckVRunLumi2(std::vector< std::vector< int > > VVRunLumi)
bool inJSON(std::vector< std::vector< int > > VVRunLumi, int Run, int LS)
void CheckVRunLumi(std::vector< std::vector< int > > VVRunLumi)