CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripBadComponentsDQMService.cc
Go to the documentation of this file.
5 #include <string>
6 #include <sstream>
7 #include <cctype>
8 #include <time.h>
9 #include "boost/cstdint.hpp"
10 #include "boost/lexical_cast.hpp"
11 
12 using namespace std;
13 
16  iConfig_(iConfig),
17  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
18  notAlreadyRead_(true)
19 {
20  obj_ = 0;
21  edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::SiStripBadComponentsDQMService]";
22 }
23 
25 {
26  edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::~SiStripBadComponentsDQMService]";
27 }
28 
30 {
31  ss << "Run " << getRunNumber() << std::endl;
33  obj_->printSummary(ss);
34 }
35 
37 {
38  std::stringstream localString;
39  getMetaDataString(localString);
40  if( ss == localString.str() ) return false;
41 
42  return true;
43 }
44 
46 {
47  // Do this only if it was not already read
48  if( notAlreadyRead_ ) {
49  //*LOOP OVER THE LIST OF SUMMARY OBJECTS TO INSERT IN DB*//
50 
52 
53  std::cout << "[readBadComponents]: opened requested file" << std::endl;
54 
55  obj_=new SiStripBadStrip();
56 
58 
59  dqmStore_->cd();
60 
61  std::string mdir = "MechanicalView";
62  if (!goToDir(dqmStore_, mdir)) return;
63  std::string mechanicalview_dir = dqmStore_->pwd();
64 
65  std::vector<std::string> subdet_folder;
66  subdet_folder.push_back("TIB");
67  subdet_folder.push_back("TOB");
68  subdet_folder.push_back("TEC/side_1");
69  subdet_folder.push_back("TEC/side_2");
70  subdet_folder.push_back("TID/side_1");
71  subdet_folder.push_back("TID/side_2");
72 
73  int nDetsTotal = 0;
74  int nDetsWithErrorTotal = 0;
75  for( std::vector<std::string>::const_iterator im = subdet_folder.begin(); im != subdet_folder.end(); ++im ) {
76  std::string dname = mechanicalview_dir + "/" + (*im);
77  if (!dqmStore_->dirExists(dname)) continue;
78 
79  dqmStore_->cd(dname);
80  std::vector<std::string> module_folders;
81  getModuleFolderList(dqmStore_, module_folders);
82  int nDets = module_folders.size();
83 
84  int nDetsWithError = 0;
85  std::string bad_module_folder = dname + "/" + "BadModuleList";
86  if (dqmStore_->dirExists(bad_module_folder)) {
87  std::vector<MonitorElement *> meVec = dqmStore_->getContents(bad_module_folder);
88  for( std::vector<MonitorElement *>::const_iterator it = meVec.begin(); it != meVec.end(); ++it ) {
89  nDetsWithError++;
90  std::cout << (*it)->getName() << " " << (*it)->getIntValue() << std::endl;
91  uint32_t detId = boost::lexical_cast<uint32_t>((*it)->getName());
92  short flag = (*it)->getIntValue();
93 
94  std::vector<unsigned int> theSiStripVector;
95 
96  unsigned short firstBadStrip=0, NconsecutiveBadStrips=0;
97  unsigned int theBadStripRange;
98 
99  // for(std::vector<uint32_t>::const_iterator is=BadApvList_.begin(); is!=BadApvList_.end(); ++is){
100 
101  // firstBadStrip=(*is)*128;
102  NconsecutiveBadStrips=reader.getNumberOfApvsAndStripLength(detId).first*128;
103 
104  theBadStripRange = obj_->encode(firstBadStrip,NconsecutiveBadStrips,flag);
105 
106  LogDebug("SiStripBadComponentsDQMService") << "detid " << detId << " \t"
107  << ", flag " << flag
108  << std::endl;
109 
110  theSiStripVector.push_back(theBadStripRange);
111  // }
112 
113  SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
114  if ( !obj_->put(detId,range) ) {
115  edm::LogError("SiStripBadFiberBuilder")<<"[SiStripBadFiberBuilder::analyze] detid already exists"<<std::endl;
116  }
117  }
118  }
119  nDetsTotal += nDets;
120  nDetsWithErrorTotal += nDetsWithError;
121  }
122  dqmStore_->cd();
123  }
124 }
125 
127 {
129 
130  // ** FIXME ** //
131  dqmStore_->setVerbose(0); //add config param
132 
133  if( iConfig_.getParameter<bool>("accessDQMFile") ){
134 
136 
137  edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::openRequestedFile] Accessing root File" << fileName;
138 
139  dqmStore_->open(fileName, false);
140  } else {
141  edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::openRequestedFile] Accessing dqmStore stream in Online Operation";
142  }
143 }
144 
146  edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::getRunNumber] " << iConfig_.getParameter<uint32_t>("RunNb");
147  return iConfig_.getParameter<uint32_t>("RunNb");
148 }
149 
151 {
152  std::string currDir = dqm_store->pwd();
153  std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
154  if (dirName.find(name) == 0) {
155  return true;
156  }
157  std::vector<std::string> subDirVec = dqm_store->getSubdirs();
158  for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
159  ic != subDirVec.end(); ic++) {
160  dqm_store->cd(*ic);
161  if (!goToDir(dqm_store, name)) dqm_store->goUp();
162  else return true;
163  }
164  return false;
165 }
166 
167 void SiStripBadComponentsDQMService::getModuleFolderList(DQMStore * dqm_store, std::vector<std::string>& mfolders)
168 {
169  std::string currDir = dqm_store->pwd();
170  if (currDir.find("module_") != std::string::npos) {
171  // std::string mId = currDir.substr(currDir.find("module_")+7, 9);
172  mfolders.push_back(currDir);
173  } else {
174  std::vector<std::string> subdirs = dqm_store->getSubdirs();
175  for( std::vector<std::string>::const_iterator it = subdirs.begin();
176  it != subdirs.end(); ++it) {
177  dqm_store->cd(*it);
178  getModuleFolderList(dqm_store, mfolders);
179  dqm_store->goUp();
180  }
181  }
182 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void getMetaDataString(std::stringstream &ss)
Used to fill the logDB.
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1574
void printSummary(std::stringstream &ss) const
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
void getModuleFolderList(DQMStore *dqm_store, std::vector< std::string > &mfolders)
virtual bool checkForCompatibility(std::string ss)
Check is the transfer is needed.
SiStripBadComponentsDQMService(const edm::ParameterSet &, const edm::ActivityRegistry &)
bool goToDir(DQMStore *dqm_store, std::string name)
void setVerbose(unsigned level)
Definition: DQMStore.cc:548
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1652
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:648
std::pair< ContainerIterator, ContainerIterator > Range
void goUp(void)
equivalent to &quot;cd ..&quot;
Definition: DQMStore.cc:595
bool open(const std::string &filename, bool overwrite=false, const std::string &path="", const std::string &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2632
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:171
bool put(const uint32_t &detID, const InputVector &vect)
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
const std::string & pwd(void) const
Definition: DQMStore.cc:556