CMS 3D CMS Logo

listbadmodule.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstdio>
3 #include <TDirectory.h>
4 #include <TFile.h>
5 #include <TKey.h>
6 #include <TH1.h>
7 #include <Riostream.h>
8 #include <string>
9 #include <vector>
10 #include <set>
11 #include <fstream>
12 #include <sstream>
13 #include <string>
14 #include <cstdint>
15 #include <cstdlib>
16 #include <cstdio>
17 
18 #include "listbadmodule.h"
19 
20 //using namespace std;
21 
22 int main(int argc, char *argv[]) {
23  if (argc == 3) {
24  char *filename = argv[1];
25  char *pclfilename = argv[2];
26 
27  std::cout << "ready to prepare list of bad modules " << filename << std::endl;
28 
29  listbadmodule(filename, pclfilename);
30 
31  } else {
32  std::cout << "Too few arguments: " << argc << std::endl;
33  return -1;
34  }
35  return 0;
36 }
37 
39  int debug = 1;
40 
41  // extract fully bad modules from PCLBadComponents txt file
42 
43  std::set<unsigned int> pclbadmods;
44 
45  std::ifstream pclfile(pclfilename);
46 
47  char line[400];
48  unsigned int pcldetid;
49  char sixapvs[] = "1 1 1 1 1 1";
50  char fourapvs[] = "1 1 x x 1 1";
51 
52  while (pclfile.getline(line, 400)) {
53  if (strstr(line, sixapvs) || strstr(line, fourapvs)) {
54  std::stringstream linestream;
55  linestream << line;
56  linestream >> pcldetid;
57  // std::cout << pcldetid << std::endl;
58  pclbadmods.insert(pcldetid);
59  }
60  }
61 
62  std::vector<std::string> subdet;
63  subdet.push_back("TIB");
64  subdet.push_back("TID/MINUS");
65  subdet.push_back("TID/PLUS");
66  subdet.push_back("TOB");
67  subdet.push_back("TEC/MINUS");
68  subdet.push_back("TEC/PLUS");
69 
70  std::string nrun = filename.substr(filename.find("_R000") + 5, 6);
71  int fileNum = atoi(nrun.c_str());
72  std::cout << " ------ Run " << fileNum << std::endl;
73 
74  std::ofstream outfile;
75  std::string namefile;
76  namefile = "QualityTestOBSOLETE_run" + nrun + ".txt";
77  outfile.open(namefile.c_str());
78 
79  TFile *myfile = TFile::Open(filename.c_str());
80  if (debug == 1) {
81  std::cout << " Opened " << filename << std::endl;
82  }
83  std::string topdir = "DQMData/Run " + nrun + "/SiStrip/Run summary/MechanicalView";
84  gDirectory->cd(topdir.c_str());
85  TDirectory *mec1 = gDirectory;
86 
87  //get the summary first
88  std::vector<int> nbadmod;
89  for (unsigned int i = 0; i < subdet.size(); i++) {
90  int nbad = 0;
91  std::string badmodule_dir = subdet[i] + "/BadModuleList";
92  if (gDirectory->cd(badmodule_dir.c_str())) {
93  TIter next(gDirectory->GetListOfKeys());
94  TKey *key;
95  while ((key = dynamic_cast<TKey *>(next()))) {
96  std::string sflag = key->GetName();
97  if (sflag.empty())
98  continue;
99  nbad++;
100  }
101  }
102  nbadmod.push_back(nbad);
103  mec1->cd();
104  }
105 
106  outfile << "Number of bad modules in total excluding PCL-only bad modules:" << std::endl;
107  outfile << "--------------------------------------------------------------" << std::endl;
108  outfile << subdet.at(0) << ": " << nbadmod.at(0) << std::endl;
109  outfile << subdet.at(1) << ": " << nbadmod.at(1) << std::endl;
110  outfile << subdet.at(2) << ": " << nbadmod.at(2) << std::endl;
111  outfile << subdet.at(3) << ": " << nbadmod.at(3) << std::endl;
112  outfile << subdet.at(4) << ": " << nbadmod.at(4) << std::endl;
113  outfile << subdet.at(5) << ": " << nbadmod.at(5) << std::endl;
114  outfile << "-------------------------------" << std::endl;
115 
116  outfile << std::endl << "List of bad modules per partition:" << std::endl;
117  outfile << "----------------------------------" << std::endl;
118 
119  std::set<unsigned int>::const_iterator pclbadmod = pclbadmods.begin();
120 
121  for (unsigned int i = 0; i < subdet.size(); i++) {
122  std::string badmodule_dir = subdet[i] + "/BadModuleList";
123  outfile << " " << std::endl;
124  outfile << "SubDetector " << subdet[i] << std::endl;
125  outfile << " " << std::endl;
126  std::cout << badmodule_dir.c_str() << std::endl;
127  if (gDirectory->cd(badmodule_dir.c_str())) {
128  //
129  // Loop to find bad module for each partition
130  //
131  TIter next(gDirectory->GetListOfKeys());
132  TKey *key;
133 
134  while ((key = dynamic_cast<TKey *>(next()))) {
135  std::string sflag = key->GetName();
136  if (sflag.empty())
137  continue;
138  std::string detid = sflag.substr(sflag.find("<") + 1, 9);
139  size_t pos1 = sflag.find("/");
140  sflag = sflag.substr(sflag.find("<") + 13, pos1 - 2);
141  int flag = atoi(sflag.c_str());
142  sscanf(detid.c_str(), "%u", &pcldetid);
143  // the following loop add modules which are bad only for the PCL to the list.
144  // It requires that the bad modules from QT are sorted as the one of the PCL
145  while (pclbadmod != pclbadmods.end() && pcldetid > *pclbadmod) {
146  outfile << "Module " << *pclbadmod << " PCLBadModule " << std::endl;
147  pclbadmod++;
148  }
149  std::string message;
150  message = "Module " + detid;
151  if (((flag >> 0) & 0x1) > 0)
152  message += " Fed BadChannel : ";
153  if (((flag >> 1) & 0x1) > 0)
154  message += " # of Digi : ";
155  if (((flag >> 2) & 0x1) > 0)
156  message += " # of Clusters :";
157  if (((flag >> 3) & 0x1) > 0)
158  message += " Excluded FED Channel ";
159  if (((flag >> 4) & 0x1) > 0)
160  message += " DCSError ";
161  if (pclbadmods.find(pcldetid) != pclbadmods.end()) {
162  message += " PCLBadModule ";
163  pclbadmod = pclbadmods.find(pcldetid);
164  pclbadmod++;
165  }
166  outfile << message.c_str() << std::endl;
167  }
168  }
169  mec1->cd();
170  }
171  myfile->Close();
172  outfile.close();
173 }
cmsBatch.argv
argv
Definition: cmsBatch.py:279
mps_fire.i
i
Definition: mps_fire.py:355
dir2webdir.argc
argc
Definition: dir2webdir.py:39
gather_cfg.cout
cout
Definition: gather_cfg.py:144
main
int main(int argc, char *argv[])
Definition: listbadmodule.cc:22
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
debug
#define debug
Definition: HDRShower.cc:19
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
listbadmodule.h
listbadmodule
void listbadmodule(std::string filename, std::string pclfilename)
Definition: listbadmodule.cc:38
timingPdfMaker.outfile
outfile
Definition: timingPdfMaker.py:351
mps_splice.line
line
Definition: mps_splice.py:76
crabWrapper.key
key
Definition: crabWrapper.py:19
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31