CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
listbadmodule.cc File Reference
#include <iostream>
#include <stdio.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TKey.h>
#include <TH1.h>
#include <Riostream.h>
#include <string>
#include <vector>
#include <set>
#include <fstream>
#include <sstream>
#include <stdint.h>
#include <cstdlib>
#include <cstdio>
#include "listbadmodule.h"

Go to the source code of this file.

Functions

void listbadmodule (std::string filename, std::string pclfilename)
 
int main (int argc, char *argv[])
 

Function Documentation

void listbadmodule ( std::string  filename,
std::string  pclfilename 
)

Definition at line 39 of file listbadmodule.cc.

References gather_cfg::cout, debug, i, relval_steps::key, geometryCSVtoXML::line, python.rootplot.argparse::message, GetRecoTauVFromDQM_MC_cff::next, timingPdfMaker::outfile, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by main().

39  {
40 
41  int debug = 1;
42 
43  // extract fully bad modules from PCLBadComponents txt file
44 
45  std::set<unsigned int> pclbadmods;
46 
47  std::ifstream pclfile(pclfilename);
48 
49  char line[400];
50  unsigned int pcldetid;
51  char sixapvs[]="1 1 1 1 1 1";
52  char fourapvs[]="1 1 x x 1 1";
53 
54  while(pclfile.getline(line,400)) {
55  if(strstr(line,sixapvs) || strstr(line,fourapvs)) {
56  std::stringstream linestream;
57  linestream << line;
58  linestream >> pcldetid;
59  // std::cout << pcldetid << std::endl;
60  pclbadmods.insert(pcldetid);
61  }
62  }
63 
64  std::vector<std::string> subdet;
65  subdet.push_back("TIB");
66  subdet.push_back("TID/MINUS");
67  subdet.push_back("TID/PLUS");
68  subdet.push_back("TOB");
69  subdet.push_back("TEC/MINUS");
70  subdet.push_back("TEC/PLUS");
71 
72  std::string nrun = filename.substr(filename.find("_R000")+5, 6);
73  int fileNum = atoi(nrun.c_str());
74  std::cout << " ------ Run " << fileNum << std::endl;
75 
76  std::ofstream outfile;
77  std::string namefile;
78  namefile = "QualityTestOBSOLETE_run" + nrun + ".txt";
79  outfile.open(namefile.c_str());
80 
81  TFile *myfile = TFile::Open(filename.c_str());
82  if (debug == 1){
83  std::cout <<" Opened "<< filename << std::endl;
84  }
85  std::string topdir = "DQMData/Run " + nrun + "/SiStrip/Run summary/MechanicalView";
86  gDirectory->cd(topdir.c_str());
87  TDirectory* mec1 = gDirectory;
88 
89  //get the summary first
90  std::vector <int> nbadmod;
91  for (unsigned int i=0; i < subdet.size(); i++){
92  int nbad = 0;
93  std::string badmodule_dir = subdet[i] + "/BadModuleList";
94  if (gDirectory->cd(badmodule_dir.c_str())){
95  TIter next(gDirectory->GetListOfKeys());
96  TKey *key;
97  while ( (key = dynamic_cast<TKey*>(next())) ) {
98  std::string sflag = key->GetName();
99  if (sflag.size() == 0) continue;
100  nbad++;
101  }
102  }
103  nbadmod.push_back(nbad);
104  mec1->cd();
105  }
106 
107  outfile << "Number of bad modules in total excluding PCL-only bad modules:" << std::endl;
108  outfile << "--------------------------------------------------------------" << std::endl;
109  outfile << subdet.at(0) << ": " << nbadmod.at(0) << std::endl;
110  outfile << subdet.at(1) << ": " << nbadmod.at(1) << std::endl;
111  outfile << subdet.at(2) << ": " << nbadmod.at(2) << std::endl;
112  outfile << subdet.at(3) << ": " << nbadmod.at(3) << std::endl;
113  outfile << subdet.at(4) << ": " << nbadmod.at(4) << std::endl;
114  outfile << subdet.at(5) << ": " << nbadmod.at(5) << std::endl;
115  outfile << "-------------------------------" << std::endl;
116 
117  outfile << std::endl
118  << "List of bad modules per partition:" << std::endl;
119  outfile << "----------------------------------" << std::endl;
120 
121  std::set<unsigned int>::const_iterator pclbadmod = pclbadmods.begin();
122 
123  for (unsigned int i=0; i < subdet.size(); i++){
124  std::string badmodule_dir = subdet[i] + "/BadModuleList";
125  outfile << " " << std::endl;
126  outfile << "SubDetector " << subdet[i] << std::endl;
127  outfile << " " << std::endl;
128  std::cout << badmodule_dir.c_str() << std::endl;
129  if (gDirectory->cd(badmodule_dir.c_str())){
130  //
131  // Loop to find bad module for each partition
132  //
133  TIter next(gDirectory->GetListOfKeys());
134  TKey *key;
135 
136  while ( (key = dynamic_cast<TKey*>(next())) ) {
137  std::string sflag = key->GetName();
138  if (sflag.size() == 0) continue;
139  std::string detid = sflag.substr(sflag.find("<")+1,9);
140  size_t pos1 = sflag.find("/");
141  sflag = sflag.substr(sflag.find("<")+13,pos1-2);
142  int flag = atoi(sflag.c_str());
143  sscanf(detid.c_str(),"%u",&pcldetid);
144  // the following loop add modules which are bad only for the PCL to the list.
145  // It requires that the bad modules from QT are sorted as the one of the PCL
146  while(pclbadmod!= pclbadmods.end() && pcldetid > *pclbadmod) {
147  outfile << "Module " << *pclbadmod << " PCLBadModule " << std::endl;
148  pclbadmod++;
149  }
151  message = "Module " + detid;
152  if (((flag >> 0) & 0x1) > 0) message += " Fed BadChannel : ";
153  if (((flag >> 1) & 0x1) > 0) message += " # of Digi : ";
154  if (((flag >> 2) & 0x1) > 0) message += " # of Clusters :";
155  if (((flag >> 3) & 0x1) > 0) message += " Excluded FED Channel ";
156  if (((flag >> 4) & 0x1) > 0) message += " DCSError ";
157  if (pclbadmods.find(pcldetid) != pclbadmods.end()) {
158  message += " PCLBadModule ";
159  pclbadmod = pclbadmods.find(pcldetid);
160  pclbadmod++;
161  }
162  outfile << message.c_str() << std::endl;
163 
164  }
165  }
166  mec1->cd();
167  }
168  myfile->Close();
169  outfile.close();
170 }
int i
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#define debug
Definition: HDRShower.cc:19
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145
int main ( int  argc,
char *  argv[] 
)

Definition at line 22 of file listbadmodule.cc.

References gather_cfg::cout, lut2db_cfg::filename, and listbadmodule().

22  {
23 
24  if(argc==3) {
25  char* filename = argv[1];
26  char* pclfilename = argv[2];
27 
28  std::cout << "ready to prepare list of bad modules " << filename << std::endl;
29 
30  listbadmodule(filename,pclfilename);
31 
32  }
33  else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
34  return 0;
35 
36 }
tuple argc
Definition: dir2webdir.py:38
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145
void listbadmodule(std::string filename, std::string pclfilename)