Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:56

0001 /*
0002  * \file EcalBarrelMonitorDbModule.cc
0003  *
0004  * \author G. Della Ricca
0005  *
0006  */
0007 
0008 #include "DQM/EcalMonitorDbModule/interface/EcalBarrelMonitorDbModule.h"
0009 
0010 #include <unistd.h>
0011 
0012 #include <cmath>
0013 #include <iostream>
0014 
0015 #include "DQMServices/Core/interface/DQMStore.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 
0018 #include "RelationalAccess/IConnectionService.h"
0019 #include "RelationalAccess/IConnectionServiceConfiguration.h"
0020 
0021 #include "CoralBase/Attribute.h"
0022 #include "CoralKernel/Context.h"
0023 
0024 #include "DQM/EcalMonitorDbModule/interface/MonitorElementsDb.h"
0025 
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 
0028 EcalBarrelMonitorDbModule::EcalBarrelMonitorDbModule(const edm::ParameterSet &ps) {
0029   dqmStore_ = edm::Service<DQMStore>().operator->();
0030 
0031   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
0032 
0033   xmlFile_ = ps.getUntrackedParameter<std::string>("xmlFile", "");
0034   if (!xmlFile_.empty()) {
0035     std::cout << "Monitor Elements from DB xml source file is " << xmlFile_ << std::endl;
0036   }
0037 
0038   sleepTime_ = ps.getUntrackedParameter<int>("sleepTime", 0);
0039   std::cout << "Sleep time is " << sleepTime_ << " second(s)." << std::endl;
0040 
0041   // html output directory
0042   htmlDir_ = ps.getUntrackedParameter<std::string>("htmlDir", ".");
0043 
0044   if (!htmlDir_.empty()) {
0045     std::cout << " HTML output will go to"
0046               << " htmlDir = " << htmlDir_ << std::endl;
0047   } else {
0048     std::cout << " HTML output is disabled" << std::endl;
0049   }
0050 
0051   ME_Db_ = new MonitorElementsDb(ps, xmlFile_);
0052 
0053   icycle_ = 0;
0054   session_ = nullptr;
0055 }
0056 
0057 EcalBarrelMonitorDbModule::~EcalBarrelMonitorDbModule() {
0058   if (ME_Db_)
0059     delete ME_Db_;
0060 }
0061 
0062 void EcalBarrelMonitorDbModule::beginJob(void) {
0063   icycle_ = 0;
0064 
0065   if (ME_Db_)
0066     ME_Db_->beginJob();
0067 }
0068 
0069 void EcalBarrelMonitorDbModule::endJob(void) {
0070   if (ME_Db_)
0071     ME_Db_->endJob();
0072 
0073   std::cout << "EcalBarrelMonitorDbModule: endJob, icycle = " << icycle_ << std::endl;
0074 }
0075 
0076 void EcalBarrelMonitorDbModule::analyze(const edm::Event &e, const edm::EventSetup &c) {
0077   icycle_++;
0078 
0079   std::cout << "EcalBarrelMonitorDbModule: icycle = " << icycle_ << std::endl;
0080 
0081   try {
0082     coral::Context &context = coral::Context::instance();
0083     context.loadComponent("CORAL/Services/ConnectionService");
0084     context.loadComponent("CORAL/Services/EnvironmentAuthenticationService");
0085     coral::IHandle<coral::IConnectionService> connectionService =
0086         context.query<coral::IConnectionService>("CORAL/Services/ConnectionService");
0087     context.loadComponent("CORAL/RelationalPlugins/oracle");
0088 
0089     // Set configuration parameters
0090     coral::IConnectionServiceConfiguration &config = connectionService->configuration();
0091     config.setConnectionRetrialPeriod(1);
0092     config.setConnectionRetrialTimeOut(10);
0093 
0094     session_ = connectionService->connect("ECAL CondDB", coral::ReadOnly);
0095 
0096     if (ME_Db_)
0097       ME_Db_->analyze(e, c, session_);
0098 
0099   } catch (coral::Exception &e) {
0100     std::cerr << "CORAL Exception : " << e.what() << std::endl;
0101   } catch (std::exception &e) {
0102     std::cerr << "Standard C++ exception : " << e.what() << std::endl;
0103   }
0104 
0105   if (!htmlDir_.empty()) {
0106     ME_Db_->htmlOutput(htmlDir_);
0107   }
0108 
0109   delete session_;
0110 
0111   sleep(sleepTime_);
0112 }
0113 
0114 DEFINE_FWK_MODULE(EcalBarrelMonitorDbModule);