CMS 3D CMS Logo

Functions
modulediff.cc File Reference
#include <Riostream.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TKey.h>
#include <TH1.h>
#include <TH2.h>
#include <TH2D.h>
#include <TCanvas.h>
#include <TGraph.h>
#include <TPaveStats.h>
#include <TText.h>
#include <TLegend.h>
#include <cstring>
#include <utility>
#include <vector>
#include <sstream>
#include <algorithm>
#include <TString.h>
#include <TColor.h>
#include <dirent.h>

Go to the source code of this file.

Functions

void get_difference (vector< int >, vector< int >, vector< int > &)
 
int get_filename (int, string, string &)
 
int main (int argc, char *argv[])
 
void modulediff (int run_2, string repro_run2)
 
int read_badmodlist (int, string, vector< int > &)
 
int search_closest_run (int, string)
 

Function Documentation

void get_difference ( vector< int >  badlist1,
vector< int >  badlist2,
vector< int > &  difflist 
)

Definition at line 129 of file modulediff.cc.

Referenced by modulediff().

130 {
131  //check if any element of badlist1 is in badlist2
132  for ( unsigned int i1 = 0; i1 < badlist1.size() ; i1++ )
133  {
134  bool thisrecovered = true;
135  for ( unsigned int i2 = 0; i2 < badlist2.size() ; i2++ )
136  if ( badlist1[ i1 ] == badlist2[ i2 ] )
137  {
138  thisrecovered = false;
139  break;
140  }
141  if ( thisrecovered )
142  difflist.push_back ( badlist1[ i1 ] );
143  }
144 }
int get_filename ( int  run,
string  repro_type,
string &  filename 
)

Definition at line 201 of file modulediff.cc.

References gather_cfg::cout, nullptr, findQualityFiles::run, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by read_badmodlist(), and search_closest_run().

202 {
203  stringstream runstr;
204  runstr << run;
205 
206  stringstream rundirprefix;
207  rundirprefix << "000" << run / 100 << "xx/";
208 
209  stringstream thisdir;
210  //thisdir << "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/data/OfflineData/Run2011/" << repro_type.c_str() << "/" << rundirprefix.str();
211  thisdir << "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/data/OfflineData/HIRun2011/" << repro_type.c_str() << "/" << rundirprefix.str();
212 
213  string thisdir2 = thisdir.str();
214  DIR *dp;
215 
216  if ( ( dp = opendir( thisdir2.c_str() ) ) == nullptr )
217  {
218  cout << "dir " << thisdir2.c_str() << " not found" << endl;
219  return -1;
220  }
221 
222  struct dirent *dirp;
223 
224  string dqmfile;
225 
226  while ( ( dirp = readdir ( dp ) ) != nullptr )
227  {
228  string dirfile = string ( dirp->d_name );
229  if (
230  dirfile.find ( "__DQM" ) != string::npos &&
231  dirfile.find ( runstr.str() ) != string::npos
232  )
233  {
234  dqmfile = dirfile;
235  break;
236  }
237  }
238 
239  closedir( dp );
240 
241  if ( dqmfile.size() < 10 )
242  {
243  //cout << "file " << dqmfile << " not found" << endl;
244  return -1;
245  }
246 
247  filename = thisdir.str() + dqmfile;
248 
249  return 0;
250 }
#define nullptr
int main ( int  argc,
char *  argv[] 
)

Definition at line 32 of file modulediff.cc.

References gather_cfg::cout, modulediff(), and compare_using_db::run2.

32  {
33 
34  if(argc==3) {
35  char* crun2 = argv[1];
36  char* repro_run2 = argv[2];
37 
38  int run2 = 0;
39  sscanf(crun2,"%d",&run2);
40 
41  std::cout << "ready to run modulediff " << run2 << " repro run " << repro_run2 << std::endl;
42 
43  modulediff(run2,repro_run2);
44 
45  }
46  else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
47  return 0;
48 
49 }
void modulediff(int run_2, string repro_run2)
Definition: modulediff.cc:51
void modulediff ( int  run_2,
string  repro_run2 
)

Definition at line 51 of file modulediff.cc.

References gather_cfg::cout, get_difference(), mps_fire::i, createfilelist::int, lumiCalc2::outfile, read_badmodlist(), and search_closest_run().

Referenced by main().

