FindNewDQRunsND.C
Go to the documentation of this file.
1 #include <map>
2 //#include <stdio>
3 #include <iostream> // std::cout
4 #include <string>
5 #include <algorithm>
6 #include <vector>
7 #include <set>
8 
9 void FindNewDQRunsND(string filename="databasecopyND.csv", string filename2="tables/DQValidityTableND.csv"){
10 
11  ofstream outdb;
12  outdb.open("dqvaliditynewND.csv");
13 
14  ifstream alldb(filename.c_str());
15  ifstream allgr(filename2.c_str());
16 
17  vector<string> flag_db;
18  vector<string> comment_db;
19  vector<string> nevents_db;
20  vector<string> emptyspillfract_db;
21  vector<string> miprate_db;
22  vector<string> ngoodcdb_db;
23  vector<string> numslc_db;
24  vector<string> trkfrac_db;
25  vector<string> timingpeakstart_db;
26  vector<string> timingpeakend_db;
27  vector<string> firstsec_db;
28  vector<string> lastsec_db;
29  vector<string> beam_db;
30  vector<string> channel_db;
31 
32  vector<string> flag_gr;
33  vector<string> comment_gr;
34  vector<string> nevents_gr;
35  vector<string> emptyspillfract_gr;
36  vector<string> miprate_gr;
37  vector<string> ngoodcdb_gr;
38  vector<string> numslc_gr;
39  vector<string> trkfrac_gr;
40  vector<string> timingpeakstart_gr;
41  vector<string> timingpeakend_gr;
42  vector<string> firstsec_gr;
43  vector<string> lastsec_gr;
44  vector<string> beam_gr;
45  vector<string> channel_gr;
46 
47  set<string> setdbruns;
48 
49  map<int, int> runflagmap;
50 
51  string line_db;
52  string line_gr;
53 
54  while ( getline(alldb, line_db) ){
55  stringstream strdb(line_db);
56  string field_db;
57 
58  getline(strdb, field_db,',');
59  flag_db.push_back(field_db);
60 
61  getline(strdb, field_db,',');
62  comment_db.push_back(field_db);
63 
64  getline(strdb, field_db,',');
65  nevents_db.push_back(field_db);
66 
67  getline(strdb, field_db,',');
68  emptyspillfract_db.push_back(field_db);
69 
70  getline(strdb, field_db,',');
71  miprate_db.push_back(field_db);
72 
73  getline(strdb, field_db,',');
74  ngoodcdb_db.push_back(field_db);
75 
76  getline(strdb, field_db,',');
77  numslc_db.push_back(field_db);
78 
79  getline(strdb, field_db,',');
80  trkfrac_db.push_back(field_db);
81 
82  getline(strdb, field_db,',');
83  timingpeakstart_db.push_back(field_db);
84 
85  getline(strdb, field_db,',');
86  timingpeakend_db.push_back(field_db);
87 
88  getline(strdb, field_db,',');
89  firstsec_db.push_back(field_db);
90 
91  getline(strdb, field_db,',');
92  //std::cout << "db last sec" << field_db << std::endl;
93  lastsec_db.push_back(field_db);
94 
95  getline(strdb, field_db,',');
96  //std::cout << "beam?: " << field_db << std::endl;
97  beam_db.push_back(field_db);
98 
99  //getline(strdb, field_db,',');
100  getline(strdb, field_db,',');
101  //std::cout << "channeldb: " << field_db << std::endl;
102  channel_db.push_back(field_db);
103  }
104 
105  while ( getline(allgr, line_gr) ){
106  stringstream strgr(line_gr);
107  string field_gr;
108 
109  getline(strgr, field_gr,',');
110  flag_gr.push_back(field_gr);
111 
112  getline(strgr, field_gr,',');
113  comment_gr.push_back(field_gr);
114 
115  getline(strgr, field_gr,',');
116  nevents_gr.push_back(field_gr);
117 
118  getline(strgr, field_gr,',');
119  emptyspillfract_gr.push_back(field_gr);
120 
121  getline(strgr, field_gr,',');
122  miprate_gr.push_back(field_gr);
123 
124  getline(strgr, field_gr,',');
125  ngoodcdb_gr.push_back(field_gr);
126 
127  getline(strgr, field_gr,',');
128  numslc_gr.push_back(field_gr);
129 
130  getline(strgr, field_gr,',');
131  trkfrac_gr.push_back(field_gr);
132 
133  getline(strgr, field_gr,',');
134  timingpeakstart_gr.push_back(field_gr);
135 
136  getline(strgr, field_gr,',');
137  timingpeakend_gr.push_back(field_gr);
138 
139  getline(strgr, field_gr,',');
140  firstsec_gr.push_back(field_gr);
141 
142  getline(strgr, field_gr,',');
143  lastsec_gr.push_back(field_gr);
144 
145  getline(strgr, field_gr,',');
146  beam_gr.push_back(field_gr);
147 
148  getline(strgr, field_gr,',');
149  getline(strgr, field_gr,',');
150  channel_gr.push_back(field_gr);
151  }
152 
153  outdb << "flag,comment,nevents,emptyspillfract,miprate,ngoodcdb,numslc,trkfrac,timingpeakstart,timingpeakend,firstsec,lastsec,beam,tv,channel" << endl;
154  bool samechannel, changedchannel;
155 
156  string lastchannel="0";
157 
158  for(int j=0; j<channel_db.size(); j++){
159  runflagmap[atoi(channel_db[j].c_str())] = atoi(flag_db[j].c_str());
160  if(atoi(channel_db[j].c_str()) > atoi(lastchannel.c_str()))
161  lastchannel = channel_db[j];
162  }
163 
164  //for(int i=0; channel_gr.size(); i++){
165 
166  //std::cout << channel_gr[i] <<"," <<flag_gr[i] <<"," << comment_gr[i]<<"," << nevents_gr[i]<<"," << emptyspillfract_gr[i]<<","<< miprate_gr[i]<<","<<ngoodcdb_gr[i]<<"," << numslc_gr[i]<<"," << trkfrac_gr[i]<<"," <<timingpeakstart_gr[i]<<","<<timingpeakend_gr[i]<<","<<firstsec_gr[i]<<","<<lastsec_gr[i]<<","<<beam_gr[i] << std::endl;
167  //}
168 
169  std::cout << "Last Uploaded Run/Subrun: " << lastchannel << std::endl;
170  for(int i=1; i<channel_gr.size(); i++){
171  samechannel = false;
172  changedchannel = false;
173  if(atoi(channel_gr[i].c_str()) <= atoi(lastchannel.c_str()))
174  samechannel=true;
175  if( samechannel == false ){
176  std::cout << "New subrun found! Adding subrun " << channel_gr[i] << " to database..." << endl;
177  outdb << flag_gr[i] <<"," << comment_gr[i]<<"," << nevents_gr[i]<<"," << emptyspillfract_gr[i]<<","<< miprate_gr[i]<<","<<ngoodcdb_gr[i]<<"," << numslc_gr[i]<<"," << trkfrac_gr[i]<<"," <<timingpeakstart_gr[i]<<","<<timingpeakend_gr[i]<<","<<firstsec_gr[i]<<","<<lastsec_gr[i]<<","<<beam_gr[i]<<","<< channel_gr[i]<<",0" <<std::endl;
178  }
179  }
180 
181 }
string filename
Definition: shutoffs.py:106
void FindNewDQRunsND(string filename="databasecopyND.csv", string filename2="tables/DQValidityTableND.csv")
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6