CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripCommissioningOfflineClient.cc
Go to the documentation of this file.
1 
21 #include <boost/cstdint.hpp>
22 #include <iostream>
23 #include <iomanip>
24 #include <fstream>
25 #include <sstream>
26 #include <sys/types.h>
27 #include <dirent.h>
28 #include <errno.h>
29 #include "TProfile.h"
30 
31 using namespace sistrip;
32 
33 // -----------------------------------------------------------------------------
34 //
36  : bei_( edm::Service<DQMStore>().operator->() ),
37  histos_(0),
38  //inputFiles_( pset.getUntrackedParameter< std::vector<std::string> >( "InputRootFiles", std::vector<std::string>() ) ),
39  outputFileName_( pset.getUntrackedParameter<std::string>( "OutputRootFile", "" ) ),
40  collateHistos_( !pset.getUntrackedParameter<bool>( "UseClientFile", false ) ),
41  analyzeHistos_( pset.getUntrackedParameter<bool>( "AnalyzeHistos", true ) ),
42  xmlFile_( (pset.getUntrackedParameter<edm::FileInPath>( "SummaryXmlFile", edm::FileInPath() )).fullPath() ),
43  createSummaryPlots_( false ),
44  clientHistos_( false ),
45  uploadToDb_( false ),
46  runType_(sistrip::UNKNOWN_RUN_TYPE),
47  runNumber_(0),
48  map_(),
49  plots_(),
50  parameters_(pset)
51 {
53  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
54  << " Constructing object...";
56  pset.getUntrackedParameter<std::string>( "FilePath" ),
57  pset.getUntrackedParameter<uint32_t>("RunNumber"),
59 }
60 
61 // -----------------------------------------------------------------------------
62 //
65  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
66  << " Destructing object...";
67 }
68 
69 // -----------------------------------------------------------------------------
70 //
73  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
74  << " Analyzing root file(s)...";
75 
76  // Check for null pointer
77  if ( !bei_ ) {
79  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
80  << " NULL pointer to DQMStore!"
81  << " Aborting...";
82  return;
83  }
84  bei_->setVerbose(0);
85 
86  // Check if .root file can be opened
87  std::vector<std::string>::const_iterator ifile = inputFiles_.begin();
88  for ( ; ifile != inputFiles_.end(); ifile++ ) {
89  std::ifstream root_file;
90  root_file.open( ifile->c_str() );
91  if( !root_file.is_open() ) {
93  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
94  << " The input root file \"" << *ifile
95  << "\" could not be opened!"
96  << " Please check the path and filename!";
97  } else {
98  root_file.close();
100  if ( found != std::string::npos && clientHistos_ ) {
102  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
103  << " The input root files appear to be a mixture"
104  << " of \"Source\" and \"Client\" files!"
105  << " Aborting...";
106  return;
107  }
108  if ( found != std::string::npos && inputFiles_.size() != 1 ) {
110  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
111  << " There appear to be multiple input \"Client\" root files!"
112  << " Aborting...";
113  return;
114  }
115  if ( found != std::string::npos ) { clientHistos_ = true; }
116  }
117  }
118  if ( clientHistos_ && inputFiles_.size() == 1 ) {
120  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
121  << " Collated histograms found in input root file \""
122  << inputFiles_[0] << "\"";
123  }
124 
125  // Check if .xml file can be opened
126  if ( !xmlFile_.empty() ) {
127  std::ifstream xml_file;
128  xml_file.open( xmlFile_.c_str() );
129  if( !xml_file.is_open() ) {
131  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
132  << " The SummaryPlot XML file \"" << xmlFile_
133  << "\" could not be opened!"
134  << " Please check the path and filename!"
135  << " Aborting...";
136  return;
137  } else {
138  createSummaryPlots_ = true;
139  xml_file.close();
140  }
141  }
142 
143  // Open root file(s) and create ME's
144  if ( inputFiles_.empty() ) {
146  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
147  << " No input root files specified!";
148  return;
149  }
150 
152  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
153  << " Opening root files. This may take some time!...";
154  std::vector<std::string>::const_iterator jfile = inputFiles_.begin();
155  for ( ; jfile != inputFiles_.end(); jfile++ ) {
157  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
158  << " Opening root file \"" << *jfile
159  << "\"... (This may take some time.)";
160  if ( clientHistos_ ) {
161  bei_->open( *jfile, false, sistrip::collate_, "" );
162  } else {
163  bei_->open( *jfile, false, "SiStrip", sistrip::collate_ );
164  }
166  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
167  << " Opened root file \"" << *jfile << "\"!";
168  }
170  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
171  << " Opened " << inputFiles_.size() << " root files!";
172 
173  // Retrieve list of histograms
174  std::vector<std::string> contents;
175  bei_->getContents( contents );
176 
177  // If using client file, remove "source" histograms from list
178  if ( clientHistos_ ) {
179  std::vector<std::string> temp;
180  std::vector<std::string>::iterator istr = contents.begin();
181  for ( ; istr != contents.end(); istr++ ) {
182  if ( istr->find(sistrip::collate_) != std::string::npos ) {
183  temp.push_back( *istr );
184  }
185  }
186  contents.clear();
187  contents = temp;
188  }
189 
190  // Some debug
192  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
193  << " Found " << contents.size()
194  << " directories containing MonitorElements";
195 
196  // Some more debug
197  if (0) {
198  std::stringstream ss;
199  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
200  << " Directories found: " << std::endl;
201  std::vector<std::string>::iterator istr = contents.begin();
202  for ( ; istr != contents.end(); istr++ ) { ss << " " << *istr << std::endl; }
203  LogTrace(mlDqmClient_) << ss.str();
204  }
205 
206  // Extract run type from contents
208 
209  // Extract run number from contents
211 
212  // Copy custom information to the collated structure
214 
215  // Check runType
218  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
219  << " Unknown commissioning runType: "
221  << " and run number is " << runNumber_;
222  return;
223  } else {
225  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
226  << " Run type is "
228  << " and run number is " << runNumber_;
229  }
230 
231  // Open and parse "summary plot" xml file
232  if ( createSummaryPlots_ ) {
234  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
235  << " Parsing summary plot XML file...";
236  SummaryPlotXmlParser xml_file;
237  xml_file.parseXML(xmlFile_);
238  plots_ = xml_file.summaryPlots(runType_);
240  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
241  << " Parsed summary plot XML file and found "
242  << plots_.size() << " plots defined!";
243  } else {
245  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
246  << " Null string for SummaryPlotXmlFile!"
247  << " No summary plots will be created!";
248  }
249 
250  // Some debug
251  std::stringstream ss;
252  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]" << std::endl
253  << " Input root files : ";
254  if ( inputFiles_.empty() ) { ss << "(none)"; }
255  else {
256  std::vector<std::string>::const_iterator ifile = inputFiles_.begin();
257  for ( ; ifile != inputFiles_.end(); ifile++ ) {
258  if ( ifile != inputFiles_.begin() ) {
259  ss << std::setw(25) << std::setfill(' ') << ": ";
260  }
261  ss << "\"" << *ifile << "\"" << std::endl;
262  }
263  }
264  ss << " Run type : \""
265  << SiStripEnumsAndStrings::runType( runType_ ) << "\"" << std::endl
266  << " Run number : " << runNumber_ << std::endl
267  << " Summary plot XML file : ";
268  if ( xmlFile_.empty() ) { ss << "(none)"; }
269  else { ss << "\"" << xmlFile_ << "\""; }
270  edm::LogVerbatim(mlDqmClient_) << ss.str();
271 
272  // Virtual method that creates CommissioningHistogram object
274  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
275  << " Creating CommissioningHistogram object...";
276  createHistos(parameters_, setup);
277  if ( histos_ ) {
279  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
280  << " Created CommissioningHistogram object!";
281  } else {
283  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
284  << " NULL pointer to CommissioningHistogram object!"
285  << " Aborting...";
286  return;
287  }
288 
289  // Perform collation
290  if ( histos_ ) {
291  histos_->extractHistograms( contents );
292  }
293 
294  // Perform analysis
295  if ( analyzeHistos_ ) {
297  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
298  << " Analyzing histograms...";
299  if ( histos_ ) { histos_->histoAnalysis( true ); }
301  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
302  << " Analyzed histograms!";
303  } else {
305  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
306  << " No histogram analysis performed!";
307  }
308 
309  // Create summary plots
310  if ( createSummaryPlots_ ) {
312  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
313  << " Generating summary plots...";
314  std::vector<SummaryPlot>::const_iterator iplot = plots_.begin();
315  for ( ; iplot != plots_.end(); iplot++ ) {
316  if ( histos_ ) {
317  histos_->createSummaryHisto( iplot->monitorable(),
318  iplot->presentation(),
319  iplot->level(),
320  iplot->granularity() );
321  }
322  }
324  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
325  << " Generated summary plots!";
326  } else {
328  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
329  << " No summary plots generated!";
330  }
331 
332  // Save client root file
333  if ( histos_ ) {
334  bool save = parameters_.getUntrackedParameter<bool>( "SaveClientFile", true );
335  if ( save ) { histos_->save( outputFileName_, runNumber_ ); }
336  else {
338  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
339  << " Client file not saved!";
340  }
341  }
342 
343  // Virtual method to trigger the database upload
345 
346  // Print analyses
347  if ( histos_ ) {
349  histos_->printSummary();
350  }
351 
352  // Remove all ME/CME objects
353  if ( histos_ ) { histos_->remove(); }
354 
356  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
357  << " Finished analyzing root file(s)...";
358 
359 }
360 
361 // -----------------------------------------------------------------------------
362 //
364  const edm::EventSetup& setup ) {
365  if ( !(event.id().event()%10) ) {
367  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
368  << " Empty event loop! User can kill job...";
369  }
370 }
371 
372 // -----------------------------------------------------------------------------
373 //
375 
376 // -----------------------------------------------------------------------------
377 //
379 
380  // Check pointer
381  if ( histos_ ) {
383  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
384  << " CommissioningHistogram object already exists!"
385  << " Aborting...";
386  return;
387  }
388 
389  // Check pointer to BEI
390  if ( !bei_ ) {
392  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
393  << " NULL pointer to DQMStore!";
394  return;
395  }
396 
397  // Create "commissioning histograms" object
399  else if ( runType_ == sistrip::FED_CABLING ) { histos_ = new FedCablingHistograms( pset, bei_ ); }
400  else if ( runType_ == sistrip::APV_TIMING ) { histos_ = new ApvTimingHistograms( pset, bei_ ); }
401  else if ( runType_ == sistrip::OPTO_SCAN ) { histos_ = new OptoScanHistograms( pset, bei_ ); }
402  else if ( runType_ == sistrip::VPSP_SCAN ) { histos_ = new VpspScanHistograms( pset, bei_ ); }
403  else if ( runType_ == sistrip::PEDESTALS ) { histos_ = new PedestalsHistograms( pset, bei_ ); }
404  else if ( runType_ == sistrip::PEDS_ONLY ) { histos_ = new PedsOnlyHistograms( pset, bei_ ); }
405  else if ( runType_ == sistrip::NOISE ) { histos_ = new NoiseHistograms( pset, bei_ ); }
406  else if ( runType_ == sistrip::APV_LATENCY ||
408  else if ( runType_ == sistrip::CALIBRATION ||
412  else if ( runType_ == sistrip::UNDEFINED_RUN_TYPE ) {
413  histos_ = 0;
415  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
416  << " Undefined run type!";
417  return;
418  } else if ( runType_ == sistrip::UNKNOWN_RUN_TYPE ) {
419  histos_ = 0;
421  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
422  << " Unknown run type!";
423  return;
424  }
425  histos_->configure(pset,setup);
426 }
427 
428 // -----------------------------------------------------------------------------
429 //
431  const std::string path,
432  uint32_t run_number,
433  bool collate_histos ) {
434 
435  std::string runStr;
436  std::stringstream ss;
437  ss << std::setfill('0') << std::setw(8) << run_number;
438  runStr = ss.str();
439 
440  std::string nameStr = "";
441  if ( !collate_histos ) { nameStr = "SiStripCommissioningClient_"; }
442  else { nameStr = "SiStripCommissioningSource_"; }
443 
444  LogTrace("TEST") << " runStr " << runStr;
445 
446  // Open directory
447  DIR* dp;
448  struct dirent* dirp;
449  if ( (dp = opendir(path.c_str())) == NULL ) {
451  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
452  << " Error locating directory \"" << path
453  << "\". No such directory!";
454  return;
455  }
456 
457  // Find compatible files
458  while ( (dirp = readdir(dp)) != NULL ) {
459  std::string fileName(dirp->d_name);
460  bool goodName = ( fileName.find(nameStr) != std::string::npos );
461  bool goodRun = ( fileName.find(runStr) != std::string::npos );
462  bool rootFile = ( fileName.find(".root") != std::string::npos );
463  //bool rootFile = ( fileName.rfind(".root",5) == fileName.size()-5 );
464  if ( goodName && goodRun && rootFile ) {
465  std::string entry = path;
466  entry += "/";
467  entry += fileName;
468  files.push_back(entry);
469  }
470  }
471  closedir(dp);
472 
473  // Some debug
474  if ( !collate_histos && files.size() > 1 ) {
475  std::stringstream ss;
476  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
477  << " Found more than one client file!";
478  std::vector<std::string>::const_iterator ifile = files.begin();
479  std::vector<std::string>::const_iterator jfile = files.end();
480  for ( ; ifile != jfile; ++ifile ) { ss << std::endl << *ifile; }
481  edm::LogError(mlDqmClient_) << ss.str();
482  } else if ( files.empty() ) {
484  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
485  << " No input files found!" ;
486  }
487 
488 }
489 
static const char runNumber_[]
virtual void analyze(const edm::Event &, const edm::EventSetup &)
EventNumber_t event() const
Definition: EventID.h:41
Map map_
T getUntrackedParameter(std::string const &, T const &) const
static const char dqmClientFileName_[]
void parseXML(const std::string &xml_file)
static const char mlDqmClient_[]
#define NULL
Definition: scimark2.h:8
void save(std::string &filename, uint32_t run_number=0)
uint16_t size_type
virtual void configure(const edm::ParameterSet &, const edm::EventSetup &)
virtual void setInputFiles(std::vector< std::string > &, const std::string, uint32_t, bool)
static std::string runType(const sistrip::RunType &)
Parses the &quot;summary plot&quot; xml configuration file.
void extractHistograms(const std::vector< std::string > &)
static sistrip::RunType runType(DQMStore *const, const std::vector< std::string > &)
virtual void createHistos(const edm::ParameterSet &, const edm::EventSetup &)
SiStripCommissioningOfflineClient(const edm::ParameterSet &)
tuple jfile
Definition: looper.py:278
static uint32_t runNumber(DQMStore *const, const std::vector< std::string > &)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
std::vector< SummaryPlot > summaryPlots(const sistrip::RunType &)
edm::EventID id() const
Definition: EventBase.h:60
list save
Definition: cuy.py:1163
virtual void createSummaryHisto(const sistrip::Monitorable &, const sistrip::Presentation &, const std::string &top_level_dir, const sistrip::Granularity &)
static void copyCustomInformation(DQMStore *const, const std::vector< std::string > &)
volatile std::atomic< bool > shutdown_flag false
static const char collate_[]
void remove(std::string pattern="")
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43
virtual void histoAnalysis(bool debug)