Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:43

0001 // system include files
0002 #include <memory>
0003 #include <iostream>
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "CondCore/CondDB/interface/Time.h"
0011 
0012 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
0013 #include "CondFormats/AlignmentRecord/interface/CTPPSRPAlignmentCorrectionsDataRcd.h"
0014 #include "CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h"
0015 #include "CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h"
0016 
0017 using namespace std;
0018 
0019 class CTPPSRPAlignmentInfoReader : public edm::one::EDAnalyzer<> {
0020 public:
0021   cond::Time_t iov_;
0022   std::string record_;
0023 
0024   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, CTPPSRPAlignmentCorrectionsDataRcd> tokenAlignmentsIdeal_;
0025   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord> tokenAlignmentsReal_;
0026   edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord> tokenAlignmentsMisaligned_;
0027 
0028   explicit CTPPSRPAlignmentInfoReader(edm::ParameterSet const& iConfig);
0029 
0030   explicit CTPPSRPAlignmentInfoReader(int i) {}
0031   ~CTPPSRPAlignmentInfoReader() override {}
0032   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0033   void printInfo(const CTPPSRPAlignmentCorrectionsData& alignments, const edm::Event& event);
0034 };
0035 
0036 //----------------------------------------------------------------------------------------------------
0037 
0038 CTPPSRPAlignmentInfoReader::CTPPSRPAlignmentInfoReader(edm::ParameterSet const& iConfig)
0039     : iov_(iConfig.getParameter<unsigned long long>("iov")), record_(iConfig.getParameter<string>("record")) {
0040   if (strcmp(record_.c_str(), "CTPPSRPAlignmentCorrectionsDataRcd") == 0) {
0041     tokenAlignmentsIdeal_ = esConsumes<CTPPSRPAlignmentCorrectionsData, CTPPSRPAlignmentCorrectionsDataRcd>();
0042   } else if (strcmp(record_.c_str(), "RPRealAlignmentRecord") == 0) {
0043     tokenAlignmentsReal_ = esConsumes<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>();
0044   } else {
0045     tokenAlignmentsMisaligned_ = esConsumes<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>();
0046   }
0047 }
0048 
0049 //----------------------------------------------------------------------------------------------------
0050 
0051 void CTPPSRPAlignmentInfoReader::analyze(const edm::Event& e, const edm::EventSetup& context) {
0052   using namespace edm;
0053 
0054   //this part gets the handle of the event source and the record (i.e. the Database)
0055   if (e.id().run() == iov_) {
0056     ESHandle<CTPPSRPAlignmentCorrectionsData> hAlignments;
0057 
0058     if (strcmp(record_.c_str(), "CTPPSRPAlignmentCorrectionsDataRcd") == 0) {
0059       hAlignments = context.getHandle(tokenAlignmentsIdeal_);
0060     } else if (strcmp(record_.c_str(), "RPRealAlignmentRecord") == 0) {
0061       hAlignments = context.getHandle(tokenAlignmentsReal_);
0062     } else {
0063       hAlignments = context.getHandle(tokenAlignmentsMisaligned_);
0064     }
0065 
0066     //std::cout
0067     edm::LogPrint("CTPPSRPAlignmentInfoReader")
0068         << "New alignments found in run=" << e.id().run() << ", event=" << e.id().event() << ":\n"
0069         << *hAlignments;
0070   }
0071 }
0072 
0073 DEFINE_FWK_MODULE(CTPPSRPAlignmentInfoReader);