CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQM/EcalBarrelMonitorClient/src/EcalBarrelMonitorClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EcalBarrelMonitorClient.cc
00003  *
00004  * $Date: 2011/09/02 13:55:01 $
00005  * $Revision: 1.504 $
00006  * \author G. Della Ricca
00007  * \author F. Cossutti
00008  *
00009 */
00010 
00011 #include <memory>
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <fstream>
00015 #include <algorithm>
00016 #include <unistd.h>
00017 
00018 #include "FWCore/Framework/interface/Run.h"
00019 #include "FWCore/Framework/interface/LuminosityBlock.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "FWCore/ParameterSet/interface/FileInPath.h"
00024 
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 
00027 #include "DQMServices/Core/interface/MonitorElement.h"
00028 
00029 #include "DQMServices/Core/interface/DQMStore.h"
00030 
00031 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
00032 
00033 #ifdef WITH_ECAL_COND_DB
00034 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00035 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00036 #include "OnlineDB/EcalCondDB/interface/RunDat.h"
00037 #include "OnlineDB/EcalCondDB/interface/MonRunDat.h"
00038 #include "DQM/EcalCommon/interface/LogicID.h"
00039 #endif
00040 
00041 #include "DQM/EcalCommon/interface/Masks.h"
00042 
00043 #include "DQM/EcalCommon/interface/UtilsClient.h"
00044 #include "DQM/EcalCommon/interface/Numbers.h"
00045 
00046 #include "DQM/EcalBarrelMonitorClient/interface/EcalBarrelMonitorClient.h"
00047 
00048 #include "DQM/EcalBarrelMonitorClient/interface/EBIntegrityClient.h"
00049 #include "DQM/EcalBarrelMonitorClient/interface/EBStatusFlagsClient.h"
00050 #include "DQM/EcalBarrelMonitorClient/interface/EBOccupancyClient.h"
00051 #include "DQM/EcalBarrelMonitorClient/interface/EBCosmicClient.h"
00052 #include "DQM/EcalBarrelMonitorClient/interface/EBLaserClient.h"
00053 #include "DQM/EcalBarrelMonitorClient/interface/EBPedestalClient.h"
00054 #include "DQM/EcalBarrelMonitorClient/interface/EBPedestalOnlineClient.h"
00055 #include "DQM/EcalBarrelMonitorClient/interface/EBTestPulseClient.h"
00056 #include "DQM/EcalBarrelMonitorClient/interface/EBBeamCaloClient.h"
00057 #include "DQM/EcalBarrelMonitorClient/interface/EBBeamHodoClient.h"
00058 #include "DQM/EcalBarrelMonitorClient/interface/EBTriggerTowerClient.h"
00059 #include "DQM/EcalBarrelMonitorClient/interface/EBClusterClient.h"
00060 #include "DQM/EcalBarrelMonitorClient/interface/EBTimingClient.h"
00061 
00062 EcalBarrelMonitorClient::EcalBarrelMonitorClient(const edm::ParameterSet& ps) {
00063 
00064   // verbose switch
00065 
00066   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00067 
00068   if ( verbose_ ) {
00069     std::cout << std::endl;
00070     std::cout << " *** Ecal Barrel Generic Monitor Client ***" << std::endl;
00071     std::cout << std::endl;
00072   }
00073 
00074   // DQM ROOT input file
00075 
00076   inputFile_ = ps.getUntrackedParameter<std::string>("inputFile", "");
00077 
00078   if ( verbose_ ) {
00079     if ( inputFile_.size() != 0 ) {
00080       std::cout << " Reading DQM data from inputFile '" << inputFile_ << "'" << std::endl;
00081     }
00082   }
00083 
00084   // Ecal Cond DB
00085 
00086   dbName_ = ps.getUntrackedParameter<std::string>("dbName", "");
00087   dbHostName_ = ps.getUntrackedParameter<std::string>("dbHostName", "");
00088   dbHostPort_ = ps.getUntrackedParameter<int>("dbHostPort", 1521);
00089   dbUserName_ = ps.getUntrackedParameter<std::string>("dbUserName", "");
00090   dbPassword_ = ps.getUntrackedParameter<std::string>("dbPassword", "");
00091 
00092   dbTagName_ = ps.getUntrackedParameter<std::string>("dbTagName", "CMSSW");
00093 
00094   if ( verbose_ ) {
00095     if ( dbName_.size() != 0 ) {
00096       std::cout << " Ecal Cond DB: " << std::endl;
00097       std::cout << "   dbName = '" << dbName_ << "'" << std::endl;
00098       std::cout << "   dbUserName = '" << dbUserName_ << "'" << std::endl;
00099       if ( dbHostName_.size() != 0 ) {
00100         std::cout << "   dbHostName = '" << dbHostName_ << "'" << std::endl;
00101         std::cout << "   dbHostPort = '" << dbHostPort_ << "'" << std::endl;
00102       }
00103       std::cout << "   dbTagName = '" << dbTagName_ << "'" << std::endl;
00104 #ifndef WITH_ECAL_COND_DB
00105       std::cout << std::endl;
00106       std::cout << "WARNING: DB access is NOT available" << std::endl;
00107       std::cout << std::endl;
00108 #endif
00109     } else {
00110       std::cout << " Ecal Cond DB is OFF" << std::endl;
00111     }
00112   }
00113 
00114   // mergeRuns switch
00115 
00116   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00117 
00118   if ( verbose_ ) {
00119     if ( mergeRuns_ ) {
00120       std::cout << " mergeRuns switch is ON" << std::endl;
00121     } else {
00122       std::cout << " mergeRuns switch is OFF" << std::endl;
00123     }
00124   }
00125 
00126   // resetFile
00127 
00128   resetFile_ = ps.getUntrackedParameter<std::string>("resetFile", "");
00129 
00130   if ( verbose_ ) {
00131     if ( resetFile_.size() != 0 ) {
00132       std::cout << " resetFile is '" << resetFile_ << "'" << std::endl;
00133     }
00134   }
00135 
00136   // updateTime
00137 
00138   updateTime_ = ps.getUntrackedParameter<int>("updateTime", 0);
00139 
00140   if ( verbose_ ) {
00141     std::cout << " updateTime is " << updateTime_ << " minute(s)" << std::endl;
00142   }
00143 
00144   // dbUpdateTime
00145 
00146   dbUpdateTime_  = ps.getUntrackedParameter<int>("dbUpdateTime", 0);
00147 
00148   if ( verbose_ ) {
00149     std::cout << " dbUpdateTime is " << dbUpdateTime_ << " minute(s)" << std::endl;
00150   }
00151 
00152   // location
00153 
00154   location_ =  ps.getUntrackedParameter<std::string>("location", "H4");
00155 
00156   if ( verbose_ ) {
00157     std::cout << " location is '" << location_ << "'" << std::endl;
00158   }
00159 
00160   // cloneME switch
00161 
00162   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00163 
00164   if ( verbose_ ) {
00165     if ( cloneME_ ) {
00166       std::cout << " cloneME switch is ON" << std::endl;
00167     } else {
00168       std::cout << " cloneME switch is OFF" << std::endl;
00169     }
00170   }
00171 
00172   // debug switch
00173 
00174   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00175 
00176   if ( verbose_ ) {
00177     if ( debug_ ) {
00178       std::cout << " debug switch is ON" << std::endl;
00179     } else {
00180       std::cout << " debug switch is OFF" << std::endl;
00181     }
00182   }
00183 
00184   // prescaleFactor
00185 
00186   prescaleFactor_ = ps.getUntrackedParameter<int>("prescaleFactor", 1);
00187 
00188   if ( verbose_ ) {
00189     std::cout << " prescaleFactor is " << prescaleFactor_ << std::endl;
00190   }
00191 
00192   // prefixME path
00193 
00194   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00195 
00196   if ( verbose_ ) {
00197     std::cout << " prefixME path is '" << prefixME_ << "'" << std::endl;
00198   }
00199 
00200   // enableCleanup switch
00201 
00202   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00203 
00204   if ( verbose_ ) {
00205     if ( enableCleanup_ ) {
00206       std::cout << " enableCleanup switch is ON" << std::endl;
00207     } else {
00208       std::cout << " enableCleanup switch is OFF" << std::endl;
00209     }
00210   }
00211 
00212   // vector of selected Super Modules (Defaults to all 36).
00213 
00214   superModules_.reserve(36);
00215   for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00216 
00217   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00218 
00219   if ( verbose_ ) {
00220     std::cout << " Selected SMs:" << std::endl;
00221     for ( unsigned int i = 0; i < superModules_.size(); i++ ) {
00222       std::cout << " " << std::setw(2) << std::setfill('0') << superModules_[i];
00223     }
00224     std::cout << std::endl;
00225   }
00226 
00227   // vector of enabled Clients (defaults)
00228 
00229   enabledClients_.push_back("Integrity");
00230   enabledClients_.push_back("StatusFlags");
00231   enabledClients_.push_back("PedestalOnline");
00232   enabledClients_.push_back("Summary");
00233 
00234   enabledClients_ = ps.getUntrackedParameter<std::vector<std::string> >("enabledClients", enabledClients_);
00235 
00236   if ( verbose_ ) {
00237     std::cout << " Enabled Clients:" << std::endl;
00238     for ( unsigned int i = 0; i < enabledClients_.size(); i++ ) {
00239       std::cout << " " << enabledClients_[i];
00240     }
00241     std::cout << std::endl;
00242   }
00243 
00244   // set runTypes (use resize() on purpose!)
00245 
00246   runTypes_.resize(30);
00247   for ( unsigned int i = 0; i < runTypes_.size(); i++ ) runTypes_[i] =  "UNKNOWN";
00248 
00249   runTypes_[EcalDCCHeaderBlock::COSMIC]               = "COSMIC";
00250   runTypes_[EcalDCCHeaderBlock::BEAMH4]               = "BEAM";
00251   runTypes_[EcalDCCHeaderBlock::BEAMH2]               = "BEAM";
00252   runTypes_[EcalDCCHeaderBlock::MTCC]                 = "MTCC";
00253   runTypes_[EcalDCCHeaderBlock::LASER_STD]            = "LASER";
00254   runTypes_[EcalDCCHeaderBlock::LED_STD]              = "LED";
00255   runTypes_[EcalDCCHeaderBlock::TESTPULSE_MGPA]       = "TEST_PULSE";
00256   runTypes_[EcalDCCHeaderBlock::PEDESTAL_STD]         = "PEDESTAL";
00257   runTypes_[EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN] = "PEDESTAL-OFFSET";
00258 
00259   runTypes_[EcalDCCHeaderBlock::COSMICS_GLOBAL]       = "COSMIC";
00260   runTypes_[EcalDCCHeaderBlock::PHYSICS_GLOBAL]       = "PHYSICS";
00261   runTypes_[EcalDCCHeaderBlock::HALO_GLOBAL]          = "HALO";
00262   runTypes_[EcalDCCHeaderBlock::COSMICS_LOCAL]        = "COSMIC";
00263   runTypes_[EcalDCCHeaderBlock::PHYSICS_LOCAL]        = "PHYSICS";
00264   runTypes_[EcalDCCHeaderBlock::HALO_LOCAL]           = "HALO";
00265 
00266   runTypes_[EcalDCCHeaderBlock::LASER_GAP]            = "LASER";
00267   runTypes_[EcalDCCHeaderBlock::LED_GAP]              = "LED";
00268   runTypes_[EcalDCCHeaderBlock::TESTPULSE_GAP]        = "TEST_PULSE";
00269   runTypes_[EcalDCCHeaderBlock::PEDESTAL_GAP]         = "PEDESTAL";
00270 
00271   runTypes_[EcalDCCHeaderBlock::CALIB_LOCAL]          = "CALIB";
00272 
00273   // clients' constructors
00274 
00275   clients_.reserve(12);
00276   clientsNames_.reserve(12);
00277 
00278   if ( find(enabledClients_.begin(), enabledClients_.end(), "Integrity" ) != enabledClients_.end() ) {
00279 
00280     clients_.push_back( new EBIntegrityClient(ps) );
00281     clientsNames_.push_back( "Integrity" );
00282 
00283     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00284     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00285     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00286     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN ));
00287     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00288     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00289     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00290     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00291 
00292     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00293     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00294     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00295     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00296     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00297     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00298     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00299 
00300   }
00301 
00302   if ( find(enabledClients_.begin(), enabledClients_.end(), "StatusFlags" ) != enabledClients_.end() ) {
00303 
00304     clients_.push_back( new EBStatusFlagsClient(ps) );
00305     clientsNames_.push_back( "StatusFlags" );
00306 
00307     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00308     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00309     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00310     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN ));
00311     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00312     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00313     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00314     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00315 
00316     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00317     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00318     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00319     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00320     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00321     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00322     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00323 
00324   }
00325 
00326   if ( find(enabledClients_.begin(), enabledClients_.end(), "Occupancy" ) != enabledClients_.end() ) {
00327 
00328     clients_.push_back( new EBOccupancyClient(ps) );
00329     clientsNames_.push_back( "Occupancy" );
00330 
00331     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00332     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00333     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00334     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN ));
00335     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00336     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00337     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00338     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00339 
00340     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00341     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00342     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00343     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00344     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00345     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00346     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00347 
00348   }
00349 
00350   if ( find(enabledClients_.begin(), enabledClients_.end(), "Cosmic" ) != enabledClients_.end() ) {
00351 
00352     clients_.push_back( new EBCosmicClient(ps) );
00353     clientsNames_.push_back( "Cosmic" );
00354 
00355     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00356     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00357     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00358     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00359     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00360 
00361     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00362     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00363     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00364     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00365     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00366     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00367     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00368 
00369   }
00370 
00371   if ( find(enabledClients_.begin(), enabledClients_.end(), "Laser" ) != enabledClients_.end() ) {
00372 
00373     clients_.push_back( new EBLaserClient(ps) );
00374     clientsNames_.push_back( "Laser" );
00375 
00376     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00377     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00378     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00379     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00380     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00381     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00382     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00383 
00384     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00385     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00386     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00387     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00388     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00389     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00390     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00391 
00392   }
00393 
00394   if ( find(enabledClients_.begin(), enabledClients_.end(), "Pedestal" ) != enabledClients_.end() ) {
00395 
00396     clients_.push_back( new EBPedestalClient(ps) );
00397     clientsNames_.push_back( "Pedestal" );
00398 
00399     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00400     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00401     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00402     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00403     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00404     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00405     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00406 
00407     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00408     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00409     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00410     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00411     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00412     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00413     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00414 
00415   }
00416 
00417   if ( find(enabledClients_.begin(), enabledClients_.end(), "PedestalOnline" ) != enabledClients_.end() ) {
00418 
00419     clients_.push_back( new EBPedestalOnlineClient(ps) );
00420     clientsNames_.push_back( "PedestalOnline" );
00421 
00422     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00423     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00424     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00425     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00426     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00427     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00428     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00429 
00430     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00431     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00432     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00433     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00434     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00435     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00436     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00437 
00438   }
00439 
00440   if ( find(enabledClients_.begin(), enabledClients_.end(), "TestPulse" ) != enabledClients_.end() ) {
00441 
00442     clients_.push_back( new EBTestPulseClient(ps) );
00443     clientsNames_.push_back( "TestPulse" );
00444 
00445     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00446     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00447     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00448     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00449     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00450     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00451     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00452 
00453     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00454     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00455     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00456     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00457     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00458     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00459     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00460 
00461   }
00462 
00463   if ( find(enabledClients_.begin(), enabledClients_.end(), "BeamCalo" ) != enabledClients_.end() ) {
00464 
00465     clients_.push_back( new EBBeamCaloClient(ps) );
00466     clientsNames_.push_back( "BeamCalo" );
00467 
00468     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00469     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00470 
00471   }
00472 
00473   if ( find(enabledClients_.begin(), enabledClients_.end(), "BeamHodo" ) != enabledClients_.end() ) {
00474 
00475     clients_.push_back( new EBBeamHodoClient(ps) );
00476     clientsNames_.push_back( "BeamHodo" );
00477 
00478     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00479     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00480 
00481   }
00482 
00483   if ( find(enabledClients_.begin(), enabledClients_.end(), "TriggerTower" ) != enabledClients_.end() ) {
00484 
00485     clients_.push_back( new EBTriggerTowerClient(ps) );
00486     clientsNames_.push_back( "TriggerTower" );
00487 
00488     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00489     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00490     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00491     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00492     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00493     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00494     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00495 
00496     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00497     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00498     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00499     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00500     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00501     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00502     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00503 
00504   }
00505 
00506   if ( find(enabledClients_.begin(), enabledClients_.end(), "Cluster" ) != enabledClients_.end() ) {
00507 
00508     clients_.push_back( new EBClusterClient(ps) );
00509     clientsNames_.push_back( "Cluster" );
00510 
00511     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00512     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00513     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00514     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00515     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00516     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00517     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00518 
00519     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00520     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00521     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00522     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00523     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00524     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00525     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00526 
00527   }
00528 
00529   if ( find(enabledClients_.begin(), enabledClients_.end(), "Timing" ) != enabledClients_.end() ) {
00530 
00531     clients_.push_back( new EBTimingClient(ps) );
00532     clientsNames_.push_back( "Timing" );
00533 
00534     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMIC ));
00535     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_STD ));
00536     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_STD ));
00537     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_MGPA ));
00538     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH4 ));
00539     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::BEAMH2 ));
00540     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::MTCC ));
00541 
00542     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_GLOBAL ));
00543     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_GLOBAL ));
00544     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::COSMICS_LOCAL ));
00545     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PHYSICS_LOCAL ));
00546     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::LASER_GAP ));
00547     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::TESTPULSE_GAP ));
00548     clientsRuns_.insert(std::pair<EBClient*,int>( clients_.back(), EcalDCCHeaderBlock::PEDESTAL_GAP ));
00549 
00550   }
00551 
00552   // define status bits
00553 
00554   clientsStatus_.insert(std::pair<std::string,int>( "Integrity",       0 ));
00555   clientsStatus_.insert(std::pair<std::string,int>( "Cosmic",          1 ));
00556   clientsStatus_.insert(std::pair<std::string,int>( "Laser",           2 ));
00557   clientsStatus_.insert(std::pair<std::string,int>( "Pedestal",        3 ));
00558   clientsStatus_.insert(std::pair<std::string,int>( "PedestalOnline",  4 ));
00559   clientsStatus_.insert(std::pair<std::string,int>( "TestPulse",       5 ));
00560   clientsStatus_.insert(std::pair<std::string,int>( "BeamCalo",        6 ));
00561   clientsStatus_.insert(std::pair<std::string,int>( "BeamHodo",        7 ));
00562   clientsStatus_.insert(std::pair<std::string,int>( "TriggerTower",    8 ));
00563   clientsStatus_.insert(std::pair<std::string,int>( "Cluster",         9 ));
00564   clientsStatus_.insert(std::pair<std::string,int>( "Timing",         10 ));
00565   clientsStatus_.insert(std::pair<std::string,int>( "Led",            11 ));
00566   clientsStatus_.insert(std::pair<std::string,int>( "StatusFlags",    12 ));
00567   clientsStatus_.insert(std::pair<std::string,int>( "Occupancy",      13 ));
00568 
00569   if ( find(enabledClients_.begin(), enabledClients_.end(), "Summary" ) != enabledClients_.end() ) {
00570 
00571     summaryClient_ = new EBSummaryClient(ps);
00572 
00573   }
00574 
00575   if ( summaryClient_ ) summaryClient_->setFriends(clients_);
00576 
00577   if ( verbose_ ) std::cout << std::endl;
00578 
00579 }
00580 
00581 EcalBarrelMonitorClient::~EcalBarrelMonitorClient() {
00582 
00583   if ( verbose_ ) std::cout << "Exit ..." << std::endl;
00584 
00585   for ( unsigned int i=0; i<clients_.size(); i++ ) {
00586     delete clients_[i];
00587   }
00588 
00589   if ( summaryClient_ ) delete summaryClient_;
00590 
00591 }
00592 
00593 void EcalBarrelMonitorClient::beginJob(void) {
00594 
00595   begin_run_ = false;
00596   end_run_   = false;
00597 
00598   forced_status_ = false;
00599   forced_update_ = false;
00600 
00601   h_ = 0;
00602 
00603   status_  = "unknown";
00604 
00605   run_     = -1;
00606   evt_     = -1;
00607 
00608   runType_ = -1;
00609   evtType_ = -1;
00610 
00611   last_run_ = -1;
00612 
00613   subrun_  = -1;
00614 
00615   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: beginJob" << std::endl;
00616 
00617   ievt_ = 0;
00618   jevt_ = 0;
00619 
00620   current_time_ = time(NULL);
00621   last_time_update_ = current_time_;
00622   last_time_reset_ = current_time_;
00623 
00624   // get hold of back-end interface
00625 
00626   dqmStore_ = edm::Service<DQMStore>().operator->();
00627 
00628   if ( inputFile_.size() != 0 ) {
00629     if ( dqmStore_ ) {
00630       dqmStore_->open(inputFile_);
00631     }
00632   }
00633 
00634   for ( unsigned int i=0; i<clients_.size(); i++ ) {
00635     clients_[i]->beginJob();
00636   }
00637 
00638   if ( summaryClient_ ) summaryClient_->beginJob();
00639 
00640   // summary for DQM GUI
00641 
00642   MonitorElement* me;
00643 
00644   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo" );
00645 
00646   me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummary");
00647   if ( me ) {
00648     dqmStore_->removeElement(me->getName());
00649   }
00650   me = dqmStore_->bookFloat("reportSummary");
00651   me->Fill(-1.0);
00652 
00653   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo/reportSummaryContents" );
00654 
00655   std::string name;
00656   for (int i = 0; i < 36; i++) {
00657     name = "EcalBarrel_" + Numbers::sEB(i+1);
00658     me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryContents/" + name);
00659     if ( me ) {
00660       dqmStore_->removeElement(me->getName());
00661     }
00662     me = dqmStore_->bookFloat(name);
00663     me->Fill(-1.0);
00664   }
00665 
00666   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo" );
00667 
00668   me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryMap");
00669   if ( me ) {
00670     dqmStore_->removeElement(me->getName());
00671   }
00672   me = dqmStore_->book2D("reportSummaryMap","reportSummaryMap", 72, 0., 72., 34, 0., 34);
00673   for ( int iettx = 0; iettx < 34; iettx++ ) {
00674     for ( int ipttx = 0; ipttx < 72; ipttx++ ) {
00675       me->setBinContent( ipttx+1, iettx+1, -1.0 );
00676     }
00677   }
00678   me->setAxisTitle("jphi", 1);
00679   me->setAxisTitle("jeta", 2);
00680 
00681 }
00682 
00683 void EcalBarrelMonitorClient::beginRun(void) {
00684 
00685   begin_run_ = true;
00686   end_run_   = false;
00687 
00688   last_run_  = run_;
00689 
00690   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: beginRun" << std::endl;
00691 
00692   jevt_ = 0;
00693 
00694   current_time_ = time(NULL);
00695   last_time_update_ = current_time_;
00696   last_time_reset_ = current_time_;
00697 
00698   this->setup();
00699 
00700   this->beginRunDb();
00701 
00702   for ( int i=0; i<int(clients_.size()); i++ ) {
00703     clients_[i]->cleanup();
00704     bool done = false;
00705     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00706       if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00707         done = true;
00708         clients_[i]->beginRun();
00709       }
00710     }
00711   }
00712 
00713   if ( summaryClient_ ) summaryClient_->beginRun();
00714 
00715 }
00716 
00717 void EcalBarrelMonitorClient::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00718 
00719   Numbers::initGeometry(c, verbose_);
00720 
00721   if ( verbose_ ) std::cout << std::endl;
00722 
00723   Masks::initMasking(c, verbose_);
00724 
00725   if ( verbose_ ) {
00726     std::cout << std::endl;
00727     std::cout << "Standard beginRun() for run " << r.id().run() << std::endl;
00728     std::cout << std::endl;
00729   }
00730 
00731   run_ = r.id().run();
00732   evt_ = 0;
00733 
00734   jevt_ = 0;
00735 
00736 }
00737 
00738 void EcalBarrelMonitorClient::endJob(void) {
00739 
00740   if ( ! end_run_ ) {
00741 
00742     if ( verbose_ ) {
00743       std::cout << std::endl;
00744       std::cout << "Checking last event at endJob() ... " << std::endl;
00745       std::cout << std::endl;
00746     }
00747 
00748     forced_update_ = true;
00749     this->analyze();
00750 
00751     if ( begin_run_ && ! end_run_ ) {
00752 
00753       if ( verbose_ ) {
00754         std::cout << std::endl;
00755         std::cout << "Forcing endRun() ... " << std::endl;
00756         std::cout << std::endl;
00757       }
00758 
00759       forced_status_ = true;
00760       this->analyze();
00761       this->endRun();
00762 
00763     }
00764 
00765   }
00766 
00767   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: endJob, ievt = " << ievt_ << std::endl;
00768 
00769   this->cleanup();
00770 
00771   for ( unsigned int i=0; i<clients_.size(); i++ ) {
00772     clients_[i]->endJob();
00773   }
00774 
00775   if ( summaryClient_ ) summaryClient_->endJob();
00776 
00777 }
00778 
00779 void EcalBarrelMonitorClient::endRun(void) {
00780 
00781   begin_run_ = false;
00782   end_run_   = true;
00783 
00784   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: endRun, jevt = " << jevt_ << std::endl;
00785 
00786   if ( subrun_ != -1 ) {
00787 
00788     this->writeDb();
00789 
00790     this->endRunDb();
00791 
00792   }
00793 
00794   if ( resetFile_.size() != 0 || dbUpdateTime_ > 0 ) {
00795 
00796     this->softReset(false);
00797 
00798     for ( int i=0; i<int(clients_.size()); i++ ) {
00799       bool done = false;
00800       for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00801         if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00802           done = true;
00803           clients_[i]->analyze();
00804         }
00805       }
00806     }
00807 
00808     if ( summaryClient_ ) summaryClient_->analyze();
00809 
00810   }
00811 
00812   for ( int i=0; i<int(clients_.size()); i++ ) {
00813     bool done = false;
00814     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00815       if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00816         done = true;
00817         clients_[i]->endRun();
00818       }
00819     }
00820   }
00821 
00822   if ( summaryClient_ ) summaryClient_->endRun();
00823 
00824   this->cleanup();
00825 
00826   status_  = "unknown";
00827 
00828   run_     = -1;
00829   evt_     = -1;
00830 
00831   runType_ = -1;
00832   evtType_ = -1;
00833 
00834   subrun_ = -1;
00835 
00836 }
00837 
00838 void EcalBarrelMonitorClient::endRun(const edm::Run& r, const edm::EventSetup& c) {
00839 
00840   if ( verbose_ ) {
00841     std::cout << std::endl;
00842     std::cout << "Standard endRun() for run " << r.id().run() << std::endl;
00843     std::cout << std::endl;
00844   }
00845 
00846   this->analyze();
00847 
00848   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
00849 
00850     forced_update_ = true;
00851     this->analyze();
00852 
00853     if ( ! mergeRuns_ ) {
00854 
00855       if ( begin_run_ && ! end_run_ ) {
00856 
00857         forced_status_ = false;
00858         this->endRun();
00859 
00860       }
00861 
00862     }
00863 
00864   }
00865 
00866   // summary for DQM GUI
00867 
00868   if ( run_ != -1 && evt_ != -1 && runType_ == -1 )  {
00869 
00870     MonitorElement* me;
00871 
00872     me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummary");
00873     if ( me ) me->Fill(-1.0);
00874 
00875     for (int i = 0; i < 36; i++) {
00876       me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryContents/EcalBarrel_" + Numbers::sEB(i+1));
00877       if ( me ) me->Fill(-1.0);
00878     }
00879 
00880     me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryMap");
00881     for ( int iettx = 0; iettx < 34; iettx++ ) {
00882       for ( int ipttx = 0; ipttx < 72; ipttx++ ) {
00883         if ( me ) me->setBinContent( ipttx+1, iettx+1, -1.0 );
00884       }
00885     }
00886 
00887   }
00888 
00889 }
00890 
00891 void EcalBarrelMonitorClient::beginLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c) {
00892 
00893   if ( verbose_ ) {
00894     std::cout << std::endl;
00895     std::cout << "Standard beginLuminosityBlock() for luminosity block " << l.id().luminosityBlock() << " of run " << l.id().run() << std::endl;
00896     std::cout << std::endl;
00897   }
00898 
00899 }
00900 
00901 void EcalBarrelMonitorClient::endLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c) {
00902 
00903   current_time_ = time(NULL);
00904 
00905   if ( verbose_ ) {
00906     std::cout << std::endl;
00907     std::cout << "Standard endLuminosityBlock() for luminosity block " << l.id().luminosityBlock() << " of run " << l.id().run() << std::endl;
00908     std::cout << std::endl;
00909   }
00910 
00911   if ( updateTime_ > 0 ) {
00912     if ( (current_time_ - last_time_update_) < 60 * updateTime_ ) {
00913       return;
00914     }
00915     last_time_update_ = current_time_;
00916   }
00917 
00918   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
00919 
00920     forced_update_ = true;
00921     this->analyze();
00922 
00923   }
00924 
00925 }
00926 
00927 void EcalBarrelMonitorClient::reset(void) {
00928 
00929 }
00930 
00931 void EcalBarrelMonitorClient::setup(void) {
00932 
00933 }
00934 
00935 void EcalBarrelMonitorClient::cleanup(void) {
00936 
00937   if ( ! enableCleanup_ ) return;
00938 
00939   if ( cloneME_ ) {
00940     if ( h_ ) delete h_;
00941   }
00942 
00943   h_ = 0;
00944 
00945 }
00946 
00947 void EcalBarrelMonitorClient::beginRunDb(void) {
00948 
00949   subrun_ = 0;
00950 
00951 #ifdef WITH_ECAL_COND_DB
00952   EcalCondDBInterface* econn;
00953 
00954   econn = 0;
00955 
00956   if ( dbName_.size() != 0 ) {
00957     try {
00958       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
00959       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
00960       if ( verbose_ ) std::cout << "done." << std::endl;
00961     } catch (std::runtime_error &e) {
00962       std::cerr << e.what() << std::endl;
00963       if ( dbHostName_.size() != 0 ) {
00964         try {
00965           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
00966           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
00967           if ( verbose_ ) std::cout << "done." << std::endl;
00968         } catch (std::runtime_error &e) {
00969           std::cerr << e.what() << std::endl;
00970         }
00971       }
00972     }
00973   }
00974 
00975   // create the objects necessary to identify a dataset
00976 
00977   LocationDef locdef;
00978 
00979   locdef.setLocation(location_);
00980 
00981   RunTypeDef rundef;
00982 
00983   rundef.setRunType( this->getRunType() );
00984 
00985   RunTag runtag;
00986 
00987   runtag.setLocationDef(locdef);
00988   runtag.setRunTypeDef(rundef);
00989 
00990   runtag.setGeneralTag( this->getRunType() );
00991 
00992   // fetch the RunIOV from the DB
00993 
00994   bool foundRunIOV = false;
00995 
00996   if ( econn ) {
00997     try {
00998       if ( verbose_ ) std::cout << "Fetching RunIOV ..." << std::endl;
00999 //      runiov_ = econn->fetchRunIOV(&runtag, run_);
01000       runiov_ = econn->fetchRunIOV(location_, run_);
01001       if ( verbose_ ) std::cout << "done." << std::endl;
01002       foundRunIOV = true;
01003     } catch (std::runtime_error &e) {
01004       std::cerr << e.what() << std::endl;
01005       foundRunIOV = false;
01006     }
01007   }
01008 
01009   // begin - setup the RunIOV (on behalf of the DAQ)
01010 
01011   if ( ! foundRunIOV ) {
01012 
01013     Tm startRun;
01014 
01015     startRun.setToCurrentGMTime();
01016 
01017     runiov_.setRunNumber(run_);
01018     runiov_.setRunStart(startRun);
01019     runiov_.setRunTag(runtag);
01020 
01021     if ( econn ) {
01022       try {
01023         if ( verbose_ ) std::cout << "Inserting RunIOV ..." << std::endl;
01024         econn->insertRunIOV(&runiov_);
01025 //        runiov_ = econn->fetchRunIOV(&runtag, run_);
01026         runiov_ = econn->fetchRunIOV(location_, run_);
01027         if ( verbose_ ) std::cout << "done." << std::endl;
01028       } catch (std::runtime_error &e) {
01029         std::cerr << e.what() << std::endl;
01030         try {
01031           if ( verbose_ ) std::cout << "Fetching RunIOV (again) ..." << std::endl;
01032 //          runiov_ = econn->fetchRunIOV(&runtag, run_);
01033           runiov_ = econn->fetchRunIOV(location_, run_);
01034           if ( verbose_ ) std::cout << "done." << std::endl;
01035           foundRunIOV = true;
01036         } catch (std::runtime_error &e) {
01037           std::cerr << e.what() << std::endl;
01038           foundRunIOV = false;
01039         }
01040       }
01041     }
01042 
01043   }
01044 
01045   // end - setup the RunIOV (on behalf of the DAQ)
01046 
01047   if ( verbose_ ) {
01048     std::cout << std::endl;
01049     std::cout << "=============RunIOV:" << std::endl;
01050     std::cout << "Run Number:         " << runiov_.getRunNumber() << std::endl;
01051     std::cout << "Run Start:          " << runiov_.getRunStart().str() << std::endl;
01052     std::cout << "Run End:            " << runiov_.getRunEnd().str() << std::endl;
01053     std::cout << "====================" << std::endl;
01054     std::cout << std::endl;
01055     std::cout << "=============RunTag:" << std::endl;
01056     std::cout << "GeneralTag:         " << runiov_.getRunTag().getGeneralTag() << std::endl;
01057     std::cout << "Location:           " << runiov_.getRunTag().getLocationDef().getLocation() << std::endl;
01058     std::cout << "Run Type:           " << runiov_.getRunTag().getRunTypeDef().getRunType() << std::endl;
01059     std::cout << "====================" << std::endl;
01060     std::cout << std::endl;
01061   }
01062 
01063   std::string rt = runiov_.getRunTag().getRunTypeDef().getRunType();
01064   if ( strcmp(rt.c_str(), "UNKNOWN") == 0 ) {
01065     runType_ = -1;
01066   } else {
01067     for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01068       if ( strcmp(rt.c_str(), runTypes_[i].c_str()) == 0 ) {
01069         if ( runType_ != int(i) ) {
01070           if ( verbose_ ) {
01071             std::cout << std::endl;
01072             std::cout << "Fixing Run Type to: " << runTypes_[i] << std::endl;
01073             std::cout << std::endl;
01074           }
01075           runType_ = i;
01076         }
01077         break;
01078       }
01079     }
01080   }
01081 
01082   if ( verbose_ ) std::cout << std::endl;
01083 
01084   if ( econn ) {
01085     try {
01086       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01087       delete econn;
01088       econn = 0;
01089       if ( verbose_ ) std::cout << "done." << std::endl;
01090     } catch (std::runtime_error &e) {
01091       std::cerr << e.what() << std::endl;
01092     }
01093   }
01094 #endif
01095 
01096   if ( verbose_ ) std::cout << std::endl;
01097 
01098 }
01099 
01100 void EcalBarrelMonitorClient::writeDb(void) {
01101 
01102   subrun_++;
01103 
01104 #ifdef WITH_ECAL_COND_DB
01105   EcalCondDBInterface* econn;
01106 
01107   econn = 0;
01108 
01109   if ( dbName_.size() != 0 ) {
01110     try {
01111       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01112       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01113       if ( verbose_ ) std::cout << "done." << std::endl;
01114     } catch (std::runtime_error &e) {
01115       std::cerr << e.what() << std::endl;
01116       if ( dbHostName_.size() != 0 ) {
01117         try {
01118           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01119           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01120           if ( verbose_ ) std::cout << "done." << std::endl;
01121         } catch (std::runtime_error &e) {
01122           std::cerr << e.what() << std::endl;
01123         }
01124       }
01125     }
01126   }
01127 
01128   MonVersionDef monverdef;
01129 
01130   monverdef.setMonitoringVersion("test01");
01131 
01132   MonRunTag montag;
01133 
01134   montag.setMonVersionDef(monverdef);
01135   montag.setGeneralTag(dbTagName_);
01136 
01137   Tm startSubRun;
01138 
01139   startSubRun.setToCurrentGMTime();
01140 
01141   // fetch the MonIOV from the DB
01142 
01143   bool foundMonIOV = false;
01144 
01145   if ( econn ) {
01146     try {
01147       if ( verbose_ ) std::cout << "Fetching MonIOV ..." << std::endl;
01148       RunTag runtag = runiov_.getRunTag();
01149       moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01150       if ( verbose_ ) std::cout << "done." << std::endl;
01151       foundMonIOV = true;
01152     } catch (std::runtime_error &e) {
01153       std::cerr << e.what() << std::endl;
01154       foundMonIOV = false;
01155     }
01156   }
01157 
01158   // begin - setup the MonIOV
01159 
01160   if ( !foundMonIOV ) {
01161 
01162     moniov_.setRunIOV(runiov_);
01163     moniov_.setSubRunNumber(subrun_);
01164 
01165     if ( subrun_ > 1 ) {
01166       moniov_.setSubRunStart(startSubRun);
01167     } else {
01168       moniov_.setSubRunStart(runiov_.getRunStart());
01169     }
01170 
01171     moniov_.setMonRunTag(montag);
01172 
01173     if ( econn ) {
01174       try {
01175         if ( verbose_ ) std::cout << "Inserting MonIOV ..." << std::endl;
01176         econn->insertMonRunIOV(&moniov_);
01177         RunTag runtag = runiov_.getRunTag();
01178         moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01179         if ( verbose_ ) std::cout << "done." << std::endl;
01180       } catch (std::runtime_error &e) {
01181         std::cerr << e.what() << std::endl;
01182         try {
01183           if ( verbose_ ) std::cout << "Fetching MonIOV (again) ..." << std::endl;
01184           RunTag runtag = runiov_.getRunTag();
01185           moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01186           if ( verbose_ ) std::cout << "done." << std::endl;
01187           foundMonIOV = true;
01188         } catch (std::runtime_error &e) {
01189           std::cerr << e.what() << std::endl;
01190           foundMonIOV = false;
01191         }
01192       }
01193     }
01194 
01195   }
01196 
01197   // end - setup the MonIOV
01198 
01199   if ( verbose_ ) {
01200     std::cout << std::endl;
01201     std::cout << "==========MonRunIOV:" << std::endl;
01202     std::cout << "SubRun Number:      " << moniov_.getSubRunNumber() << std::endl;
01203     std::cout << "SubRun Start:       " << moniov_.getSubRunStart().str() << std::endl;
01204     std::cout << "SubRun End:         " << moniov_.getSubRunEnd().str() << std::endl;
01205     std::cout << "====================" << std::endl;
01206     std::cout << std::endl;
01207     std::cout << "==========MonRunTag:" << std::endl;
01208     std::cout << "GeneralTag:         " << moniov_.getMonRunTag().getGeneralTag() << std::endl;
01209     std::cout << "Monitoring Ver:     " << moniov_.getMonRunTag().getMonVersionDef().getMonitoringVersion() << std::endl;
01210     std::cout << "====================" << std::endl;
01211     std::cout << std::endl;
01212   }
01213 
01214   int taskl = 0x0;
01215   int tasko = 0x0;
01216 
01217   for ( int i=0; i<int(clients_.size()); i++ ) {
01218     bool done = false;
01219     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01220       if ( h_ && runType_ != -1 && runType_ == (*j).second && !done ) {
01221         if ( strcmp(clientsNames_[i].c_str(), "Cosmic") == 0 && runType_ != EcalDCCHeaderBlock::COSMIC && runType_ != EcalDCCHeaderBlock::COSMICS_LOCAL && runType_ != EcalDCCHeaderBlock::COSMICS_GLOBAL && runType_ != EcalDCCHeaderBlock::PHYSICS_GLOBAL && runType_ != EcalDCCHeaderBlock::PHYSICS_LOCAL && h_->GetBinContent(2+EcalDCCHeaderBlock::COSMIC) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::COSMICS_LOCAL) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::COSMICS_GLOBAL) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::PHYSICS_GLOBAL) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::PHYSICS_LOCAL) == 0 ) continue;
01222         if ( strcmp(clientsNames_[i].c_str(), "Laser") == 0 && runType_ != EcalDCCHeaderBlock::LASER_STD && runType_ != EcalDCCHeaderBlock::LASER_GAP && h_->GetBinContent(2+EcalDCCHeaderBlock::LASER_STD) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::LASER_GAP) == 0 ) continue;
01223         if ( strcmp(clientsNames_[i].c_str(), "Pedestal") == 0 && runType_ != EcalDCCHeaderBlock::PEDESTAL_STD && runType_ != EcalDCCHeaderBlock::PEDESTAL_GAP && h_->GetBinContent(2+EcalDCCHeaderBlock::PEDESTAL_STD) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::PEDESTAL_GAP) == 0 ) continue;
01224         if ( strcmp(clientsNames_[i].c_str(), "TestPulse") == 0 && runType_ != EcalDCCHeaderBlock::TESTPULSE_MGPA && runType_ != EcalDCCHeaderBlock::TESTPULSE_GAP && h_->GetBinContent(2+EcalDCCHeaderBlock::TESTPULSE_MGPA) == 0 && h_->GetBinContent(2+EcalDCCHeaderBlock::TESTPULSE_GAP) == 0 ) continue;
01225         done = true;
01226         if ( verbose_ ) {
01227           if ( econn ) {
01228             std::cout << " Writing " << clientsNames_[i] << " results to DB " << std::endl;
01229             std::cout << std::endl;
01230           }
01231         }
01232         bool status;
01233         if ( clients_[i]->writeDb(econn, &runiov_, &moniov_, status) ) {
01234           taskl |= 0x1 << clientsStatus_[clientsNames_[i]];
01235           if ( status ) {
01236             tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01237           }
01238         } else {
01239           tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01240         }
01241       }
01242     }
01243     if ( ((taskl >> clientsStatus_[clientsNames_[i]]) & 0x1) ) {
01244       if ( verbose_ ) {
01245         std::cout << " Task output for " << clientsNames_[i] << " = "
01246              << ((tasko >> clientsStatus_[clientsNames_[i]]) & 0x1) << std::endl;
01247         std::cout << std::endl;
01248       }
01249     }
01250   }
01251 
01252   bool status;
01253   if ( summaryClient_ ) summaryClient_->writeDb(econn, &runiov_, &moniov_, status);
01254 
01255   EcalLogicID ecid;
01256   MonRunDat md;
01257   std::map<EcalLogicID, MonRunDat> dataset;
01258 
01259   MonRunOutcomeDef monRunOutcomeDef;
01260 
01261   monRunOutcomeDef.setShortDesc("success");
01262 
01263   float nevt = -1.;
01264 
01265   if ( h_ ) nevt = h_->GetSumOfWeights();
01266 
01267   md.setNumEvents(int(nevt));
01268   md.setMonRunOutcomeDef(monRunOutcomeDef);
01269 
01270 //  string fileName = "";
01271 //  md.setRootfileName(fileName);
01272 
01273   md.setTaskList(taskl);
01274   md.setTaskOutcome(tasko);
01275 
01276   if ( econn ) {
01277     try {
01278       ecid = LogicID::getEcalLogicID("EB");
01279       dataset[ecid] = md;
01280     } catch (std::runtime_error &e) {
01281       std::cerr << e.what() << std::endl;
01282     }
01283   }
01284 
01285   if ( econn ) {
01286     try {
01287       if ( verbose_ ) std::cout << "Inserting MonRunDat ..." << std::endl;
01288       econn->insertDataSet(&dataset, &moniov_);
01289       if ( verbose_ ) std::cout << "done." << std::endl;
01290     } catch (std::runtime_error &e) {
01291       std::cerr << e.what() << std::endl;
01292     }
01293   }
01294 
01295   if ( econn ) {
01296     try {
01297       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01298       delete econn;
01299       econn = 0;
01300       if ( verbose_ ) std::cout << "done." << std::endl;
01301     } catch (std::runtime_error &e) {
01302       std::cerr << e.what() << std::endl;
01303     }
01304   }
01305 #endif
01306 
01307   if ( verbose_ ) std::cout << std::endl;
01308 
01309 }
01310 
01311 void EcalBarrelMonitorClient::endRunDb(void) {
01312 
01313 #ifdef WITH_ECAL_COND_DB
01314   EcalCondDBInterface* econn;
01315 
01316   econn = 0;
01317 
01318   if ( dbName_.size() != 0 ) {
01319     try {
01320       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01321       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01322       if ( verbose_ ) std::cout << "done." << std::endl;
01323     } catch (std::runtime_error &e) {
01324       std::cerr << e.what() << std::endl;
01325       if ( dbHostName_.size() != 0 ) {
01326         try {
01327           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01328           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01329           if ( verbose_ ) std::cout << "done." << std::endl;
01330         } catch (std::runtime_error &e) {
01331           std::cerr << e.what() << std::endl;
01332         }
01333       }
01334     }
01335   }
01336 
01337   EcalLogicID ecid;
01338   RunDat rd;
01339   std::map<EcalLogicID, RunDat> dataset;
01340 
01341   float nevt = -1.;
01342 
01343   if ( h_ ) nevt = h_->GetSumOfWeights();
01344 
01345   rd.setNumEvents(int(nevt));
01346 
01347   // fetch the RunDat from the DB
01348 
01349   bool foundRunDat = false;
01350 
01351   if ( econn ) {
01352     try {
01353       if ( verbose_ ) std::cout << "Fetching RunDat ..." << std::endl;
01354       econn->fetchDataSet(&dataset, &runiov_);
01355       if ( verbose_ ) std::cout << "done." << std::endl;
01356       foundRunDat = true;
01357     } catch (std::runtime_error &e) {
01358       std::cerr << e.what() << std::endl;
01359       foundRunDat = false;
01360     }
01361   }
01362 
01363   // begin - setup the RunDat (on behalf of the DAQ)
01364 
01365   if ( ! foundRunDat ) {
01366 
01367     if ( econn ) {
01368       try {
01369         ecid = LogicID::getEcalLogicID("EB");
01370         dataset[ecid] = rd;
01371       } catch (std::runtime_error &e) {
01372         std::cerr << e.what() << std::endl;
01373       }
01374     }
01375 
01376     if ( econn ) {
01377       try {
01378         if ( verbose_ ) std::cout << "Inserting RunDat ..." << std::endl;
01379         econn->insertDataSet(&dataset, &runiov_);
01380         if ( verbose_ ) std::cout << "done." << std::endl;
01381       } catch (std::runtime_error &e) {
01382         std::cerr << e.what() << std::endl;
01383       }
01384     }
01385 
01386   }
01387 
01388   // end - setup the RunDat (on behalf of the DAQ)
01389 
01390   if ( econn ) {
01391     try {
01392       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01393       delete econn;
01394       econn = 0;
01395       if ( verbose_ ) std::cout << "done." << std::endl;
01396     } catch (std::runtime_error &e) {
01397       std::cerr << e.what() << std::endl;
01398     }
01399   }
01400 #endif
01401 
01402 }
01403 
01404 void EcalBarrelMonitorClient::analyze(void) {
01405 
01406   current_time_ = time(NULL);
01407 
01408   ievt_++;
01409   jevt_++;
01410 
01411   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
01412 
01413   MonitorElement* me;
01414   std::string s;
01415 
01416   me = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
01417   if ( me ) {
01418     status_ = "unknown";
01419     s = me->valueString();
01420     if ( strcmp(s.c_str(), "i=0") == 0 ) status_ = "begin-of-run";
01421     if ( strcmp(s.c_str(), "i=1") == 0 ) status_ = "running";
01422     if ( strcmp(s.c_str(), "i=2") == 0 ) status_ = "end-of-run";
01423     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/STATUS'" << std::endl;
01424   }
01425 
01426   if ( inputFile_.size() != 0 ) {
01427     if ( ievt_ == 1 ) {
01428       if ( verbose_ ) {
01429         std::cout << std::endl;
01430         std::cout << " Reading DQM from file, forcing 'begin-of-run'" << std::endl;
01431         std::cout << std::endl;
01432       }
01433       status_ = "begin-of-run";
01434     }
01435   }
01436 
01437   int ecal_run = -1;
01438   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
01439   if ( me ) {
01440     s = me->valueString();
01441     sscanf(s.c_str(), "i=%d", &ecal_run);
01442     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUN'" << std::endl;
01443   }
01444 
01445   int ecal_evt = -1;
01446   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
01447   if ( me ) {
01448     s = me->valueString();
01449     sscanf(s.c_str(), "i=%d", &ecal_evt);
01450     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/EVT'" << std::endl;
01451   }
01452 
01453   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01454   h_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, h_ );
01455 
01456   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUNTYPE");
01457   if ( me ) {
01458     s = me->valueString();
01459     sscanf(s.c_str(), "i=%d", &evtType_);
01460     if ( runType_ == -1 ) runType_ = evtType_;
01461     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUNTYPE'" << std::endl;
01462   }
01463 
01464   // if the run number from the Event is less than zero,
01465   // use the run number from the ECAL DCC header
01466   if ( run_ <= 0 ) run_ = ecal_run;
01467 
01468   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01469     if ( ! mergeRuns_ && run_ != last_run_ ) forced_update_ = true;
01470   }
01471 
01472   bool update = ( forced_update_                    ) ||
01473                 ( prescaleFactor_ != 1              ) ||
01474                 ( jevt_ <   10                      ) ||
01475                 ( jevt_ <  100 && jevt_ %   10 == 0 ) ||
01476                 ( jevt_ < 1000 && jevt_ %  100 == 0 ) ||
01477                 (                 jevt_ % 1000 == 0 );
01478 
01479   if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01480 
01481     if ( verbose_ ) {
01482       std::cout << " RUN status = \"" << status_ << "\"" << std::endl;
01483       std::cout << "   CMS run/event number = " << run_ << "/" << evt_ << std::endl;
01484       std::cout << "   EB run/event number = " << ecal_run << "/" << ecal_evt << std::endl;
01485       std::cout << "   EB location = " << location_ << std::endl;
01486       std::cout << "   EB run/event type = " << this->getRunType() << "/" << ( evtType_ == -1 ? "UNKNOWN" : runTypes_[evtType_] ) << std::flush;
01487 
01488       if ( h_ ) {
01489         if ( h_->GetSumOfWeights() != 0 ) {
01490           std::cout << " ( " << std::flush;
01491           for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01492             if ( strcmp(runTypes_[i].c_str(), "UNKNOWN") != 0 && h_->GetBinContent(2+i) != 0 ) {
01493               std::string s = runTypes_[i];
01494               transform( s.begin(), s.end(), s.begin(), (int(*)(int))tolower );
01495               std::cout << s << " ";
01496             }
01497           }
01498           std::cout << ")" << std::flush;
01499         }
01500       }
01501       std::cout << std::endl;
01502     }
01503 
01504   }
01505 
01506   if ( strcmp(status_.c_str(), "begin-of-run") == 0 ) {
01507 
01508     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01509 
01510       if ( ! begin_run_ ) {
01511 
01512         forced_status_ = false;
01513         this->beginRun();
01514 
01515       }
01516 
01517     }
01518 
01519   }
01520 
01521   if ( strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "running") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01522 
01523     if ( begin_run_ && ! end_run_ ) {
01524 
01525       bool update = ( forced_update_                      ) ||
01526                     ( prescaleFactor_ != 1                ) ||
01527                     ( jevt_ <     3                       ) ||
01528                     ( jevt_ <  1000 && jevt_ %   100 == 0 ) ||
01529                     ( jevt_ < 10000 && jevt_ %  1000 == 0 ) ||
01530                     (                  jevt_ % 10000 == 0 );
01531 
01532       if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01533 
01534         for ( int i=0; i<int(clients_.size()); i++ ) {
01535           bool done = false;
01536           for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01537             if ( runType_ != -1 && runType_ == (*j).second && !done ) {
01538               done = true;
01539               clients_[i]->analyze();
01540             }
01541           }
01542         }
01543 
01544         if ( summaryClient_ ) summaryClient_->analyze();
01545 
01546       }
01547 
01548       forced_update_ = false;
01549 
01550       bool reset = false;
01551 
01552       if ( resetFile_.size() != 0 ) {
01553         if ( access(resetFile_.c_str(), W_OK) == 0 ) {
01554           if ( unlink(resetFile_.c_str()) == 0 ) {
01555             reset |= true;
01556           }
01557         }
01558       }
01559 
01560       if ( dbUpdateTime_ > 0 ) {
01561         reset |= (current_time_ - last_time_reset_) > 60 * dbUpdateTime_;
01562       }
01563 
01564       if ( reset ) {
01565         if ( runType_ == EcalDCCHeaderBlock::COSMIC ||
01566              runType_ == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
01567              runType_ == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
01568              runType_ == EcalDCCHeaderBlock::COSMICS_LOCAL ||
01569              runType_ == EcalDCCHeaderBlock::PHYSICS_LOCAL ||
01570              runType_ == EcalDCCHeaderBlock::BEAMH2 ||
01571              runType_ == EcalDCCHeaderBlock::BEAMH4 ) this->writeDb();
01572         this->softReset(true);
01573         last_time_reset_ = current_time_;
01574       }
01575 
01576     }
01577 
01578   }
01579 
01580   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01581 
01582     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01583 
01584       if ( begin_run_ && ! end_run_ ) {
01585 
01586         forced_status_ = false;
01587         this->endRun();
01588 
01589       }
01590 
01591     }
01592 
01593   }
01594 
01595   // BEGIN: run-time fixes for missing state transitions
01596 
01597   // run number transition
01598 
01599   if ( strcmp(status_.c_str(), "running") == 0 ) {
01600 
01601     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01602 
01603       if ( ! mergeRuns_ ) {
01604 
01605         int new_run_ = run_;
01606         int old_run_ = last_run_;
01607 
01608         if ( new_run_ != old_run_ ) {
01609 
01610           if ( begin_run_ && ! end_run_ ) {
01611 
01612             if ( verbose_ ) {
01613               std::cout << std::endl;
01614               std::cout << " Old run has finished, issuing endRun() ... " << std::endl;
01615               std::cout << std::endl;
01616             }
01617 
01618             // end old_run_
01619             run_ = old_run_;
01620 
01621             forced_status_ = false;
01622             this->endRun();
01623 
01624           }
01625 
01626           if ( ! begin_run_ ) {
01627 
01628             if ( verbose_ ) {
01629               std::cout << std::endl;
01630               std::cout << " New run has started, issuing beginRun() ... " << std::endl;
01631               std::cout << std::endl;
01632             }
01633 
01634             // start new_run_
01635             run_ = new_run_;
01636 
01637             forced_status_ = false;
01638             this->beginRun();
01639 
01640           }
01641 
01642         }
01643 
01644       }
01645 
01646     }
01647 
01648   }
01649 
01650   // 'running' state without a previous 'begin-of-run' state
01651 
01652   if ( strcmp(status_.c_str(), "running") == 0 ) {
01653 
01654     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01655 
01656       if ( ! forced_status_ ) {
01657 
01658         if ( ! begin_run_ ) {
01659 
01660           if ( verbose_ ) {
01661             std::cout << std::endl;
01662             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01663             std::cout << std::endl;
01664           }
01665 
01666           forced_status_ = true;
01667           this->beginRun();
01668 
01669         }
01670 
01671       }
01672 
01673     }
01674 
01675   }
01676 
01677   // 'end-of-run' state without a previous 'begin-of-run' or 'running' state
01678 
01679   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01680 
01681     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01682 
01683       if ( ! forced_status_ ) {
01684 
01685         if ( ! begin_run_ ) {
01686 
01687           if ( verbose_ ) {
01688             std::cout << std::endl;
01689             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01690             std::cout << std::endl;
01691           }
01692 
01693           forced_status_ = true;
01694           this->beginRun();
01695 
01696         }
01697 
01698       }
01699 
01700     }
01701 
01702   }
01703 
01704   // END: run-time fixes for missing state transitions
01705 
01706 }
01707 
01708 void EcalBarrelMonitorClient::analyze(const edm::Event& e, const edm::EventSetup& c) {
01709 
01710   run_ = e.id().run();
01711   evt_ = e.id().event();
01712 
01713   if ( prescaleFactor_ > 0 ) {
01714     if ( jevt_ % prescaleFactor_ == 0 ) this->analyze();
01715   }
01716 
01717 }
01718 
01719 void EcalBarrelMonitorClient::softReset(bool flag) {
01720 
01721   std::vector<MonitorElement*> mes = dqmStore_->getAllContents(prefixME_);
01722   std::vector<MonitorElement*>::const_iterator meitr;
01723   for ( meitr=mes.begin(); meitr!=mes.end(); meitr++ ) {
01724     if ( !strncmp((*meitr)->getName().c_str(), "EB", 2)
01725          && strncmp((*meitr)->getName().c_str(), "EBTrend", 7)
01726          && strncmp((*meitr)->getName().c_str(), "by lumi", 7) ) {
01727       if ( flag ) {
01728         dqmStore_->softReset(*meitr);
01729       } else {
01730         dqmStore_->disableSoftReset(*meitr);
01731       }
01732     }
01733   }
01734 
01735   MonitorElement* me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01736   if ( me ) {
01737     if ( flag ) {
01738       dqmStore_->softReset(me);
01739     } else {
01740       dqmStore_->disableSoftReset(me);
01741     }
01742   }
01743 
01744 }
01745