CMS 3D CMS Logo

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

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