CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalBarrelMonitorClient/src/EcalBarrelMonitorClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EcalBarrelMonitorClient.cc
00003  *
00004  * $Date: 2010/11/10 16:52:35 $
00005  * $Revision: 1.503 $
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   char histo[200];
00643 
00644   MonitorElement* me;
00645 
00646   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo" );
00647 
00648   sprintf(histo, "reportSummary");
00649   me = dqmStore_->get(prefixME_ + "/EventInfo/" + histo);
00650   if ( me ) {
00651     dqmStore_->removeElement(me->getName());
00652   }
00653   me = dqmStore_->bookFloat(histo);
00654   me->Fill(-1.0);
00655 
00656   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo/reportSummaryContents" );
00657 
00658   for (int i = 0; i < 36; i++) {
00659     sprintf(histo, "EcalBarrel_%s", Numbers::sEB(i+1).c_str());
00660     me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryContents/" + histo);
00661     if ( me ) {
00662       dqmStore_->removeElement(me->getName());
00663     }
00664     me = dqmStore_->bookFloat(histo);
00665     me->Fill(-1.0);
00666   }
00667 
00668   dqmStore_->setCurrentFolder( prefixME_ + "/EventInfo" );
00669 
00670   sprintf(histo, "reportSummaryMap");
00671   me = dqmStore_->get(prefixME_ + "/EventInfo/" + histo);
00672   if ( me ) {
00673     dqmStore_->removeElement(me->getName());
00674   }
00675   me = dqmStore_->book2D(histo, histo, 72, 0., 72., 34, 0., 34);
00676   for ( int iettx = 0; iettx < 34; iettx++ ) {
00677     for ( int ipttx = 0; ipttx < 72; ipttx++ ) {
00678       me->setBinContent( ipttx+1, iettx+1, -1.0 );
00679     }
00680   }
00681   me->setAxisTitle("jphi", 1);
00682   me->setAxisTitle("jeta", 2);
00683 
00684 }
00685 
00686 void EcalBarrelMonitorClient::beginRun(void) {
00687 
00688   begin_run_ = true;
00689   end_run_   = false;
00690 
00691   last_run_  = run_;
00692 
00693   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: beginRun" << std::endl;
00694 
00695   jevt_ = 0;
00696 
00697   current_time_ = time(NULL);
00698   last_time_update_ = current_time_;
00699   last_time_reset_ = current_time_;
00700 
00701   this->setup();
00702 
00703   this->beginRunDb();
00704 
00705   for ( int i=0; i<int(clients_.size()); i++ ) {
00706     clients_[i]->cleanup();
00707     bool done = false;
00708     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00709       if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00710         done = true;
00711         clients_[i]->beginRun();
00712       }
00713     }
00714   }
00715 
00716   if ( summaryClient_ ) summaryClient_->beginRun();
00717 
00718 }
00719 
00720 void EcalBarrelMonitorClient::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00721 
00722   Numbers::initGeometry(c, verbose_);
00723 
00724   if ( verbose_ ) std::cout << std::endl;
00725 
00726   Masks::initMasking(c, verbose_);
00727 
00728   if ( verbose_ ) {
00729     std::cout << std::endl;
00730     std::cout << "Standard beginRun() for run " << r.id().run() << std::endl;
00731     std::cout << std::endl;
00732   }
00733 
00734   run_ = r.id().run();
00735   evt_ = 0;
00736 
00737   jevt_ = 0;
00738 
00739 }
00740 
00741 void EcalBarrelMonitorClient::endJob(void) {
00742 
00743   if ( ! end_run_ ) {
00744 
00745     if ( verbose_ ) {
00746       std::cout << std::endl;
00747       std::cout << "Checking last event at endJob() ... " << std::endl;
00748       std::cout << std::endl;
00749     }
00750 
00751     forced_update_ = true;
00752     this->analyze();
00753 
00754     if ( begin_run_ && ! end_run_ ) {
00755 
00756       if ( verbose_ ) {
00757         std::cout << std::endl;
00758         std::cout << "Forcing endRun() ... " << std::endl;
00759         std::cout << std::endl;
00760       }
00761 
00762       forced_status_ = true;
00763       this->analyze();
00764       this->endRun();
00765 
00766     }
00767 
00768   }
00769 
00770   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: endJob, ievt = " << ievt_ << std::endl;
00771 
00772   this->cleanup();
00773 
00774   for ( unsigned int i=0; i<clients_.size(); i++ ) {
00775     clients_[i]->endJob();
00776   }
00777 
00778   if ( summaryClient_ ) summaryClient_->endJob();
00779 
00780 }
00781 
00782 void EcalBarrelMonitorClient::endRun(void) {
00783 
00784   begin_run_ = false;
00785   end_run_   = true;
00786 
00787   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: endRun, jevt = " << jevt_ << std::endl;
00788 
00789   if ( subrun_ != -1 ) {
00790 
00791     this->writeDb();
00792 
00793     this->endRunDb();
00794 
00795   }
00796 
00797   if ( resetFile_.size() != 0 || dbUpdateTime_ > 0 ) {
00798 
00799     this->softReset(false);
00800 
00801     for ( int i=0; i<int(clients_.size()); i++ ) {
00802       bool done = false;
00803       for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00804         if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00805           done = true;
00806           clients_[i]->analyze();
00807         }
00808       }
00809     }
00810 
00811     if ( summaryClient_ ) summaryClient_->analyze();
00812 
00813   }
00814 
00815   for ( int i=0; i<int(clients_.size()); i++ ) {
00816     bool done = false;
00817     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
00818       if ( runType_ != -1 && runType_ == (*j).second && !done ) {
00819         done = true;
00820         clients_[i]->endRun();
00821       }
00822     }
00823   }
00824 
00825   if ( summaryClient_ ) summaryClient_->endRun();
00826 
00827   this->cleanup();
00828 
00829   status_  = "unknown";
00830 
00831   run_     = -1;
00832   evt_     = -1;
00833 
00834   runType_ = -1;
00835   evtType_ = -1;
00836 
00837   subrun_ = -1;
00838 
00839 }
00840 
00841 void EcalBarrelMonitorClient::endRun(const edm::Run& r, const edm::EventSetup& c) {
00842 
00843   if ( verbose_ ) {
00844     std::cout << std::endl;
00845     std::cout << "Standard endRun() for run " << r.id().run() << std::endl;
00846     std::cout << std::endl;
00847   }
00848 
00849   this->analyze();
00850 
00851   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
00852 
00853     forced_update_ = true;
00854     this->analyze();
00855 
00856     if ( ! mergeRuns_ ) {
00857 
00858       if ( begin_run_ && ! end_run_ ) {
00859 
00860         forced_status_ = false;
00861         this->endRun();
00862 
00863       }
00864 
00865     }
00866 
00867   }
00868 
00869   // summary for DQM GUI
00870 
00871   if ( run_ != -1 && evt_ != -1 && runType_ == -1 )  {
00872 
00873     char histo[200];
00874 
00875     MonitorElement* me;
00876 
00877     sprintf(histo, "reportSummary");
00878     me = dqmStore_->get(prefixME_ + "/EventInfo/" + histo);
00879     if ( me ) me->Fill(-1.0);
00880 
00881     for (int i = 0; i < 36; i++) {
00882       sprintf(histo, "EcalBarrel_%s", Numbers::sEB(i+1).c_str());
00883       me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryContents/" + histo);
00884       if ( me ) me->Fill(-1.0);
00885     }
00886 
00887     sprintf(histo, "reportSummaryMap");
00888     me = dqmStore_->get(prefixME_ + "/EventInfo/" + histo);
00889     for ( int iettx = 0; iettx < 34; iettx++ ) {
00890       for ( int ipttx = 0; ipttx < 72; ipttx++ ) {
00891         if ( me ) me->setBinContent( ipttx+1, iettx+1, -1.0 );
00892       }
00893     }
00894 
00895   }
00896 
00897 }
00898 
00899 void EcalBarrelMonitorClient::beginLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c) {
00900 
00901   if ( verbose_ ) {
00902     std::cout << std::endl;
00903     std::cout << "Standard beginLuminosityBlock() for luminosity block " << l.id().luminosityBlock() << " of run " << l.id().run() << std::endl;
00904     std::cout << std::endl;
00905   }
00906 
00907 }
00908 
00909 void EcalBarrelMonitorClient::endLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c) {
00910 
00911   current_time_ = time(NULL);
00912 
00913   if ( verbose_ ) {
00914     std::cout << std::endl;
00915     std::cout << "Standard endLuminosityBlock() for luminosity block " << l.id().luminosityBlock() << " of run " << l.id().run() << std::endl;
00916     std::cout << std::endl;
00917   }
00918 
00919   if ( updateTime_ > 0 ) {
00920     if ( (current_time_ - last_time_update_) < 60 * updateTime_ ) {
00921       return;
00922     }
00923     last_time_update_ = current_time_;
00924   }
00925 
00926   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
00927 
00928     forced_update_ = true;
00929     this->analyze();
00930 
00931   }
00932 
00933 }
00934 
00935 void EcalBarrelMonitorClient::reset(void) {
00936 
00937 }
00938 
00939 void EcalBarrelMonitorClient::setup(void) {
00940 
00941 }
00942 
00943 void EcalBarrelMonitorClient::cleanup(void) {
00944 
00945   if ( ! enableCleanup_ ) return;
00946 
00947   if ( cloneME_ ) {
00948     if ( h_ ) delete h_;
00949   }
00950 
00951   h_ = 0;
00952 
00953 }
00954 
00955 void EcalBarrelMonitorClient::beginRunDb(void) {
00956 
00957   subrun_ = 0;
00958 
00959 #ifdef WITH_ECAL_COND_DB
00960   EcalCondDBInterface* econn;
00961 
00962   econn = 0;
00963 
00964   if ( dbName_.size() != 0 ) {
00965     try {
00966       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
00967       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
00968       if ( verbose_ ) std::cout << "done." << std::endl;
00969     } catch (std::runtime_error &e) {
00970       std::cerr << e.what() << std::endl;
00971       if ( dbHostName_.size() != 0 ) {
00972         try {
00973           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
00974           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
00975           if ( verbose_ ) std::cout << "done." << std::endl;
00976         } catch (std::runtime_error &e) {
00977           std::cerr << e.what() << std::endl;
00978         }
00979       }
00980     }
00981   }
00982 
00983   // create the objects necessary to identify a dataset
00984 
00985   LocationDef locdef;
00986 
00987   locdef.setLocation(location_);
00988 
00989   RunTypeDef rundef;
00990 
00991   rundef.setRunType( this->getRunType() );
00992 
00993   RunTag runtag;
00994 
00995   runtag.setLocationDef(locdef);
00996   runtag.setRunTypeDef(rundef);
00997 
00998   runtag.setGeneralTag( this->getRunType() );
00999 
01000   // fetch the RunIOV from the DB
01001 
01002   bool foundRunIOV = false;
01003 
01004   if ( econn ) {
01005     try {
01006       if ( verbose_ ) std::cout << "Fetching RunIOV ..." << std::endl;
01007 //      runiov_ = econn->fetchRunIOV(&runtag, run_);
01008       runiov_ = econn->fetchRunIOV(location_, run_);
01009       if ( verbose_ ) std::cout << "done." << std::endl;
01010       foundRunIOV = true;
01011     } catch (std::runtime_error &e) {
01012       std::cerr << e.what() << std::endl;
01013       foundRunIOV = false;
01014     }
01015   }
01016 
01017   // begin - setup the RunIOV (on behalf of the DAQ)
01018 
01019   if ( ! foundRunIOV ) {
01020 
01021     Tm startRun;
01022 
01023     startRun.setToCurrentGMTime();
01024 
01025     runiov_.setRunNumber(run_);
01026     runiov_.setRunStart(startRun);
01027     runiov_.setRunTag(runtag);
01028 
01029     if ( econn ) {
01030       try {
01031         if ( verbose_ ) std::cout << "Inserting RunIOV ..." << std::endl;
01032         econn->insertRunIOV(&runiov_);
01033 //        runiov_ = econn->fetchRunIOV(&runtag, run_);
01034         runiov_ = econn->fetchRunIOV(location_, run_);
01035         if ( verbose_ ) std::cout << "done." << std::endl;
01036       } catch (std::runtime_error &e) {
01037         std::cerr << e.what() << std::endl;
01038         try {
01039           if ( verbose_ ) std::cout << "Fetching RunIOV (again) ..." << std::endl;
01040 //          runiov_ = econn->fetchRunIOV(&runtag, run_);
01041           runiov_ = econn->fetchRunIOV(location_, run_);
01042           if ( verbose_ ) std::cout << "done." << std::endl;
01043           foundRunIOV = true;
01044         } catch (std::runtime_error &e) {
01045           std::cerr << e.what() << std::endl;
01046           foundRunIOV = false;
01047         }
01048       }
01049     }
01050 
01051   }
01052 
01053   // end - setup the RunIOV (on behalf of the DAQ)
01054 
01055   if ( verbose_ ) {
01056     std::cout << std::endl;
01057     std::cout << "=============RunIOV:" << std::endl;
01058     std::cout << "Run Number:         " << runiov_.getRunNumber() << std::endl;
01059     std::cout << "Run Start:          " << runiov_.getRunStart().str() << std::endl;
01060     std::cout << "Run End:            " << runiov_.getRunEnd().str() << std::endl;
01061     std::cout << "====================" << std::endl;
01062     std::cout << std::endl;
01063     std::cout << "=============RunTag:" << std::endl;
01064     std::cout << "GeneralTag:         " << runiov_.getRunTag().getGeneralTag() << std::endl;
01065     std::cout << "Location:           " << runiov_.getRunTag().getLocationDef().getLocation() << std::endl;
01066     std::cout << "Run Type:           " << runiov_.getRunTag().getRunTypeDef().getRunType() << std::endl;
01067     std::cout << "====================" << std::endl;
01068     std::cout << std::endl;
01069   }
01070 
01071   std::string rt = runiov_.getRunTag().getRunTypeDef().getRunType();
01072   if ( strcmp(rt.c_str(), "UNKNOWN") == 0 ) {
01073     runType_ = -1;
01074   } else {
01075     for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01076       if ( strcmp(rt.c_str(), runTypes_[i].c_str()) == 0 ) {
01077         if ( runType_ != int(i) ) {
01078           if ( verbose_ ) {
01079             std::cout << std::endl;
01080             std::cout << "Fixing Run Type to: " << runTypes_[i] << std::endl;
01081             std::cout << std::endl;
01082           }
01083           runType_ = i;
01084         }
01085         break;
01086       }
01087     }
01088   }
01089 
01090   if ( verbose_ ) std::cout << std::endl;
01091 
01092   if ( econn ) {
01093     try {
01094       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01095       delete econn;
01096       econn = 0;
01097       if ( verbose_ ) std::cout << "done." << std::endl;
01098     } catch (std::runtime_error &e) {
01099       std::cerr << e.what() << std::endl;
01100     }
01101   }
01102 #endif
01103 
01104   if ( verbose_ ) std::cout << std::endl;
01105 
01106 }
01107 
01108 void EcalBarrelMonitorClient::writeDb(void) {
01109 
01110   subrun_++;
01111 
01112 #ifdef WITH_ECAL_COND_DB
01113   EcalCondDBInterface* econn;
01114 
01115   econn = 0;
01116 
01117   if ( dbName_.size() != 0 ) {
01118     try {
01119       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01120       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01121       if ( verbose_ ) std::cout << "done." << std::endl;
01122     } catch (std::runtime_error &e) {
01123       std::cerr << e.what() << std::endl;
01124       if ( dbHostName_.size() != 0 ) {
01125         try {
01126           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01127           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01128           if ( verbose_ ) std::cout << "done." << std::endl;
01129         } catch (std::runtime_error &e) {
01130           std::cerr << e.what() << std::endl;
01131         }
01132       }
01133     }
01134   }
01135 
01136   MonVersionDef monverdef;
01137 
01138   monverdef.setMonitoringVersion("test01");
01139 
01140   MonRunTag montag;
01141 
01142   montag.setMonVersionDef(monverdef);
01143   montag.setGeneralTag(dbTagName_);
01144 
01145   Tm startSubRun;
01146 
01147   startSubRun.setToCurrentGMTime();
01148 
01149   // fetch the MonIOV from the DB
01150 
01151   bool foundMonIOV = false;
01152 
01153   if ( econn ) {
01154     try {
01155       if ( verbose_ ) std::cout << "Fetching MonIOV ..." << std::endl;
01156       RunTag runtag = runiov_.getRunTag();
01157       moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01158       if ( verbose_ ) std::cout << "done." << std::endl;
01159       foundMonIOV = true;
01160     } catch (std::runtime_error &e) {
01161       std::cerr << e.what() << std::endl;
01162       foundMonIOV = false;
01163     }
01164   }
01165 
01166   // begin - setup the MonIOV
01167 
01168   if ( !foundMonIOV ) {
01169 
01170     moniov_.setRunIOV(runiov_);
01171     moniov_.setSubRunNumber(subrun_);
01172 
01173     if ( subrun_ > 1 ) {
01174       moniov_.setSubRunStart(startSubRun);
01175     } else {
01176       moniov_.setSubRunStart(runiov_.getRunStart());
01177     }
01178 
01179     moniov_.setMonRunTag(montag);
01180 
01181     if ( econn ) {
01182       try {
01183         if ( verbose_ ) std::cout << "Inserting MonIOV ..." << std::endl;
01184         econn->insertMonRunIOV(&moniov_);
01185         RunTag runtag = runiov_.getRunTag();
01186         moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01187         if ( verbose_ ) std::cout << "done." << std::endl;
01188       } catch (std::runtime_error &e) {
01189         std::cerr << e.what() << std::endl;
01190         try {
01191           if ( verbose_ ) std::cout << "Fetching MonIOV (again) ..." << std::endl;
01192           RunTag runtag = runiov_.getRunTag();
01193           moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01194           if ( verbose_ ) std::cout << "done." << std::endl;
01195           foundMonIOV = true;
01196         } catch (std::runtime_error &e) {
01197           std::cerr << e.what() << std::endl;
01198           foundMonIOV = false;
01199         }
01200       }
01201     }
01202 
01203   }
01204 
01205   // end - setup the MonIOV
01206 
01207   if ( verbose_ ) {
01208     std::cout << std::endl;
01209     std::cout << "==========MonRunIOV:" << std::endl;
01210     std::cout << "SubRun Number:      " << moniov_.getSubRunNumber() << std::endl;
01211     std::cout << "SubRun Start:       " << moniov_.getSubRunStart().str() << std::endl;
01212     std::cout << "SubRun End:         " << moniov_.getSubRunEnd().str() << std::endl;
01213     std::cout << "====================" << std::endl;
01214     std::cout << std::endl;
01215     std::cout << "==========MonRunTag:" << std::endl;
01216     std::cout << "GeneralTag:         " << moniov_.getMonRunTag().getGeneralTag() << std::endl;
01217     std::cout << "Monitoring Ver:     " << moniov_.getMonRunTag().getMonVersionDef().getMonitoringVersion() << std::endl;
01218     std::cout << "====================" << std::endl;
01219     std::cout << std::endl;
01220   }
01221 
01222   int taskl = 0x0;
01223   int tasko = 0x0;
01224 
01225   for ( int i=0; i<int(clients_.size()); i++ ) {
01226     bool done = false;
01227     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01228       if ( h_ && runType_ != -1 && runType_ == (*j).second && !done ) {
01229         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;
01230         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;
01231         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;
01232         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;
01233         done = true;
01234         if ( verbose_ ) {
01235           if ( econn ) {
01236             std::cout << " Writing " << clientsNames_[i] << " results to DB " << std::endl;
01237             std::cout << std::endl;
01238           }
01239         }
01240         bool status;
01241         if ( clients_[i]->writeDb(econn, &runiov_, &moniov_, status) ) {
01242           taskl |= 0x1 << clientsStatus_[clientsNames_[i]];
01243           if ( status ) {
01244             tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01245           }
01246         } else {
01247           tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01248         }
01249       }
01250     }
01251     if ( ((taskl >> clientsStatus_[clientsNames_[i]]) & 0x1) ) {
01252       if ( verbose_ ) {
01253         std::cout << " Task output for " << clientsNames_[i] << " = "
01254              << ((tasko >> clientsStatus_[clientsNames_[i]]) & 0x1) << std::endl;
01255         std::cout << std::endl;
01256       }
01257     }
01258   }
01259 
01260   bool status;
01261   if ( summaryClient_ ) summaryClient_->writeDb(econn, &runiov_, &moniov_, status);
01262 
01263   EcalLogicID ecid;
01264   MonRunDat md;
01265   std::map<EcalLogicID, MonRunDat> dataset;
01266 
01267   MonRunOutcomeDef monRunOutcomeDef;
01268 
01269   monRunOutcomeDef.setShortDesc("success");
01270 
01271   float nevt = -1.;
01272 
01273   if ( h_ ) nevt = h_->GetSumOfWeights();
01274 
01275   md.setNumEvents(int(nevt));
01276   md.setMonRunOutcomeDef(monRunOutcomeDef);
01277 
01278 //  string fileName = "";
01279 //  md.setRootfileName(fileName);
01280 
01281   md.setTaskList(taskl);
01282   md.setTaskOutcome(tasko);
01283 
01284   if ( econn ) {
01285     try {
01286       ecid = LogicID::getEcalLogicID("EB");
01287       dataset[ecid] = md;
01288     } catch (std::runtime_error &e) {
01289       std::cerr << e.what() << std::endl;
01290     }
01291   }
01292 
01293   if ( econn ) {
01294     try {
01295       if ( verbose_ ) std::cout << "Inserting MonRunDat ..." << std::endl;
01296       econn->insertDataSet(&dataset, &moniov_);
01297       if ( verbose_ ) std::cout << "done." << std::endl;
01298     } catch (std::runtime_error &e) {
01299       std::cerr << e.what() << std::endl;
01300     }
01301   }
01302 
01303   if ( econn ) {
01304     try {
01305       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01306       delete econn;
01307       econn = 0;
01308       if ( verbose_ ) std::cout << "done." << std::endl;
01309     } catch (std::runtime_error &e) {
01310       std::cerr << e.what() << std::endl;
01311     }
01312   }
01313 #endif
01314 
01315   if ( verbose_ ) std::cout << std::endl;
01316 
01317 }
01318 
01319 void EcalBarrelMonitorClient::endRunDb(void) {
01320 
01321 #ifdef WITH_ECAL_COND_DB
01322   EcalCondDBInterface* econn;
01323 
01324   econn = 0;
01325 
01326   if ( dbName_.size() != 0 ) {
01327     try {
01328       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01329       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01330       if ( verbose_ ) std::cout << "done." << std::endl;
01331     } catch (std::runtime_error &e) {
01332       std::cerr << e.what() << std::endl;
01333       if ( dbHostName_.size() != 0 ) {
01334         try {
01335           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01336           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01337           if ( verbose_ ) std::cout << "done." << std::endl;
01338         } catch (std::runtime_error &e) {
01339           std::cerr << e.what() << std::endl;
01340         }
01341       }
01342     }
01343   }
01344 
01345   EcalLogicID ecid;
01346   RunDat rd;
01347   std::map<EcalLogicID, RunDat> dataset;
01348 
01349   float nevt = -1.;
01350 
01351   if ( h_ ) nevt = h_->GetSumOfWeights();
01352 
01353   rd.setNumEvents(int(nevt));
01354 
01355   // fetch the RunDat from the DB
01356 
01357   bool foundRunDat = false;
01358 
01359   if ( econn ) {
01360     try {
01361       if ( verbose_ ) std::cout << "Fetching RunDat ..." << std::endl;
01362       econn->fetchDataSet(&dataset, &runiov_);
01363       if ( verbose_ ) std::cout << "done." << std::endl;
01364       foundRunDat = true;
01365     } catch (std::runtime_error &e) {
01366       std::cerr << e.what() << std::endl;
01367       foundRunDat = false;
01368     }
01369   }
01370 
01371   // begin - setup the RunDat (on behalf of the DAQ)
01372 
01373   if ( ! foundRunDat ) {
01374 
01375     if ( econn ) {
01376       try {
01377         ecid = LogicID::getEcalLogicID("EB");
01378         dataset[ecid] = rd;
01379       } catch (std::runtime_error &e) {
01380         std::cerr << e.what() << std::endl;
01381       }
01382     }
01383 
01384     if ( econn ) {
01385       try {
01386         if ( verbose_ ) std::cout << "Inserting RunDat ..." << std::endl;
01387         econn->insertDataSet(&dataset, &runiov_);
01388         if ( verbose_ ) std::cout << "done." << std::endl;
01389       } catch (std::runtime_error &e) {
01390         std::cerr << e.what() << std::endl;
01391       }
01392     }
01393 
01394   }
01395 
01396   // end - setup the RunDat (on behalf of the DAQ)
01397 
01398   if ( econn ) {
01399     try {
01400       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01401       delete econn;
01402       econn = 0;
01403       if ( verbose_ ) std::cout << "done." << std::endl;
01404     } catch (std::runtime_error &e) {
01405       std::cerr << e.what() << std::endl;
01406     }
01407   }
01408 #endif
01409 
01410 }
01411 
01412 void EcalBarrelMonitorClient::analyze(void) {
01413 
01414   current_time_ = time(NULL);
01415 
01416   ievt_++;
01417   jevt_++;
01418 
01419   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
01420 
01421   MonitorElement* me;
01422   std::string s;
01423 
01424   me = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
01425   if ( me ) {
01426     status_ = "unknown";
01427     s = me->valueString();
01428     if ( strcmp(s.c_str(), "i=0") == 0 ) status_ = "begin-of-run";
01429     if ( strcmp(s.c_str(), "i=1") == 0 ) status_ = "running";
01430     if ( strcmp(s.c_str(), "i=2") == 0 ) status_ = "end-of-run";
01431     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/STATUS'" << std::endl;
01432   }
01433 
01434   if ( inputFile_.size() != 0 ) {
01435     if ( ievt_ == 1 ) {
01436       if ( verbose_ ) {
01437         std::cout << std::endl;
01438         std::cout << " Reading DQM from file, forcing 'begin-of-run'" << std::endl;
01439         std::cout << std::endl;
01440       }
01441       status_ = "begin-of-run";
01442     }
01443   }
01444 
01445   int ecal_run = -1;
01446   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
01447   if ( me ) {
01448     s = me->valueString();
01449     sscanf(s.c_str(), "i=%d", &ecal_run);
01450     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUN'" << std::endl;
01451   }
01452 
01453   int ecal_evt = -1;
01454   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
01455   if ( me ) {
01456     s = me->valueString();
01457     sscanf(s.c_str(), "i=%d", &ecal_evt);
01458     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/EVT'" << std::endl;
01459   }
01460 
01461   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01462   h_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, h_ );
01463 
01464   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUNTYPE");
01465   if ( me ) {
01466     s = me->valueString();
01467     sscanf(s.c_str(), "i=%d", &evtType_);
01468     if ( runType_ == -1 ) runType_ = evtType_;
01469     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUNTYPE'" << std::endl;
01470   }
01471 
01472   // if the run number from the Event is less than zero,
01473   // use the run number from the ECAL DCC header
01474   if ( run_ <= 0 ) run_ = ecal_run;
01475 
01476   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01477     if ( ! mergeRuns_ && run_ != last_run_ ) forced_update_ = true;
01478   }
01479 
01480   bool update = ( forced_update_                    ) ||
01481                 ( prescaleFactor_ != 1              ) ||
01482                 ( jevt_ <   10                      ) ||
01483                 ( jevt_ <  100 && jevt_ %   10 == 0 ) ||
01484                 ( jevt_ < 1000 && jevt_ %  100 == 0 ) ||
01485                 (                 jevt_ % 1000 == 0 );
01486 
01487   if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01488 
01489     if ( verbose_ ) {
01490       std::cout << " RUN status = \"" << status_ << "\"" << std::endl;
01491       std::cout << "   CMS run/event number = " << run_ << "/" << evt_ << std::endl;
01492       std::cout << "   EB run/event number = " << ecal_run << "/" << ecal_evt << std::endl;
01493       std::cout << "   EB location = " << location_ << std::endl;
01494       std::cout << "   EB run/event type = " << this->getRunType() << "/" << ( evtType_ == -1 ? "UNKNOWN" : runTypes_[evtType_] ) << std::flush;
01495 
01496       if ( h_ ) {
01497         if ( h_->GetSumOfWeights() != 0 ) {
01498           std::cout << " ( " << std::flush;
01499           for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01500             if ( strcmp(runTypes_[i].c_str(), "UNKNOWN") != 0 && h_->GetBinContent(2+i) != 0 ) {
01501               std::string s = runTypes_[i];
01502               transform( s.begin(), s.end(), s.begin(), (int(*)(int))tolower );
01503               std::cout << s << " ";
01504             }
01505           }
01506           std::cout << ")" << std::flush;
01507         }
01508       }
01509       std::cout << std::endl;
01510     }
01511 
01512   }
01513 
01514   if ( strcmp(status_.c_str(), "begin-of-run") == 0 ) {
01515 
01516     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01517 
01518       if ( ! begin_run_ ) {
01519 
01520         forced_status_ = false;
01521         this->beginRun();
01522 
01523       }
01524 
01525     }
01526 
01527   }
01528 
01529   if ( strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "running") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01530 
01531     if ( begin_run_ && ! end_run_ ) {
01532 
01533       bool update = ( forced_update_                      ) ||
01534                     ( prescaleFactor_ != 1                ) ||
01535                     ( jevt_ <     3                       ) ||
01536                     ( jevt_ <  1000 && jevt_ %   100 == 0 ) ||
01537                     ( jevt_ < 10000 && jevt_ %  1000 == 0 ) ||
01538                     (                  jevt_ % 10000 == 0 );
01539 
01540       if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01541 
01542         for ( int i=0; i<int(clients_.size()); i++ ) {
01543           bool done = false;
01544           for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01545             if ( runType_ != -1 && runType_ == (*j).second && !done ) {
01546               done = true;
01547               clients_[i]->analyze();
01548             }
01549           }
01550         }
01551 
01552         if ( summaryClient_ ) summaryClient_->analyze();
01553 
01554       }
01555 
01556       forced_update_ = false;
01557 
01558       bool reset = false;
01559 
01560       if ( resetFile_.size() != 0 ) {
01561         if ( access(resetFile_.c_str(), W_OK) == 0 ) {
01562           if ( unlink(resetFile_.c_str()) == 0 ) {
01563             reset |= true;
01564           }
01565         }
01566       }
01567 
01568       if ( dbUpdateTime_ > 0 ) {
01569         reset |= (current_time_ - last_time_reset_) > 60 * dbUpdateTime_;
01570       }
01571 
01572       if ( reset ) {
01573         if ( runType_ == EcalDCCHeaderBlock::COSMIC ||
01574              runType_ == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
01575              runType_ == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
01576              runType_ == EcalDCCHeaderBlock::COSMICS_LOCAL ||
01577              runType_ == EcalDCCHeaderBlock::PHYSICS_LOCAL ||
01578              runType_ == EcalDCCHeaderBlock::BEAMH2 ||
01579              runType_ == EcalDCCHeaderBlock::BEAMH4 ) this->writeDb();
01580         this->softReset(true);
01581         last_time_reset_ = current_time_;
01582       }
01583 
01584     }
01585 
01586   }
01587 
01588   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01589 
01590     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01591 
01592       if ( begin_run_ && ! end_run_ ) {
01593 
01594         forced_status_ = false;
01595         this->endRun();
01596 
01597       }
01598 
01599     }
01600 
01601   }
01602 
01603   // BEGIN: run-time fixes for missing state transitions
01604 
01605   // run number transition
01606 
01607   if ( strcmp(status_.c_str(), "running") == 0 ) {
01608 
01609     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01610 
01611       if ( ! mergeRuns_ ) {
01612 
01613         int new_run_ = run_;
01614         int old_run_ = last_run_;
01615 
01616         if ( new_run_ != old_run_ ) {
01617 
01618           if ( begin_run_ && ! end_run_ ) {
01619 
01620             if ( verbose_ ) {
01621               std::cout << std::endl;
01622               std::cout << " Old run has finished, issuing endRun() ... " << std::endl;
01623               std::cout << std::endl;
01624             }
01625 
01626             // end old_run_
01627             run_ = old_run_;
01628 
01629             forced_status_ = false;
01630             this->endRun();
01631 
01632           }
01633 
01634           if ( ! begin_run_ ) {
01635 
01636             if ( verbose_ ) {
01637               std::cout << std::endl;
01638               std::cout << " New run has started, issuing beginRun() ... " << std::endl;
01639               std::cout << std::endl;
01640             }
01641 
01642             // start new_run_
01643             run_ = new_run_;
01644 
01645             forced_status_ = false;
01646             this->beginRun();
01647 
01648           }
01649 
01650         }
01651 
01652       }
01653 
01654     }
01655 
01656   }
01657 
01658   // 'running' state without a previous 'begin-of-run' state
01659 
01660   if ( strcmp(status_.c_str(), "running") == 0 ) {
01661 
01662     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01663 
01664       if ( ! forced_status_ ) {
01665 
01666         if ( ! begin_run_ ) {
01667 
01668           if ( verbose_ ) {
01669             std::cout << std::endl;
01670             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01671             std::cout << std::endl;
01672           }
01673 
01674           forced_status_ = true;
01675           this->beginRun();
01676 
01677         }
01678 
01679       }
01680 
01681     }
01682 
01683   }
01684 
01685   // 'end-of-run' state without a previous 'begin-of-run' or 'running' state
01686 
01687   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01688 
01689     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01690 
01691       if ( ! forced_status_ ) {
01692 
01693         if ( ! begin_run_ ) {
01694 
01695           if ( verbose_ ) {
01696             std::cout << std::endl;
01697             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01698             std::cout << std::endl;
01699           }
01700 
01701           forced_status_ = true;
01702           this->beginRun();
01703 
01704         }
01705 
01706       }
01707 
01708     }
01709 
01710   }
01711 
01712   // END: run-time fixes for missing state transitions
01713 
01714 }
01715 
01716 void EcalBarrelMonitorClient::analyze(const edm::Event& e, const edm::EventSetup& c) {
01717 
01718   run_ = e.id().run();
01719   evt_ = e.id().event();
01720 
01721   if ( prescaleFactor_ > 0 ) {
01722     if ( jevt_ % prescaleFactor_ == 0 ) this->analyze();
01723   }
01724 
01725 }
01726 
01727 void EcalBarrelMonitorClient::softReset(bool flag) {
01728 
01729   std::vector<MonitorElement*> mes = dqmStore_->getAllContents(prefixME_);
01730   std::vector<MonitorElement*>::const_iterator meitr;
01731   for ( meitr=mes.begin(); meitr!=mes.end(); meitr++ ) {
01732     if ( !strncmp((*meitr)->getName().c_str(), "EB", 2)
01733          && strncmp((*meitr)->getName().c_str(), "EBTrend", 7)
01734          && strncmp((*meitr)->getName().c_str(), "by lumi", 7) ) {
01735       if ( flag ) {
01736         dqmStore_->softReset(*meitr);
01737       } else {
01738         dqmStore_->disableSoftReset(*meitr);
01739       }
01740     }
01741   }
01742 
01743   MonitorElement* me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01744   if ( me ) {
01745     if ( flag ) {
01746       dqmStore_->softReset(me);
01747     } else {
01748       dqmStore_->disableSoftReset(me);
01749     }
01750   }
01751 
01752 }
01753