diff --git a/CondTools/Ecal/interface/EcalTimeCalibHandler.h b/CondTools/Ecal/interface/EcalTimeCalibHandler.h new file mode 100644 index 0000000000000..46654f6032705 --- /dev/null +++ b/CondTools/Ecal/interface/EcalTimeCalibHandler.h @@ -0,0 +1,37 @@ +#ifndef CondTools_Ecal_EcalTimeCalibHandler_h +#define CondTools_Ecal_EcalTimeCalibHandler_h + +#include "CondCore/PopCon/interface/PopConSourceHandler.h" +#include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h" +#include "CondTools/Ecal/interface/EcalCondHeader.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "OnlineDB/EcalCondDB/interface/all_monitoring_types.h" +#include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h" + +#include + +namespace popcon { + class EcalTimeCalibHandler : public popcon::PopConSourceHandler { + public: + EcalTimeCalibHandler(edm::ParameterSet const&); + ~EcalTimeCalibHandler() override = default; + + void getNewObjects() override; + void readXML(const std::string& filename, EcalFloatCondObjectContainer& record); + void readTXT(const std::string& filename, EcalFloatCondObjectContainer& record); + + std::string id() const override { return m_name; } + EcalCondDBInterface* econn; + + private: + const std::string m_name; + const unsigned int m_firstRun; + const std::string m_file_name; + const std::string m_file_type; + }; +} // namespace popcon +#endif diff --git a/CondTools/Ecal/plugins/TestEcalTimeCalibAnalyzer.cc b/CondTools/Ecal/plugins/TestEcalTimeCalibAnalyzer.cc new file mode 100644 index 0000000000000..769ed3f82ea19 --- /dev/null +++ b/CondTools/Ecal/plugins/TestEcalTimeCalibAnalyzer.cc @@ -0,0 +1,8 @@ +#include "CondCore/PopCon/interface/PopConAnalyzer.h" +#include "CondTools/Ecal/interface/EcalTimeCalibHandler.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +typedef popcon::PopConAnalyzer ExTestEcalTimeCalibAnalyzer; + +//define this as a plug-in +DEFINE_FWK_MODULE(ExTestEcalTimeCalibAnalyzer); diff --git a/CondTools/Ecal/python/updateTimeCalib_cfg.py b/CondTools/Ecal/python/updateTimeCalib_cfg.py new file mode 100644 index 0000000000000..196fe602f8f81 --- /dev/null +++ b/CondTools/Ecal/python/updateTimeCalib_cfg.py @@ -0,0 +1,47 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("ProcessOne") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.enable = False +process.MessageLogger.cout.enable = True +process.MessageLogger.cout.threshold = cms.untracked.string('DEBUG') +process.MessageLogger.debugModules = cms.untracked.vstring('*') + +process.source = cms.Source("EmptyIOVSource", + lastValue = cms.uint64(100000000000), + timetype = cms.string('runnumber'), + firstValue = cms.uint64(100000000000), + interval = cms.uint64(1) +) + +process.load("CondCore.CondDB.CondDB_cfi") + +process.CondDB.connect = 'sqlite_file:EcalTimeCalibConstants_minus_delays.db' + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + process.CondDB, + logconnect = cms.untracked.string('sqlite_file:log.db'), + toPut = cms.VPSet( + cms.PSet( + record = cms.string('EcalTimeCalibConstantsRcd'), + tag = cms.string('EcalTimeCalibConstants') + ) + ) +) + +process.Test1 = cms.EDAnalyzer("ExTestEcalTimeCalibAnalyzer", + record = cms.string('EcalTimeCalibConstantsRcd'), + loggingOn= cms.untracked.bool(True), + IsDestDbCheckedInQueryLog=cms.untracked.bool(True), + SinceAppendMode=cms.bool(True), + Source=cms.PSet( + firstRun = cms.string('1'), + type = cms.string('txt'), + fileName = cms.string('dump_EcalTimeCalibConstants__new_minus_delays.dat'), +# type = cms.string('xml'), +# fileName = cms.string('EcalTimeCalibConstants_minus_delays.xml'), + ) +) + +process.p = cms.Path(process.Test1) diff --git a/CondTools/Ecal/src/EcalTimeCalibHandler.cc b/CondTools/Ecal/src/EcalTimeCalibHandler.cc new file mode 100644 index 0000000000000..d5b7cb12ca029 --- /dev/null +++ b/CondTools/Ecal/src/EcalTimeCalibHandler.cc @@ -0,0 +1,112 @@ +#include "CondTools/Ecal/interface/EcalTimeCalibHandler.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include +#include +#include +#include +#include + +const Int_t kEBChannels = 61200, kEEChannels = 14648; + +popcon::EcalTimeCalibHandler::EcalTimeCalibHandler(const edm::ParameterSet& ps) + : m_name(ps.getUntrackedParameter("name", "EcalTimeCalibHandler")), + m_firstRun(static_cast(atoi(ps.getParameter("firstRun").c_str()))), + m_file_name(ps.getParameter("fileName")), + m_file_type(ps.getParameter("type")) // xml/txt +{ + edm::LogInfo("EcalTimeCalib Source handler constructor\n"); +} + +void popcon::EcalTimeCalibHandler::getNewObjects() { + edm::LogInfo("going to open file ") << m_file_name; + + // EcalCondHeader header; + EcalTimeCalibConstants* payload = new EcalTimeCalibConstants; + if (m_file_type == "xml") + readXML(m_file_name, *payload); + else + readTXT(m_file_name, *payload); + Time_t snc = (Time_t)m_firstRun; + + popcon::PopConSourceHandler::m_to_transfer.push_back(std::make_pair(payload, snc)); +} + +void popcon::EcalTimeCalibHandler::readXML(const std::string& file_, EcalFloatCondObjectContainer& record) { + std::string dummyLine, bid; + std::ifstream fxml; + fxml.open(file_); + if (!fxml.is_open()) { + throw cms::Exception("ERROR : cannot open file ") << file_; + } + // header + for (int i = 0; i < 6; i++) { + getline(fxml, dummyLine); // skip first lines + } + fxml >> bid; + std::string stt = bid.substr(7, 5); + std::istringstream iEB(stt); + int nEB; + iEB >> nEB; + if (nEB != kEBChannels) { + throw cms::Exception("Strange number of EB channels ") << nEB; + } + fxml >> bid; // 0 + for (int iChannel = 0; iChannel < kEBChannels; iChannel++) { + EBDetId myEBDetId = EBDetId::unhashIndex(iChannel); + fxml >> bid; + std::size_t found = bid.find("> bid; + stt = bid.substr(7, 5); + std::istringstream iEE(stt); + int nEE; + iEE >> nEE; + if (nEE != kEEChannels) { + throw cms::Exception("Strange number of EE channels ") << nEE; + } + fxml >> bid; // 0 + // now endcaps + for (int iChannel = 0; iChannel < kEEChannels; iChannel++) { + EEDetId myEEDetId = EEDetId::unhashIndex(iChannel); + fxml >> bid; + std::size_t found = bid.find("