Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-31 03:08:36

0001 /****************************************************************************
0002  *
0003  * Authors:
0004  *  Jan Kaspar
0005  * Adapted by:
0006  *  Helena Malbouisson
0007  *  Clemencia Mora Herrera  
0008  ****************************************************************************/
0009 
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Utilities/interface/ESGetToken.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/ESWatcher.h"
0019 #include "CondCore/CondDB/interface/Time.h"
0020 #include "FWCore/ServiceRegistry/interface/Service.h"
0021 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0022 
0023 #include "CondFormats/AlignmentRecord/interface/CTPPSRPAlignmentCorrectionsDataRcd.h"
0024 #include "CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h"
0025 #include "CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h"
0026 
0027 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
0028 #include <string>
0029 
0030 //----------------------------------------------------------------------------------------------------
0031 
0032 /**
0033  * \brief Class to print out information on current geometry.
0034  **/
0035 class CTPPSRPAlignmentInfoAnalyzer : public edm::one::EDAnalyzer<> {
0036 public:
0037   CTPPSRPAlignmentInfoAnalyzer(const edm::ParameterSet& ps);
0038   ~CTPPSRPAlignmentInfoAnalyzer() override {}
0039 
0040 private:
0041   void analyze(const edm::Event& e, const edm::EventSetup& es) override;
0042 
0043   void printInfo(const CTPPSRPAlignmentCorrectionsData& alignments, const edm::Event& event) const;
0044 
0045   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, CTPPSRPAlignmentCorrectionsDataRcd> tokenAlignmentIdeal_;
0046   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord> tokenAlignmentReal_;
0047   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord> tokenAlignmentMisaligned_;
0048 
0049   std::string record_;
0050   cond::Time_t iov_;
0051 };
0052 
0053 //----------------------------------------------------------------------------------------------------
0054 //----------------------------------------------------------------------------------------------------
0055 
0056 using namespace std;
0057 using namespace edm;
0058 
0059 //----------------------------------------------------------------------------------------------------
0060 
0061 CTPPSRPAlignmentInfoAnalyzer::CTPPSRPAlignmentInfoAnalyzer(const edm::ParameterSet& iConfig)
0062     : record_(iConfig.getParameter<string>("record")), iov_(iConfig.getParameter<unsigned long long>("iov")) {
0063   if (strcmp(record_.c_str(), "CTPPSRPAlignmentCorrectionsDataRcd") == 0) {
0064     tokenAlignmentIdeal_ = esConsumes<CTPPSRPAlignmentCorrectionsData, CTPPSRPAlignmentCorrectionsDataRcd>();
0065   } else if (strcmp(record_.c_str(), "RPRealAlignmentRecord") == 0) {
0066     tokenAlignmentReal_ = esConsumes<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>();
0067   } else {
0068     tokenAlignmentMisaligned_ = esConsumes<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>();
0069   }
0070 }
0071 
0072 //----------------------------------------------------------------------------------------------------
0073 
0074 void CTPPSRPAlignmentInfoAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075   const auto alignments = [&r = record_,
0076                            &eS = iSetup,
0077                            &tAI = tokenAlignmentIdeal_,
0078                            &tAR = tokenAlignmentReal_,
0079                            &tAM = tokenAlignmentMisaligned_]() -> const CTPPSRPAlignmentCorrectionsData {
0080     if (r == "CTPPSRPAlignmentCorrectionsDataRcd") {
0081       return eS.getData(tAI);
0082     } else if (r == "RPRealAlignmentRecord") {
0083       return eS.getData(tAR);
0084     } else {
0085       return eS.getData(tAM);
0086     }
0087   }();
0088 
0089   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0090   if (!poolDbService.isAvailable()) {
0091     edm::LogError("CTPPSAlignmentInfoAnalyzer") << " DbService not available ";
0092   } else {
0093     poolDbService->writeOneIOV(alignments, iov_, record_);
0094   }
0095 }
0096 
0097 //----------------------------------------------------------------------------------------------------
0098 
0099 void CTPPSRPAlignmentInfoAnalyzer::printInfo(const CTPPSRPAlignmentCorrectionsData& alignments,
0100                                              const edm::Event& event) const {
0101   time_t unixTime = event.time().unixTime();
0102   char timeStr[50];
0103   strftime(timeStr, 50, "%F %T", localtime(&unixTime));
0104 
0105   edm::LogInfo("CTPPSRPAlignmentInfoAnalyzer")
0106       << "New  alignments found in run=" << event.id().run() << ", event=" << event.id().event()
0107       << ", UNIX timestamp=" << unixTime << " (" << timeStr << "):\n"
0108       << alignments;
0109 }
0110 
0111 //----------------------------------------------------------------------------------------------------
0112 
0113 DEFINE_FWK_MODULE(CTPPSRPAlignmentInfoAnalyzer);