FindNewDQRuns.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 
10 void FindNewDQRuns(string filename="testdqcopy.csv", string filename2="tables/DQValidityTable.csv"){
11 
12  ofstream outdb;
13  outdb.open("dqvaliditynew.csv");
14 
15  ifstream alldb(filename.c_str());
16  ifstream allgr(filename2.c_str());
17 
18  vector<string> dbmask_db;
19  vector<string> flag_db;
20  vector<string> comment_db;
21  vector<string> miprate_db;
22  vector<string> ngooddb_db;
23  vector<string> numslc_db;
24  vector<string> trkfrac_db;
25  vector<string> channel_db;
26 
27  vector<string> dbmask_gr;
28  vector<string> flag_gr;
29  vector<string> comment_gr;
30  vector<string> miprate_gr;
31  vector<string> ngooddb_gr;
32  vector<string> numslc_gr;
33  vector<string> trkfrac_gr;
34  vector<string> channel_gr;
35 
36  set<string> setdbruns;
37 
38  map<int, int> runflagmap;
39 
40  string line_db;
41  string line_gr;
42 
43  while ( getline(alldb, line_db) ){
44  stringstream strdb(line_db);
45  string field_db;
46 
47  getline(strdb, field_db,',');
48  dbmask_db.push_back(field_db);
49 
50 
51  getline(strdb, field_db, ',');
52  flag_db.push_back(field_db);
53 
54  getline(strdb, field_db, ',');
55  comment_db.push_back(field_db);
56 
57  getline(strdb, field_db, ',');
58  miprate_db.push_back(field_db);
59 
60  getline(strdb, field_db, ',');
61  ngooddb_db.push_back(field_db);
62 
63  getline(strdb, field_db, ',');
64  numslc_db.push_back(field_db);
65 
66  getline(strdb, field_db, ',');
67  trkfrac_db.push_back(field_db);
68 
69  getline(strdb, field_db, ',');
70  channel_db.push_back(field_db);
71  setdbruns.insert(field_db);
72 
73  }
74 
75  while ( getline(allgr, line_gr) ){
76  stringstream strgr(line_gr);
77  string field_gr;
78 
79  getline(strgr, field_gr,',');
80  dbmask_gr.push_back(field_gr);
81 
82  getline(strgr, field_gr, ',');
83  flag_gr.push_back(field_gr);
84 
85  getline(strgr, field_gr, ',');
86  comment_gr.push_back(field_gr);
87 
88  getline(strgr, field_gr, ',');
89  miprate_gr.push_back(field_gr);
90 
91  getline(strgr, field_gr, ',');
92  ngooddb_gr.push_back(field_gr);
93 
94  getline(strgr, field_gr, ',');
95  numslc_gr.push_back(field_gr);
96 
97  getline(strgr, field_gr, ',');
98  trkfrac_gr.push_back(field_gr);
99 
100  getline(strgr, field_gr, ',');
101  getline(strgr, field_gr, ',');
102  channel_gr.push_back(field_gr);
103 
104  }
105 
106  outdb << "dbmask,flag,comment,miprate,ngooddb,numslc,trkfrac,tv,channel" << endl;
107  bool samechannel, changedchannel;
108 
109  string lastchannel="0";
110 
111  for(int j=0; j<channel_db.size(); j++){
112  runflagmap[atoi(channel_db[j].c_str())] = atoi(flag_db[j].c_str());
113  if(atoi(channel_db[j].c_str()) > atoi(lastchannel.c_str()))
114  lastchannel = channel_db[j];
115  }
116  //lastchannel="0";
117  std::cout << "Last Channel: " << lastchannel << std::endl;
118  int j = 0;
119  for(int i=1; i<channel_gr.size(); i++){
120  samechannel = false;
121  changedchannel = false;
122  //std::cout << "Checking " << i << " out of " << channel_gr.size() << std::endl;
123  if(atoi(channel_gr[i].c_str()) <= atoi(lastchannel.c_str()))
124  samechannel=true;
125  //for(int j=0; j<channel_db.size(); j++){
126  //std::cout << "Value Check: " << channel_gr[i] << ", " << channel_db[j] << endl;
127  //if((atoi(channel_gr[i].c_str())) == (atoi(channel_db[j].c_str()))){
128  //samechannel = true;
129  //break;
130  //}
131  //if((atoi(channel_gr[i].c_str())) < (atoi(channel_db[j].c_str()))){
132  //std::cout << "Do I get here?" << endl;
133  //break;
134  //}
135  //}
136  //std::cout << "Begin? " << channel_db.begin() << std::endl;
137  /*
138  if( runflagmap[atoi(channel_gr[i].c_str())] == atoi(flag_db[i].c_str()) ){
139  cout << "Run number "<< channel_gr[i] << " flag is different. " << atoi(flag_gr[i].c_str()) << " in GR and " << atoi(flag_db[j].c_str()) << " in database" << endl;
140  changedchannel = true;
141  }
142  }
143  */
144  if( samechannel == false ){
145  //if( setdbruns.find(channel_gr[i]) == setdbruns.end() ){
146  std::cout << "New subrun found! Adding subrun " << channel_gr[i] << " to database..." << endl;
147  outdb << dbmask_gr[i] <<","<< flag_gr[i] <<"," << comment_gr[i]<<"," << miprate_gr[i]<<"," << ngooddb_gr[i]<<"," << numslc_gr[i]<<"," << trkfrac_gr[i]<<"," <<channel_gr[i]<<","<< 0 << endl;
148  }
149  else if( changedchannel == true){
150  std::cout << "Old subrun has changed! Uploading new Subrun " << channel_gr[i] << " metrics to database..." << endl;
151  outdb << dbmask_gr[i] <<","<< flag_gr[i] <<"," << comment_gr[i]<<"," << miprate_gr[i]<<"," << ngooddb_gr[i]<<"," << numslc_gr[i]<<"," << trkfrac_gr[i]<<"," <<channel_gr[i]<<","<< 0 << endl;
152  }
153  else{}
154 }
155  //std::cout << dbmask_db[1] <<","<< flag_db[1] <<"," << comment_db[1]<<"," << miprate_db[1]<<"," << ngooddb_db[1]<<"," << numslc_db[1]<<"," << trkfrac_db[1]<<"," << channel_db[1];
156  outdb.close();
157 }
void FindNewDQRuns(string filename="testdqcopy.csv", string filename2="tables/DQValidityTable.csv")
Definition: FindNewDQRuns.C:10
string filename
Definition: shutoffs.py:106
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6