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 // Last commit: $Id: SiStripCommissioningOfflineClient.cc,v 1.44 2010/01/04 16:47:06 lowette Exp $
2 
22 #include <boost/cstdint.hpp>
23 #include <iostream>
24 #include <iomanip>
25 #include <fstream>
26 #include <sstream>
27 #include <sys/types.h>
28 #include <dirent.h>
29 #include <errno.h>
30 #include "TProfile.h"
31 
32 using namespace sistrip;
33 
34 // -----------------------------------------------------------------------------
35 //
37  : bei_( edm::Service<DQMStore>().operator->() ),
38  histos_(0),
39  //inputFiles_( pset.getUntrackedParameter< std::vector<std::string> >( "InputRootFiles", std::vector<std::string>() ) ),
40  outputFileName_( pset.getUntrackedParameter<std::string>( "OutputRootFile", "" ) ),
41  collateHistos_( !pset.getUntrackedParameter<bool>( "UseClientFile", false ) ),
42  analyzeHistos_( pset.getUntrackedParameter<bool>( "AnalyzeHistos", true ) ),
43  xmlFile_( (pset.getUntrackedParameter<edm::FileInPath>( "SummaryXmlFile", edm::FileInPath() )).fullPath() ),
44  createSummaryPlots_( false ),
45  clientHistos_( false ),
46  uploadToDb_( false ),
47  runType_(sistrip::UNKNOWN_RUN_TYPE),
48  runNumber_(0),
49  map_(),
50  plots_(),
51  parameters_(pset)
52 {
54  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
55  << " Constructing object...";
57  pset.getUntrackedParameter<std::string>( "FilePath" ),
58  pset.getUntrackedParameter<uint32_t>("RunNumber"),
60 }
61 
62 // -----------------------------------------------------------------------------
63 //
66  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
67  << " Destructing object...";
68 }
69 
70 // -----------------------------------------------------------------------------
71 //
74  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
75  << " Analyzing root file(s)...";
76 
77  // Check for null pointer
78  if ( !bei_ ) {
80  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
81  << " NULL pointer to DQMStore!"
82  << " Aborting...";
83  return;
84  }
85  bei_->setVerbose(0);
86 
87  // Check if .root file can be opened
88  std::vector<std::string>::const_iterator ifile = inputFiles_.begin();
89  for ( ; ifile != inputFiles_.end(); ifile++ ) {
90  ifstream root_file;
91  root_file.open( ifile->c_str() );
92  if( !root_file.is_open() ) {
94  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
95  << " The input root file \"" << *ifile
96  << "\" could not be opened!"
97  << " Please check the path and filename!";
98  } else {
99  root_file.close();
101  if ( found != std::string::npos && clientHistos_ ) {
103  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
104  << " The input root files appear to be a mixture"
105  << " of \"Source\" and \"Client\" files!"
106  << " Aborting...";
107  return;
108  }
109  if ( found != std::string::npos && inputFiles_.size() != 1 ) {
111  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
112  << " There appear to be multiple input \"Client\" root files!"
113  << " Aborting...";
114  return;
115  }
116  if ( found != std::string::npos ) { clientHistos_ = true; }
117  }
118  }
119  if ( clientHistos_ && inputFiles_.size() == 1 ) {
121  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
122  << " Collated histograms found in input root file \""
123  << inputFiles_[0] << "\"";
124  }
125 
126  // Check if .xml file can be opened
127  if ( !xmlFile_.empty() ) {
128  ifstream xml_file;
129  xml_file.open( xmlFile_.c_str() );
130  if( !xml_file.is_open() ) {
132  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
133  << " The SummaryPlot XML file \"" << xmlFile_
134  << "\" could not be opened!"
135  << " Please check the path and filename!"
136  << " Aborting...";
137  return;
138  } else {
139  createSummaryPlots_ = true;
140  xml_file.close();
141  }
142  }
143 
144  // Open root file(s) and create ME's
145  if ( inputFiles_.empty() ) {
147  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
148  << " No input root files specified!";
149  return;
150  }
151 
153  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
154  << " Opening root files. This may take some time!...";
155  std::vector<std::string>::const_iterator jfile = inputFiles_.begin();
156  for ( ; jfile != inputFiles_.end(); jfile++ ) {
158  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
159  << " Opening root file \"" << *jfile
160  << "\"... (This may take some time.)";
161  if ( clientHistos_ ) {
162  bei_->open( *jfile, false, sistrip::collate_, "" );
163  } else {
164  bei_->open( *jfile, false, "SiStrip", sistrip::collate_ );
165  }
167  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
168  << " Opened root file \"" << *jfile << "\"!";
169  }
171  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
172  << " Opened " << inputFiles_.size() << " root files!";
173 
174  // Retrieve list of histograms
175  std::vector<std::string> contents;
176  bei_->getContents( contents );
177 
178  // If using client file, remove "source" histograms from list
179  if ( clientHistos_ ) {
180  std::vector<std::string> temp;
181  std::vector<std::string>::iterator istr = contents.begin();
182  for ( ; istr != contents.end(); istr++ ) {
183  if ( istr->find(sistrip::collate_) != std::string::npos ) {
184  temp.push_back( *istr );
185  }
186  }
187  contents.clear();
188  contents = temp;
189  }
190 
191  // Some debug
193  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
194  << " Found " << contents.size()
195  << " directories containing MonitorElements";
196 
197  // Some more debug
198  if (0) {
199  std::stringstream ss;
200  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
201  << " Directories found: " << std::endl;
202  std::vector<std::string>::iterator istr = contents.begin();
203  for ( ; istr != contents.end(); istr++ ) { ss << " " << *istr << std::endl; }
204  LogTrace(mlDqmClient_) << ss.str();
205  }
206 
207  // Extract run type from contents
209 
210  // Extract run number from contents
212 
213  // Copy custom information to the collated structure
215 
216  // Check runType
219  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
220  << " Unknown commissioning runType: "
222  << " and run number is " << runNumber_;
223  return;
224  } else {
226  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
227  << " Run type is "
229  << " and run number is " << runNumber_;
230  }
231 
232  // Open and parse "summary plot" xml file
233  if ( createSummaryPlots_ ) {
235  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
236  << " Parsing summary plot XML file...";
237  SummaryPlotXmlParser xml_file;
238  xml_file.parseXML(xmlFile_);
239  plots_ = xml_file.summaryPlots(runType_);
241  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
242  << " Parsed summary plot XML file and found "
243  << plots_.size() << " plots defined!";
244  } else {
246  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
247  << " Null string for SummaryPlotXmlFile!"
248  << " No summary plots will be created!";
249  }
250 
251  // Some debug
252  std::stringstream ss;
253  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]" << std::endl
254  << " Input root files : ";
255  if ( inputFiles_.empty() ) { ss << "(none)"; }
256  else {
257  std::vector<std::string>::const_iterator ifile = inputFiles_.begin();
258  for ( ; ifile != inputFiles_.end(); ifile++ ) {
259  if ( ifile != inputFiles_.begin() ) {
260  ss << std::setw(25) << std::setfill(' ') << ": ";
261  }
262  ss << "\"" << *ifile << "\"" << std::endl;
263  }
264  }
265  ss << " Run type : \""
266  << SiStripEnumsAndStrings::runType( runType_ ) << "\"" << std::endl
267  << " Run number : " << runNumber_ << std::endl
268  << " Summary plot XML file : ";
269  if ( xmlFile_.empty() ) { ss << "(none)"; }
270  else { ss << "\"" << xmlFile_ << "\""; }
271  edm::LogVerbatim(mlDqmClient_) << ss.str();
272 
273  // Virtual method that creates CommissioningHistogram object
275  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
276  << " Creating CommissioningHistogram object...";
277  createHistos(parameters_, setup);
278  if ( histos_ ) {
280  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
281  << " Created CommissioningHistogram object!";
282  } else {
284  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
285  << " NULL pointer to CommissioningHistogram object!"
286  << " Aborting...";
287  return;
288  }
289 
290  // Perform collation
291  if ( histos_ ) {
292  histos_->extractHistograms( contents );
293  }
294 
295  // Perform analysis
296  if ( analyzeHistos_ ) {
298  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
299  << " Analyzing histograms...";
300  if ( histos_ ) { histos_->histoAnalysis( true ); }
302  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
303  << " Analyzed histograms!";
304  } else {
306  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
307  << " No histogram analysis performed!";
308  }
309 
310  // Create summary plots
311  if ( createSummaryPlots_ ) {
313  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
314  << " Generating summary plots...";
315  std::vector<SummaryPlot>::const_iterator iplot = plots_.begin();
316  for ( ; iplot != plots_.end(); iplot++ ) {
317  if ( histos_ ) {
318  histos_->createSummaryHisto( iplot->monitorable(),
319  iplot->presentation(),
320  iplot->level(),
321  iplot->granularity() );
322  }
323  }
325  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
326  << " Generated summary plots!";
327  } else {
329  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
330  << " No summary plots generated!";
331  }
332 
333  // Save client root file
334  if ( histos_ ) {
335  bool save = parameters_.getUntrackedParameter<bool>( "SaveClientFile", true );
336  if ( save ) { histos_->save( outputFileName_, runNumber_ ); }
337  else {
339  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
340  << " Client file not saved!";
341  }
342  }
343 
344  // Virtual method to trigger the database upload
346 
347  // Print analyses
348  if ( histos_ ) {
350  histos_->printSummary();
351  }
352 
353  // Remove all ME/CME objects
354  if ( histos_ ) { histos_->remove(); }
355 
357  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
358  << " Finished analyzing root file(s)...";
359 
360 }
361 
362 // -----------------------------------------------------------------------------
363 //
365  const edm::EventSetup& setup ) {
366  if ( !(event.id().event()%10) ) {
368  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
369  << " Empty event loop! User can kill job...";
370  }
371 }
372 
373 // -----------------------------------------------------------------------------
374 //
376 
377 // -----------------------------------------------------------------------------
378 //
380 
381  // Check pointer
382  if ( histos_ ) {
384  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
385  << " CommissioningHistogram object already exists!"
386  << " Aborting...";
387  return;
388  }
389 
390  // Check pointer to BEI
391  if ( !bei_ ) {
393  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
394  << " NULL pointer to DQMStore!";
395  return;
396  }
397 
398  // Create "commissioning histograms" object
400  else if ( runType_ == sistrip::FED_CABLING ) { histos_ = new FedCablingHistograms( pset, bei_ ); }
401  else if ( runType_ == sistrip::APV_TIMING ) { histos_ = new ApvTimingHistograms( pset, bei_ ); }
402  else if ( runType_ == sistrip::OPTO_SCAN ) { histos_ = new OptoScanHistograms( pset, bei_ ); }
403  else if ( runType_ == sistrip::VPSP_SCAN ) { histos_ = new VpspScanHistograms( pset, bei_ ); }
404  else if ( runType_ == sistrip::PEDESTALS ) { histos_ = new PedestalsHistograms( pset, bei_ ); }
405  else if ( runType_ == sistrip::PEDS_ONLY ) { histos_ = new PedsOnlyHistograms( pset, bei_ ); }
406  else if ( runType_ == sistrip::NOISE ) { histos_ = new NoiseHistograms( pset, bei_ ); }
407  else if ( runType_ == sistrip::APV_LATENCY ||
409  else if ( runType_ == sistrip::CALIBRATION ||
413  else if ( runType_ == sistrip::UNDEFINED_RUN_TYPE ) {
414  histos_ = 0;
416  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
417  << " Undefined run type!";
418  return;
419  } else if ( runType_ == sistrip::UNKNOWN_RUN_TYPE ) {
420  histos_ = 0;
422  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
423  << " Unknown run type!";
424  return;
425  }
426  histos_->configure(pset,setup);
427 }
428 
429 // -----------------------------------------------------------------------------
430 //
432  const std::string path,
433  uint32_t run_number,
434  bool collate_histos ) {
435 
436  std::string runStr;
437  std::stringstream ss;
438  ss << std::setfill('0') << std::setw(8) << run_number;
439  runStr = ss.str();
440 
441  std::string nameStr = "";
442  if ( !collate_histos ) { nameStr = "SiStripCommissioningClient_"; }
443  else { nameStr = "SiStripCommissioningSource_"; }
444 
445  LogTrace("TEST") << " runStr " << runStr;
446 
447  // Open directory
448  DIR* dp;
449  struct dirent* dirp;
450  if ( (dp = opendir(path.c_str())) == NULL ) {
452  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
453  << " Error locating directory \"" << path
454  << "\". No such directory!";
455  return;
456  }
457 
458  // Find compatible files
459  while ( (dirp = readdir(dp)) != NULL ) {
460  std::string fileName(dirp->d_name);
461  bool goodName = ( fileName.find(nameStr) != std::string::npos );
462  bool goodRun = ( fileName.find(runStr) != std::string::npos );
463  bool rootFile = ( fileName.find(".root") != std::string::npos );
464  //bool rootFile = ( fileName.rfind(".root",5) == fileName.size()-5 );
465  if ( goodName && goodRun && rootFile ) {
466  std::string entry = path;
467  entry += "/";
468  entry += fileName;
469  files.push_back(entry);
470  }
471  }
472  closedir(dp);
473 
474  // Some debug
475  if ( !collate_histos && files.size() > 1 ) {
476  std::stringstream ss;
477  ss << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
478  << " Found more than one client file!";
479  std::vector<std::string>::const_iterator ifile = files.begin();
480  std::vector<std::string>::const_iterator jfile = files.end();
481  for ( ; ifile != jfile; ++ifile ) { ss << std::endl << *ifile; }
482  edm::LogError(mlDqmClient_) << ss.str();
483  } else if ( files.empty() ) {
485  << "[SiStripCommissioningOfflineClient::" << __func__ << "]"
486  << " No input files found!" ;
487  }
488 
489 }
490 
static const char runNumber_[]
virtual void analyze(const edm::Event &, const edm::EventSetup &)
EventNumber_t event() const
Definition: EventID.h:44
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 &)
tuple files
Definition: linker.py:146
list path
Definition: scaleCards.py:51
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 > &)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
virtual void createHistos(const edm::ParameterSet &, const edm::EventSetup &)
SiStripCommissioningOfflineClient(const edm::ParameterSet &)
static uint32_t runNumber(DQMStore *const, const std::vector< std::string > &)
void setVerbose(unsigned level)
Definition: DQMStore.cc:393
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
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1497
#define LogTrace(id)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
list DIR
Definition: linker.py:124
std::vector< SummaryPlot > summaryPlots(const sistrip::RunType &)
edm::EventID id() const
Definition: EventBase.h:56
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 > &)
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:2432
static const char collate_[]
void remove(std::string pattern="")
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:33
virtual void histoAnalysis(bool debug)