ValidateDBMasks.C
Go to the documentation of this file.
1 #include <map>
2 #include <set>
3 #include <algorithm>
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 
8 #include <TFile.h>
9 #include <TString.h>
10 #include <TMath.h>
11 #include <TTree.h>
12 
13 //DQValidityTable.csv from tables/DQValidityTable.csv, shows all metrics from all runs from the database
14 
15 void ValidateDBMasks(string onmonfile="DQValidityTable.csv"){
16 
17  ifstream grfile(onmonfile.c_str());
18  ifstream dbfile("dbmaskvalid.csv");
19  map<int, int> dbmap;
20  string dbrun, dbmask;
21 
22  vector<string> dbmask_db;
23  vector<string> flag_db;
24  //vector<string> comment_db;
25  vector<string> miprate_db;
26  vector<string> ngooddb_db;
27  vector<string> numslc_db;
28  vector<string> trkfrac_db;
29  vector<string> channel_db;
30 
31  vector<string> dbmask_gr;
32  vector<string> flag_gr;
33  //vector<string> comment_gr;
34  vector<string> miprate_gr;
35  vector<string> ngooddb_gr;
36  vector<string> numslc_gr;
37  vector<string> trkfrac_gr;
38  vector<string> channel_gr;
39 
40  std::map< string, std::vector<string> > dbsubruns;
41 
42  string line_db;
43  string line_gr;
44 
45 while ( getline(dbfile, line_db) ){
46  stringstream strdb(line_db);
47  string field_db;
48 
49  getline(strdb, field_db,',');
50  dbmask_db.push_back(field_db);
51 
52 
53  getline(strdb, field_db, ',');
54  flag_db.push_back(field_db);
55 
56  getline(strdb, field_db, ',');
57  // comment_db.push_back(field_db);
58 
59  getline(strdb, field_db, ',');
60  miprate_db.push_back(field_db);
61 
62  getline(strdb, field_db, ',');
63  ngooddb_db.push_back(field_db);
64 
65  getline(strdb, field_db, ',');
66  numslc_db.push_back(field_db);
67 
68  getline(strdb, field_db, ',');
69  trkfrac_db.push_back(field_db);
70 
71  getline(strdb, field_db, ',');
72  channel_db.push_back(field_db);
73  dbsubruns[field_db];
74 
75  dbsubruns[field_db].push_back(dbmask_db.back());
76  dbsubruns[field_db].push_back(flag_db.back());
77  dbsubruns[field_db].push_back(miprate_db.back());
78  dbsubruns[field_db].push_back(ngooddb_db.back());
79  dbsubruns[field_db].push_back(numslc_db.back());
80  dbsubruns[field_db].push_back(trkfrac_db.back());
81 
82  }
83 
84 while ( getline(grfile, line_gr) ){
85  stringstream strgr(line_gr);
86  string field_gr;
87 
88  getline(strgr, field_gr,',');
89  dbmask_gr.push_back(field_gr);
90 
91  getline(strgr, field_gr, ',');
92  flag_gr.push_back(field_gr);
93 
94  getline(strgr, field_gr, ',');
95  //comment_gr.push_back(field_gr);
96 
97  getline(strgr, field_gr, ',');
98  miprate_gr.push_back(field_gr);
99 
100  getline(strgr, field_gr, ',');
101  ngooddb_gr.push_back(field_gr);
102 
103  getline(strgr, field_gr, ',');
104  numslc_gr.push_back(field_gr);
105 
106  getline(strgr, field_gr, ',');
107  trkfrac_gr.push_back(field_gr);
108 
109  getline(strgr, field_gr, ',');
110  getline(strgr, field_gr, ',');
111  channel_gr.push_back(field_gr);
112 
113  }
114 
115  string lasttrkfrac, lastnumslc, lastngooddb, lastmiprate, lastflag, lastdbmask;
116 
117  int numnotfound;
118  int numnotmatch;
119 
120  string lastchannel="0";
121 
122  for(int j=0; j<channel_db.size(); j++){
123  if(atoi(channel_db[j].c_str()) > atoi(lastchannel.c_str()))
124  lastchannel = channel_db[j];
125  }
126 
127  for(int i = 0; i < channel_gr.size(); i++){
128  //initialize
129  if(i == 0){
130  lasttrkfrac = trkfrac_gr[i];
131  lastnumslc = numslc_gr[i];
132  lastngooddb = ngooddb_gr[i];
133  lastmiprate = miprate_gr[i];
134  lastflag = flag_gr[i];
135  lastdbmask = dbmask_gr[i];
136  }
137 
138  if( atoi(channel_gr[i].c_str()) > atoi(lastchannel.c_str()) ) continue;
139 
140  if(lasttrkfrac == trkfrac_gr[i] && lastnumslc == numslc_gr[i] && lastngooddb == ngooddb_gr[i] && lastmiprate == miprate_gr[i] && lastflag == flag_gr[i] && lastdbmask == dbmask_gr[i]);
141  else{
142  lasttrkfrac = trkfrac_gr[i];
143  lastnumslc = numslc_gr[i];
144  lastngooddb = ngooddb_gr[i];
145  lastmiprate = miprate_gr[i];
146  lastflag = flag_gr[i];
147  lastdbmask = dbmask_gr[i];
148  }
149  //farther out than last database entry
150  if( atoi(channel_gr[i].c_str()) > atoi(lastchannel.c_str()) ) continue;
151 
152  //if subrun metrics are the same as the "last" one, it won't show up in the database, so just continue;
153  if(dbsubruns.find(channel_gr[i]) == dbsubruns.end()){
154  if(lasttrkfrac == trkfrac_gr[i] && lastnumslc == numslc_gr[i] && lastngooddb == ngooddb_gr[i] && lastmiprate == miprate_gr[i] && lastflag == flag_gr[i] && lastdbmask == dbmask_gr[i]);
155  else{
156  std::cout << "Run Number " << channel_gr[i] << " not found in database!" << std::endl;
157  numnotfound++;
158 
159  }
160  }
161  //Subrun is in both goodruns and database, see if their metrics are the same, if not, cry foul!
162  else{
163  if(atof(lasttrkfrac.c_str()) == atof(dbsubruns[channel_gr[i]][5].c_str()) && atof(lastnumslc.c_str()) == atof(dbsubruns[channel_gr[i]][4].c_str()) && lastngooddb == dbsubruns[channel_gr[i]][3] && atof(lastmiprate.c_str()) == atof(dbsubruns[channel_gr[i]][2].c_str()) && lastflag == dbsubruns[channel_gr[i]][1] && lastdbmask == dbsubruns[channel_gr[i]][0]);
164  else{
165  numnotmatch++;
166  std::cout << "Run Number " << channel_gr[i] << " does not match the database!" << std::endl;
167  std::cout << "Track Fraction: " << lasttrkfrac << "/" << dbsubruns[channel_gr[i]][5] << std::endl;
168  std::cout << "Num Slc: " << lastnumslc << "/" <<dbsubruns[channel_gr[i]][4] << std::endl;
169  std::cout << "Diblocks: " << lastngooddb << "/" <<dbsubruns[channel_gr[i]][3] << std::endl;
170  std::cout << "MIP Rate: " << lastmiprate << "/" <<dbsubruns[channel_gr[i]][2] << std::endl;
171  std::cout << "Flag: " << lastflag << "/" <<dbsubruns[channel_gr[i]][1] << std::endl;
172  std::cout << "Diblock Mask: " << lastdbmask << "/" <<dbsubruns[channel_gr[i]][0] << std::endl;
173  }
174  }
175 
176  }
177  std::cout << "Validation Complete!" << std::endl;
178  std::cout << "-------RESULTS-------" << std::endl;
179  std::cout << "Number of Subruns not in Database: " << numnotfound << std::endl;
180  std::cout << "Number of Subruns with wrong dbmask: " << numnotmatch << std::endl;
181 }
void ValidateDBMasks(string onmonfile="DQValidityTable.csv")
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6