CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/EcalBarrelMonitorClient/src/EcalBarrelMonitorClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EcalBarrelMonitorClient.cc
00003  *
00004  * $Date: 2013/04/02 09:07:29 $
00005  * $Revision: 1.508.2.1 $
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(begin_run_ && !end_run_){
00898     unsigned iC(0);
00899     for(; iC < enabledClients_.size(); iC++){
00900       std::string& name(enabledClients_[iC]);
00901 
00902       if(name == "Cluster" || name == "Cosmic" || name == "Occupancy" || name == "StatusFlags" || name == "Trend") continue;
00903 
00904       std::string dir(prefixME_ + "/EB" + name + "Client");
00905       if(!dqmStore_->dirExists(dir) || !dqmStore_->containsAnyMonitorable(dir)){
00906         std::vector<std::string>::iterator itr(std::find(clientsNames_.begin(), clientsNames_.end(), name));
00907         if(itr == clientsNames_.end()) continue; // something seriously wrong, but ignore
00908         std::cout << "EB" << name << "Client is missing plots; resetting now" << std::endl;
00909 
00910         break;
00911       }
00912     }
00913     if(iC != enabledClients_.size()){
00914       forced_status_ = false;
00915       endRun();
00916       beginRun();
00917       run_ = l.id().run();
00918       evt_ = 0;
00919     }
00920   }
00921 
00922   if ( updateTime_ > 0 ) {
00923     if ( (current_time_ - last_time_update_) < 60 * updateTime_ ) {
00924       return;
00925     }
00926     last_time_update_ = current_time_;
00927   }
00928 
00929   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
00930 
00931     forced_update_ = true;
00932     this->analyze();
00933 
00934   }
00935 }
00936 
00937 void EcalBarrelMonitorClient::reset(void) {
00938 
00939 }
00940 
00941 void EcalBarrelMonitorClient::setup(void) {
00942 
00943 }
00944 
00945 void EcalBarrelMonitorClient::cleanup(void) {
00946 
00947   if ( ! enableCleanup_ ) return;
00948 
00949   if ( cloneME_ ) {
00950     if ( h_ ) delete h_;
00951   }
00952 
00953   h_ = 0;
00954 
00955 }
00956 
00957 void EcalBarrelMonitorClient::beginRunDb(void) {
00958 
00959   subrun_ = 0;
00960 
00961 #ifdef WITH_ECAL_COND_DB
00962   EcalCondDBInterface* econn;
00963 
00964   econn = 0;
00965 
00966   if ( dbName_.size() != 0 ) {
00967     try {
00968       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
00969       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
00970       if ( verbose_ ) std::cout << "done." << std::endl;
00971     } catch (std::runtime_error &e) {
00972       std::cerr << e.what() << std::endl;
00973       if ( dbHostName_.size() != 0 ) {
00974         try {
00975           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
00976           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
00977           if ( verbose_ ) std::cout << "done." << std::endl;
00978         } catch (std::runtime_error &e) {
00979           std::cerr << e.what() << std::endl;
00980         }
00981       }
00982     }
00983   }
00984 
00985   // create the objects necessary to identify a dataset
00986 
00987   LocationDef locdef;
00988 
00989   locdef.setLocation(location_);
00990 
00991   RunTypeDef rundef;
00992 
00993   rundef.setRunType( this->getRunType() );
00994 
00995   RunTag runtag;
00996 
00997   runtag.setLocationDef(locdef);
00998   runtag.setRunTypeDef(rundef);
00999 
01000   runtag.setGeneralTag( this->getRunType() );
01001 
01002   // fetch the RunIOV from the DB
01003 
01004   bool foundRunIOV = false;
01005 
01006   if ( econn ) {
01007     try {
01008       if ( verbose_ ) std::cout << "Fetching RunIOV ..." << std::endl;
01009 //      runiov_ = econn->fetchRunIOV(&runtag, run_);
01010       runiov_ = econn->fetchRunIOV(location_, run_);
01011       if ( verbose_ ) std::cout << "done." << std::endl;
01012       foundRunIOV = true;
01013     } catch (std::runtime_error &e) {
01014       std::cerr << e.what() << std::endl;
01015       foundRunIOV = false;
01016     }
01017   }
01018 
01019   // begin - setup the RunIOV (on behalf of the DAQ)
01020 
01021   if ( ! foundRunIOV ) {
01022 
01023     Tm startRun;
01024 
01025     startRun.setToCurrentGMTime();
01026 
01027     runiov_.setRunNumber(run_);
01028     runiov_.setRunStart(startRun);
01029     runiov_.setRunTag(runtag);
01030 
01031     if ( econn ) {
01032       try {
01033         if ( verbose_ ) std::cout << "Inserting RunIOV ..." << std::endl;
01034         econn->insertRunIOV(&runiov_);
01035 //        runiov_ = econn->fetchRunIOV(&runtag, run_);
01036         runiov_ = econn->fetchRunIOV(location_, run_);
01037         if ( verbose_ ) std::cout << "done." << std::endl;
01038       } catch (std::runtime_error &e) {
01039         std::cerr << e.what() << std::endl;
01040         try {
01041           if ( verbose_ ) std::cout << "Fetching RunIOV (again) ..." << std::endl;
01042 //          runiov_ = econn->fetchRunIOV(&runtag, run_);
01043           runiov_ = econn->fetchRunIOV(location_, run_);
01044           if ( verbose_ ) std::cout << "done." << std::endl;
01045           foundRunIOV = true;
01046         } catch (std::runtime_error &e) {
01047           std::cerr << e.what() << std::endl;
01048           foundRunIOV = false;
01049         }
01050       }
01051     }
01052 
01053   }
01054 
01055   // end - setup the RunIOV (on behalf of the DAQ)
01056 
01057   if ( verbose_ ) {
01058     std::cout << std::endl;
01059     std::cout << "=============RunIOV:" << std::endl;
01060     std::cout << "Run Number:         " << runiov_.getRunNumber() << std::endl;
01061     std::cout << "Run Start:          " << runiov_.getRunStart().str() << std::endl;
01062     std::cout << "Run End:            " << runiov_.getRunEnd().str() << std::endl;
01063     std::cout << "====================" << std::endl;
01064     std::cout << std::endl;
01065     std::cout << "=============RunTag:" << std::endl;
01066     std::cout << "GeneralTag:         " << runiov_.getRunTag().getGeneralTag() << std::endl;
01067     std::cout << "Location:           " << runiov_.getRunTag().getLocationDef().getLocation() << std::endl;
01068     std::cout << "Run Type:           " << runiov_.getRunTag().getRunTypeDef().getRunType() << std::endl;
01069     std::cout << "====================" << std::endl;
01070     std::cout << std::endl;
01071   }
01072 
01073   std::string rt = runiov_.getRunTag().getRunTypeDef().getRunType();
01074   if ( strcmp(rt.c_str(), "UNKNOWN") == 0 ) {
01075     runType_ = -1;
01076   } else {
01077     for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01078       if ( strcmp(rt.c_str(), runTypes_[i].c_str()) == 0 ) {
01079         if ( runType_ != int(i) ) {
01080           if ( verbose_ ) {
01081             std::cout << std::endl;
01082             std::cout << "Fixing Run Type to: " << runTypes_[i] << std::endl;
01083             std::cout << std::endl;
01084           }
01085           runType_ = i;
01086         }
01087         break;
01088       }
01089     }
01090   }
01091 
01092   if ( verbose_ ) std::cout << std::endl;
01093 
01094   if ( econn ) {
01095     try {
01096       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01097       delete econn;
01098       econn = 0;
01099       if ( verbose_ ) std::cout << "done." << std::endl;
01100     } catch (std::runtime_error &e) {
01101       std::cerr << e.what() << std::endl;
01102     }
01103   }
01104 #endif
01105 
01106   if ( verbose_ ) std::cout << std::endl;
01107 
01108 }
01109 
01110 void EcalBarrelMonitorClient::writeDb(void) {
01111 
01112   subrun_++;
01113 
01114 #ifdef WITH_ECAL_COND_DB
01115   EcalCondDBInterface* econn;
01116 
01117   econn = 0;
01118 
01119   if ( dbName_.size() != 0 ) {
01120     try {
01121       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01122       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01123       if ( verbose_ ) std::cout << "done." << std::endl;
01124     } catch (std::runtime_error &e) {
01125       std::cerr << e.what() << std::endl;
01126       if ( dbHostName_.size() != 0 ) {
01127         try {
01128           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01129           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01130           if ( verbose_ ) std::cout << "done." << std::endl;
01131         } catch (std::runtime_error &e) {
01132           std::cerr << e.what() << std::endl;
01133         }
01134       }
01135     }
01136   }
01137 
01138   MonVersionDef monverdef;
01139 
01140   monverdef.setMonitoringVersion("test01");
01141 
01142   MonRunTag montag;
01143 
01144   montag.setMonVersionDef(monverdef);
01145   montag.setGeneralTag(dbTagName_);
01146 
01147   Tm startSubRun;
01148 
01149   startSubRun.setToCurrentGMTime();
01150 
01151   // fetch the MonIOV from the DB
01152 
01153   bool foundMonIOV = false;
01154 
01155   if ( econn ) {
01156     try {
01157       if ( verbose_ ) std::cout << "Fetching MonIOV ..." << std::endl;
01158       RunTag runtag = runiov_.getRunTag();
01159       moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01160       if ( verbose_ ) std::cout << "done." << std::endl;
01161       foundMonIOV = true;
01162     } catch (std::runtime_error &e) {
01163       std::cerr << e.what() << std::endl;
01164       foundMonIOV = false;
01165     }
01166   }
01167 
01168   // begin - setup the MonIOV
01169 
01170   if ( !foundMonIOV ) {
01171 
01172     moniov_.setRunIOV(runiov_);
01173     moniov_.setSubRunNumber(subrun_);
01174 
01175     if ( subrun_ > 1 ) {
01176       moniov_.setSubRunStart(startSubRun);
01177     } else {
01178       moniov_.setSubRunStart(runiov_.getRunStart());
01179     }
01180 
01181     moniov_.setMonRunTag(montag);
01182 
01183     if ( econn ) {
01184       try {
01185         if ( verbose_ ) std::cout << "Inserting MonIOV ..." << std::endl;
01186         econn->insertMonRunIOV(&moniov_);
01187         RunTag runtag = runiov_.getRunTag();
01188         moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01189         if ( verbose_ ) std::cout << "done." << std::endl;
01190       } catch (std::runtime_error &e) {
01191         std::cerr << e.what() << std::endl;
01192         try {
01193           if ( verbose_ ) std::cout << "Fetching MonIOV (again) ..." << std::endl;
01194           RunTag runtag = runiov_.getRunTag();
01195           moniov_ = econn->fetchMonRunIOV(&runtag, &montag, run_, subrun_);
01196           if ( verbose_ ) std::cout << "done." << std::endl;
01197           foundMonIOV = true;
01198         } catch (std::runtime_error &e) {
01199           std::cerr << e.what() << std::endl;
01200           foundMonIOV = false;
01201         }
01202       }
01203     }
01204 
01205   }
01206 
01207   // end - setup the MonIOV
01208 
01209   if ( verbose_ ) {
01210     std::cout << std::endl;
01211     std::cout << "==========MonRunIOV:" << std::endl;
01212     std::cout << "SubRun Number:      " << moniov_.getSubRunNumber() << std::endl;
01213     std::cout << "SubRun Start:       " << moniov_.getSubRunStart().str() << std::endl;
01214     std::cout << "SubRun End:         " << moniov_.getSubRunEnd().str() << std::endl;
01215     std::cout << "====================" << std::endl;
01216     std::cout << std::endl;
01217     std::cout << "==========MonRunTag:" << std::endl;
01218     std::cout << "GeneralTag:         " << moniov_.getMonRunTag().getGeneralTag() << std::endl;
01219     std::cout << "Monitoring Ver:     " << moniov_.getMonRunTag().getMonVersionDef().getMonitoringVersion() << std::endl;
01220     std::cout << "====================" << std::endl;
01221     std::cout << std::endl;
01222   }
01223 
01224   int taskl = 0x0;
01225   int tasko = 0x0;
01226 
01227   for ( int i=0; i<int(clients_.size()); i++ ) {
01228     bool done = false;
01229     for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01230       if ( h_ && runType_ != -1 && runType_ == (*j).second && !done ) {
01231         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;
01232         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;
01233         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;
01234         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;
01235         done = true;
01236         if ( verbose_ ) {
01237           if ( econn ) {
01238             std::cout << " Writing " << clientsNames_[i] << " results to DB " << std::endl;
01239             std::cout << std::endl;
01240           }
01241         }
01242         bool status;
01243         if ( clients_[i]->writeDb(econn, &runiov_, &moniov_, status) ) {
01244           taskl |= 0x1 << clientsStatus_[clientsNames_[i]];
01245           if ( status ) {
01246             tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01247           }
01248         } else {
01249           tasko |= 0x1 << clientsStatus_[clientsNames_[i]];
01250         }
01251       }
01252     }
01253     if ( ((taskl >> clientsStatus_[clientsNames_[i]]) & 0x1) ) {
01254       if ( verbose_ ) {
01255         std::cout << " Task output for " << clientsNames_[i] << " = "
01256              << ((tasko >> clientsStatus_[clientsNames_[i]]) & 0x1) << std::endl;
01257         std::cout << std::endl;
01258       }
01259     }
01260   }
01261 
01262   bool status;
01263   if ( summaryClient_ ) summaryClient_->writeDb(econn, &runiov_, &moniov_, status);
01264 
01265   EcalLogicID ecid;
01266   MonRunDat md;
01267   std::map<EcalLogicID, MonRunDat> dataset;
01268 
01269   MonRunOutcomeDef monRunOutcomeDef;
01270 
01271   monRunOutcomeDef.setShortDesc("success");
01272 
01273   float nevt = -1.;
01274 
01275   if ( h_ ) nevt = h_->GetSumOfWeights();
01276 
01277   md.setNumEvents(int(nevt));
01278   md.setMonRunOutcomeDef(monRunOutcomeDef);
01279 
01280 //  string fileName = "";
01281 //  md.setRootfileName(fileName);
01282 
01283   md.setTaskList(taskl);
01284   md.setTaskOutcome(tasko);
01285 
01286   if ( econn ) {
01287     try {
01288       ecid = LogicID::getEcalLogicID("EB");
01289       dataset[ecid] = md;
01290     } catch (std::runtime_error &e) {
01291       std::cerr << e.what() << std::endl;
01292     }
01293   }
01294 
01295   if ( econn ) {
01296     try {
01297       if ( verbose_ ) std::cout << "Inserting MonRunDat ..." << std::endl;
01298       econn->insertDataSet(&dataset, &moniov_);
01299       if ( verbose_ ) std::cout << "done." << std::endl;
01300     } catch (std::runtime_error &e) {
01301       std::cerr << e.what() << std::endl;
01302     }
01303   }
01304 
01305   if ( econn ) {
01306     try {
01307       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01308       delete econn;
01309       econn = 0;
01310       if ( verbose_ ) std::cout << "done." << std::endl;
01311     } catch (std::runtime_error &e) {
01312       std::cerr << e.what() << std::endl;
01313     }
01314   }
01315 #endif
01316 
01317   if ( verbose_ ) std::cout << std::endl;
01318 
01319 }
01320 
01321 void EcalBarrelMonitorClient::endRunDb(void) {
01322 
01323 #ifdef WITH_ECAL_COND_DB
01324   EcalCondDBInterface* econn;
01325 
01326   econn = 0;
01327 
01328   if ( dbName_.size() != 0 ) {
01329     try {
01330       if ( verbose_ ) std::cout << "Opening DB connection with TNS_ADMIN ..." << std::endl;
01331       econn = new EcalCondDBInterface(dbName_, dbUserName_, dbPassword_);
01332       if ( verbose_ ) std::cout << "done." << std::endl;
01333     } catch (std::runtime_error &e) {
01334       std::cerr << e.what() << std::endl;
01335       if ( dbHostName_.size() != 0 ) {
01336         try {
01337           if ( verbose_ ) std::cout << "Opening DB connection without TNS_ADMIN ..." << std::endl;
01338           econn = new EcalCondDBInterface(dbHostName_, dbName_, dbUserName_, dbPassword_, dbHostPort_);
01339           if ( verbose_ ) std::cout << "done." << std::endl;
01340         } catch (std::runtime_error &e) {
01341           std::cerr << e.what() << std::endl;
01342         }
01343       }
01344     }
01345   }
01346 
01347   EcalLogicID ecid;
01348   RunDat rd;
01349   std::map<EcalLogicID, RunDat> dataset;
01350 
01351   float nevt = -1.;
01352 
01353   if ( h_ ) nevt = h_->GetSumOfWeights();
01354 
01355   rd.setNumEvents(int(nevt));
01356 
01357   // fetch the RunDat from the DB
01358 
01359   bool foundRunDat = false;
01360 
01361   if ( econn ) {
01362     try {
01363       if ( verbose_ ) std::cout << "Fetching RunDat ..." << std::endl;
01364       econn->fetchDataSet(&dataset, &runiov_);
01365       if ( verbose_ ) std::cout << "done." << std::endl;
01366       foundRunDat = true;
01367     } catch (std::runtime_error &e) {
01368       std::cerr << e.what() << std::endl;
01369       foundRunDat = false;
01370     }
01371   }
01372 
01373   // begin - setup the RunDat (on behalf of the DAQ)
01374 
01375   if ( ! foundRunDat ) {
01376 
01377     if ( econn ) {
01378       try {
01379         ecid = LogicID::getEcalLogicID("EB");
01380         dataset[ecid] = rd;
01381       } catch (std::runtime_error &e) {
01382         std::cerr << e.what() << std::endl;
01383       }
01384     }
01385 
01386     if ( econn ) {
01387       try {
01388         if ( verbose_ ) std::cout << "Inserting RunDat ..." << std::endl;
01389         econn->insertDataSet(&dataset, &runiov_);
01390         if ( verbose_ ) std::cout << "done." << std::endl;
01391       } catch (std::runtime_error &e) {
01392         std::cerr << e.what() << std::endl;
01393       }
01394     }
01395 
01396   }
01397 
01398   // end - setup the RunDat (on behalf of the DAQ)
01399 
01400   if ( econn ) {
01401     try {
01402       if ( verbose_ ) std::cout << "Closing DB connection ..." << std::endl;
01403       delete econn;
01404       econn = 0;
01405       if ( verbose_ ) std::cout << "done." << std::endl;
01406     } catch (std::runtime_error &e) {
01407       std::cerr << e.what() << std::endl;
01408     }
01409   }
01410 #endif
01411 
01412 }
01413 
01414 void EcalBarrelMonitorClient::analyze(void) {
01415 
01416   current_time_ = time(NULL);
01417 
01418   ievt_++;
01419   jevt_++;
01420 
01421   if ( debug_ ) std::cout << "EcalBarrelMonitorClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
01422 
01423   MonitorElement* me;
01424   std::string s;
01425 
01426   me = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
01427   if ( me ) {
01428     status_ = "unknown";
01429     s = me->valueString();
01430     if ( strcmp(s.c_str(), "i=0") == 0 ) status_ = "begin-of-run";
01431     if ( strcmp(s.c_str(), "i=1") == 0 ) status_ = "running";
01432     if ( strcmp(s.c_str(), "i=2") == 0 ) status_ = "end-of-run";
01433     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/STATUS'" << std::endl;
01434   }
01435 
01436   if ( inputFile_.size() != 0 ) {
01437     if ( ievt_ == 1 ) {
01438       if ( verbose_ ) {
01439         std::cout << std::endl;
01440         std::cout << " Reading DQM from file, forcing 'begin-of-run'" << std::endl;
01441         std::cout << std::endl;
01442       }
01443       status_ = "begin-of-run";
01444     }
01445   }
01446 
01447   int ecal_run = -1;
01448   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
01449   if ( me ) {
01450     s = me->valueString();
01451     sscanf(s.c_str(), "i=%d", &ecal_run);
01452     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUN'" << std::endl;
01453   }
01454 
01455   int ecal_evt = -1;
01456   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
01457   if ( me ) {
01458     s = me->valueString();
01459     sscanf(s.c_str(), "i=%d", &ecal_evt);
01460     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/EVT'" << std::endl;
01461   }
01462 
01463   me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01464   h_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, h_ );
01465 
01466   me = dqmStore_->get(prefixME_ + "/EcalInfo/RUNTYPE");
01467   if ( me ) {
01468     s = me->valueString();
01469     sscanf(s.c_str(), "i=%d", &evtType_);
01470     if ( runType_ == -1 ) runType_ = evtType_;
01471     if ( debug_ ) std::cout << "Found '" << prefixME_ << "/EcalInfo/RUNTYPE'" << std::endl;
01472   }
01473 
01474   // if the run number from the Event is less than zero,
01475   // use the run number from the ECAL DCC header
01476   if ( run_ <= 0 ) run_ = ecal_run;
01477 
01478   if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01479     if ( ! mergeRuns_ && run_ != last_run_ ) forced_update_ = true;
01480   }
01481 
01482   bool update = ( forced_update_                    ) ||
01483                 ( prescaleFactor_ != 1              ) ||
01484                 ( jevt_ <   10                      ) ||
01485                 ( jevt_ <  100 && jevt_ %   10 == 0 ) ||
01486                 ( jevt_ < 1000 && jevt_ %  100 == 0 ) ||
01487                 (                 jevt_ % 1000 == 0 );
01488 
01489   if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01490 
01491     if ( verbose_ ) {
01492       std::cout << " RUN status = \"" << status_ << "\"" << std::endl;
01493       std::cout << "   CMS run/event number = " << run_ << "/" << evt_ << std::endl;
01494       std::cout << "   EB run/event number = " << ecal_run << "/" << ecal_evt << std::endl;
01495       std::cout << "   EB location = " << location_ << std::endl;
01496       std::cout << "   EB run/event type = " << this->getRunType() << "/" << ( evtType_ == -1 ? "UNKNOWN" : runTypes_[evtType_] ) << std::flush;
01497 
01498       if ( h_ ) {
01499         if ( h_->GetSumOfWeights() != 0 ) {
01500           std::cout << " ( " << std::flush;
01501           for ( unsigned int i = 0; i < runTypes_.size(); i++ ) {
01502             if ( strcmp(runTypes_[i].c_str(), "UNKNOWN") != 0 && h_->GetBinContent(2+i) != 0 ) {
01503               std::string s = runTypes_[i];
01504               transform( s.begin(), s.end(), s.begin(), (int(*)(int))tolower );
01505               std::cout << s << " ";
01506             }
01507           }
01508           std::cout << ")" << std::flush;
01509         }
01510       }
01511       std::cout << std::endl;
01512     }
01513 
01514   }
01515 
01516   if ( strcmp(status_.c_str(), "begin-of-run") == 0 ) {
01517 
01518     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01519 
01520       if ( ! begin_run_ ) {
01521 
01522         forced_status_ = false;
01523         this->beginRun();
01524 
01525       }
01526 
01527     }
01528 
01529   }
01530 
01531   if ( strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "running") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01532 
01533     if ( begin_run_ && ! end_run_ ) {
01534 
01535       bool update = ( forced_update_                      ) ||
01536                     ( prescaleFactor_ != 1                ) ||
01537                     ( jevt_ <     3                       ) ||
01538                     ( jevt_ <  1000 && jevt_ %   100 == 0 ) ||
01539                     ( jevt_ < 10000 && jevt_ %  1000 == 0 ) ||
01540                     (                  jevt_ % 10000 == 0 );
01541 
01542       if ( update || strcmp(status_.c_str(), "begin-of-run") == 0 || strcmp(status_.c_str(), "end-of-run") == 0 ) {
01543 
01544         for ( int i=0; i<int(clients_.size()); i++ ) {
01545           bool done = false;
01546           for ( std::multimap<EBClient*,int>::iterator j = clientsRuns_.lower_bound(clients_[i]); j != clientsRuns_.upper_bound(clients_[i]); j++ ) {
01547             if ( runType_ != -1 && runType_ == (*j).second && !done ) {
01548               done = true;
01549               clients_[i]->analyze();
01550             }
01551           }
01552         }
01553 
01554         if ( summaryClient_ ) summaryClient_->analyze();
01555 
01556       }
01557 
01558       forced_update_ = false;
01559 
01560       bool reset = false;
01561 
01562       if ( resetFile_.size() != 0 ) {
01563         if ( access(resetFile_.c_str(), W_OK) == 0 ) {
01564           if ( unlink(resetFile_.c_str()) == 0 ) {
01565             reset |= true;
01566           }
01567         }
01568       }
01569 
01570       if ( dbUpdateTime_ > 0 ) {
01571         reset |= (current_time_ - last_time_reset_) > 60 * dbUpdateTime_;
01572       }
01573 
01574       if ( reset ) {
01575         if ( runType_ == EcalDCCHeaderBlock::COSMIC ||
01576              runType_ == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
01577              runType_ == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
01578              runType_ == EcalDCCHeaderBlock::COSMICS_LOCAL ||
01579              runType_ == EcalDCCHeaderBlock::PHYSICS_LOCAL ||
01580              runType_ == EcalDCCHeaderBlock::BEAMH2 ||
01581              runType_ == EcalDCCHeaderBlock::BEAMH4 ) this->writeDb();
01582         this->softReset(true);
01583         last_time_reset_ = current_time_;
01584       }
01585 
01586     }
01587 
01588   }
01589 
01590   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01591 
01592     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01593 
01594       if ( begin_run_ && ! end_run_ ) {
01595 
01596         forced_status_ = false;
01597         this->endRun();
01598 
01599       }
01600 
01601     }
01602 
01603   }
01604 
01605   // BEGIN: run-time fixes for missing state transitions
01606 
01607   // run number transition
01608 
01609   if ( strcmp(status_.c_str(), "running") == 0 ) {
01610 
01611     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01612 
01613       if ( ! mergeRuns_ ) {
01614 
01615         int new_run_ = run_;
01616         int old_run_ = last_run_;
01617 
01618         if ( new_run_ != old_run_ ) {
01619 
01620           if ( begin_run_ && ! end_run_ ) {
01621 
01622             if ( verbose_ ) {
01623               std::cout << std::endl;
01624               std::cout << " Old run has finished, issuing endRun() ... " << std::endl;
01625               std::cout << std::endl;
01626             }
01627 
01628             // end old_run_
01629             run_ = old_run_;
01630 
01631             forced_status_ = false;
01632             this->endRun();
01633 
01634           }
01635 
01636           if ( ! begin_run_ ) {
01637 
01638             if ( verbose_ ) {
01639               std::cout << std::endl;
01640               std::cout << " New run has started, issuing beginRun() ... " << std::endl;
01641               std::cout << std::endl;
01642             }
01643 
01644             // start new_run_
01645             run_ = new_run_;
01646 
01647             forced_status_ = false;
01648             this->beginRun();
01649 
01650           }
01651 
01652         }
01653 
01654       }
01655 
01656     }
01657 
01658   }
01659 
01660   // 'running' state without a previous 'begin-of-run' state
01661 
01662   if ( strcmp(status_.c_str(), "running") == 0 ) {
01663 
01664     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01665 
01666       if ( ! forced_status_ ) {
01667 
01668         if ( ! begin_run_ ) {
01669 
01670           if ( verbose_ ) {
01671             std::cout << std::endl;
01672             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01673             std::cout << std::endl;
01674           }
01675 
01676           forced_status_ = true;
01677           this->beginRun();
01678 
01679         }
01680 
01681       }
01682 
01683     }
01684 
01685   }
01686 
01687   // 'end-of-run' state without a previous 'begin-of-run' or 'running' state
01688 
01689   if ( strcmp(status_.c_str(), "end-of-run") == 0 ) {
01690 
01691     if ( run_ != -1 && evt_ != -1 && runType_ != -1 ) {
01692 
01693       if ( ! forced_status_ ) {
01694 
01695         if ( ! begin_run_ ) {
01696 
01697           if ( verbose_ ) {
01698             std::cout << std::endl;
01699             std::cout << "Forcing beginRun() ... NOW !" << std::endl;
01700             std::cout << std::endl;
01701           }
01702 
01703           forced_status_ = true;
01704           this->beginRun();
01705 
01706         }
01707 
01708       }
01709 
01710     }
01711 
01712   }
01713 
01714   // END: run-time fixes for missing state transitions
01715 
01716 }
01717 
01718 void EcalBarrelMonitorClient::analyze(const edm::Event& e, const edm::EventSetup& c) {
01719 
01720   run_ = e.id().run();
01721   evt_ = e.id().event();
01722 
01723   if ( prescaleFactor_ > 0 ) {
01724     if ( jevt_ % prescaleFactor_ == 0 ) this->analyze();
01725   }
01726 
01727 }
01728 
01729 void EcalBarrelMonitorClient::softReset(bool flag) {
01730 
01731   std::vector<MonitorElement*> mes = dqmStore_->getAllContents(prefixME_);
01732   std::vector<MonitorElement*>::const_iterator meitr;
01733   for ( meitr=mes.begin(); meitr!=mes.end(); meitr++ ) {
01734     if ( !strncmp((*meitr)->getName().c_str(), "EB", 2)
01735          && strncmp((*meitr)->getName().c_str(), "EBTrend", 7)
01736          && strncmp((*meitr)->getName().c_str(), "by lumi", 7) ) {
01737       if ( flag ) {
01738         dqmStore_->softReset(*meitr);
01739       } else {
01740         dqmStore_->disableSoftReset(*meitr);
01741       }
01742     }
01743   }
01744 
01745   MonitorElement* me = dqmStore_->get(prefixME_ + "/EcalInfo/EVTTYPE");
01746   if ( me ) {
01747     if ( flag ) {
01748       dqmStore_->softReset(me);
01749     } else {
01750       dqmStore_->disableSoftReset(me);
01751     }
01752   }
01753 
01754 }
01755