Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-13 03:30:59

0001 #include <string>
0002 
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "Utilities/General/interface/ClassName.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/Utilities/interface/ESGetToken.h"
0012 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0013 
0014 #include "CondFormats/Alignment/interface/Alignments.h"
0015 #include "CondFormats/Alignment/interface/AlignTransform.h"
0016 
0017 #include "CondFormats/AlignmentRecord/interface/EBAlignmentRcd.h"
0018 #include "CondFormats/AlignmentRecord/interface/EEAlignmentRcd.h"
0019 #include "CondFormats/AlignmentRecord/interface/ESAlignmentRcd.h"
0020 
0021 class CaloAlignmentRcdWrite : public edm::one::EDAnalyzer<> {
0022 public:
0023   explicit CaloAlignmentRcdWrite(const edm::ParameterSet& /*iConfig*/)
0024       : ebToken_{esConsumes<Alignments, EBAlignmentRcd>(edm::ESInputTag{})},
0025         eeToken_{esConsumes<Alignments, EEAlignmentRcd>(edm::ESInputTag{})},
0026         esToken_{esConsumes<Alignments, ESAlignmentRcd>(edm::ESInputTag{})},
0027         nEventCalls_(0) {}
0028   ~CaloAlignmentRcdWrite() override {}
0029 
0030   template <typename T>
0031   void writeAlignments(const edm::EventSetup& evtSetup, edm::ESGetToken<Alignments, T>& token);
0032 
0033   void beginJob() override {}
0034   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0035   void endJob() override {}
0036 
0037 private:
0038   edm::ESGetToken<Alignments, EBAlignmentRcd> ebToken_;
0039   edm::ESGetToken<Alignments, EEAlignmentRcd> eeToken_;
0040   edm::ESGetToken<Alignments, ESAlignmentRcd> esToken_;
0041 
0042   unsigned int nEventCalls_;
0043 };
0044 
0045 template <typename T>
0046 void CaloAlignmentRcdWrite::writeAlignments(const edm::EventSetup& evtSetup, edm::ESGetToken<Alignments, T>& token) {
0047   const auto& alignmentsES = evtSetup.getData(token);
0048 
0049   std::string recordName = Demangle(typeid(T).name())();
0050 
0051   edm::LogInfo("CaloAlignmentRcdWrite") << "Uploading alignments to the database: " << recordName;
0052 
0053   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0054 
0055   if (!poolDbService.isAvailable())
0056     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0057 
0058   const Alignments alignments(alignmentsES);
0059 
0060   poolDbService->writeOneIOV<Alignments>(alignments, poolDbService->currentTime(), recordName);
0061 }
0062 
0063 void CaloAlignmentRcdWrite::analyze(const edm::Event& /*evt*/, const edm::EventSetup& evtSetup) {
0064   if (nEventCalls_ > 0) {
0065     edm::LogInfo("CaloAlignmentRcdWrite") << "Writing to DB to be done only once, "
0066                                           << "set 'untracked PSet maxEvents = {untracked int32 input = 1}'."
0067                                           << "(Your writing should be fine.)";
0068     return;
0069   }
0070 
0071   writeAlignments<EBAlignmentRcd>(evtSetup, ebToken_);
0072   writeAlignments<EEAlignmentRcd>(evtSetup, eeToken_);
0073   writeAlignments<ESAlignmentRcd>(evtSetup, esToken_);
0074 
0075   edm::LogInfo("CaloAlignmentRcdWrite") << "done!";
0076   nEventCalls_++;
0077 }
0078 
0079 DEFINE_FWK_MODULE(CaloAlignmentRcdWrite);