52 {
53  vector < int > badmodlist_run1;
54  vector < int > badmodlist_run2;
55  vector < int > modules_recovered;
56  vector < int > modules_malformed;
57  int run_1;
58  string repro_run1;
59 
60  int res = search_closest_run ( run_2 , repro_run2 );
61  if ( res > 0 )
62  {
63  run_1 = res;
64  repro_run1 = repro_run2;
65  }
66  else
67  {
68  printf("closest run not found, exiting.\n");
69  return;
70  }
71 
72 
73  int flag1 = read_badmodlist ( run_1 , repro_run1 , badmodlist_run1 );
74  int flag2 = read_badmodlist ( run_2 , repro_run2 , badmodlist_run2 );
75 
76  if ( flag1 < 0 || flag2 < 0 )
77  {
78  cout << "Error: file not found." << endl;
79  return;
80  }
81 
82  get_difference ( badmodlist_run1 , badmodlist_run2 , modules_recovered );
83  get_difference ( badmodlist_run2 , badmodlist_run1 , modules_malformed );
84 
85  //save into file
86  std::ofstream outfile;
87  string namefile = "modulediff_emailbody.txt";
88  outfile.open(namefile.c_str());
89 
90  outfile << "Recovered modules in run " << run_2 << ": " << (int)modules_recovered.size() << endl;
91  outfile << "New bad modules in run " << run_2 << ": " << (int)modules_malformed.size() << endl;
92  outfile << "Using reference run " << run_1 << endl << endl;
93 
94  outfile << "Recovered modules in run " << run_2 << ":" << endl;
95  if ( modules_recovered.empty() )
96  outfile << " -" << endl;
97  for ( unsigned int i = 0; i < modules_recovered.size() ; i++ )
98  outfile << " " << modules_recovered[ i ] << endl;
99 
100  outfile << "New bad modules that appeared in run " << run_2 << ":" << endl;
101  if ( modules_malformed.empty() )
102  outfile << " -" << endl;
103  for ( unsigned int i = 0; i < modules_malformed.size() ; i++ )
104  outfile << " " << modules_malformed[ i ] << endl;
105 
106  outfile.close();
107 
108  //create two flat files to run the locatemodule script on later
109 
110  if ( !modules_recovered.empty() )
111  {
112  std::ofstream outfile_good;
113  outfile_good.open("modulediff_good.txt");
114  for ( unsigned int i = 0; i < modules_recovered.size() ; i++ )
115  outfile_good << " " << modules_recovered[ i ] << endl;
116  outfile_good.close();
117  }
118 
119  if ( !modules_malformed.empty() )
120  {
121  std::ofstream outfile_bad;
122  outfile_bad.open("modulediff_bad.txt");
123  for ( unsigned int i = 0; i < modules_malformed.size() ; i++ )
124  outfile_bad << " " << modules_malformed[ i ] << endl;
125  outfile_bad.close();
126  }
127 }
int read_badmodlist(int, string, vector< int > &)
Definition: modulediff.cc:147
int search_closest_run(int, string)
Definition: modulediff.cc:253
void get_difference(vector< int >, vector< int >, vector< int > &)
Definition: modulediff.cc:129
Definition: Electron.h:6
int read_badmodlist ( int  run,
string  repro_type,
vector< int > &  badlist 
)

Definition at line 147 of file modulediff.cc.

References gather_cfg::cout, corrVsCorr::filename, RemoveAddSevLevel::flag, get_filename(), mps_fire::i, crabWrapper::key, and GetRecoTauVFromDQM_MC_cff::next.

Referenced by modulediff().

148 {
149  string filename;
150  int flag = get_filename ( run , repro_type , filename );
151 
152  if ( flag < 0 )
153  {
154  cout << "reading problem" << endl;
155  return -1;
156  }
157 
158  vector<string> subdet;
159  subdet.push_back("TIB");
160  subdet.push_back("TID/MINUS");
161  subdet.push_back("TID/PLUS");
162  subdet.push_back("TOB");
163  subdet.push_back("TEC/MINUS");
164  subdet.push_back("TEC/PLUS");
165 
166  string nrun = filename.substr ( filename.find( "_R000" ) + 5 , 6 );
167 
168  TFile *dqmfile = TFile::Open ( filename.c_str() , "READ" );
169  string topdir = "DQMData/Run " + nrun + "/SiStrip/Run summary/MechanicalView";
170  gDirectory->cd(topdir.c_str());
171  TDirectory* mec1 = gDirectory;
172 
173  for ( unsigned int i=0; i < subdet.size(); i++ )
174  {
175  string badmodule_dir = subdet[ i ] + "/BadModuleList";
176  if ( gDirectory->cd ( badmodule_dir.c_str() ) )
177  {
178  TIter next ( gDirectory->GetListOfKeys() );
179  TKey *key;
180 
181  while ( ( key = dynamic_cast<TKey*> ( next() ) ) )
182  {
183  string sflag = key->GetName();
184  if ( sflag.empty() ) continue;
185 
186  string detid = sflag.substr ( sflag.find ( "<" ) + 1 , 9 );
187  badlist.push_back ( atoi ( detid.c_str() ) );
188  }
189  }
190  else
191  {
192  //cout << "no dir " << badmodule_dir << " in filename " << filename << endl;
193  }
194  mec1->cd();
195  }
196  dqmfile->Close();
197  return 0;
198 }
int get_filename(int, string, string &)
Definition: modulediff.cc:201
int search_closest_run ( int  thisrun,
string  repro_type 
)

Definition at line 253 of file modulediff.cc.

References corrVsCorr::filename, and get_filename().

Referenced by modulediff().

254 {
255  string filename;
256 
257  for ( int test_run = thisrun - 1; test_run > thisrun - 1000; test_run-- )
258  {
259  int res = get_filename ( test_run , repro_type , filename );
260  if ( res == 0 )
261  return test_run;
262  }
263 
264  return -1;
265 }
Definition: Electron.h:6
int get_filename(int, string, string &)
Definition: modulediff.cc:201