Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-16 23:25:23

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDProducers and EDProducts for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include <stdexcept>
0009 #include <string>
0010 #include <iostream>
0011 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0019 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0020 #include "CondCore/CondDB/interface/Time.h"
0021 #include "CondCore/CondDB/interface/ConnectionPool.h"
0022 #include <fstream>
0023 
0024 using namespace std;
0025 
0026 namespace edmtest {
0027   class LumiTestWriteReadAnalyzer : public edm::one::EDAnalyzer<> {
0028   public:
0029     explicit LumiTestWriteReadAnalyzer(edm::ParameterSet const& p);
0030     explicit LumiTestWriteReadAnalyzer(int i) {}
0031     virtual ~LumiTestWriteReadAnalyzer() {}
0032 
0033     virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0034 
0035   private:
0036     const edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> m_token;
0037   };
0038 
0039   LumiTestWriteReadAnalyzer::LumiTestWriteReadAnalyzer(edm::ParameterSet const&)
0040       : m_token(esConsumes<BeamSpotObjects, BeamSpotObjectsRcd>()) {}
0041 
0042   void LumiTestWriteReadAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0043     static constexpr const char* const MSGSOURCE = "LumiTestWriteReadAnalyzer:";
0044     edm::eventsetup::EventSetupRecordKey recordKey(
0045         edm::eventsetup::EventSetupRecordKey::TypeTag::findType("BeamSpotObjectsRcd"));
0046     if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0047       //record not found
0048       edm::LogError(MSGSOURCE) << "Record \"BeamSpotObjectsRcd\" does not exist ";
0049     }
0050     auto const& payload = context.getData(m_token);
0051     edm::LogInfo(MSGSOURCE) << "Event " << e.id().event() << " Run " << e.id().run() << " Lumi "
0052                             << e.id().luminosityBlock() << " Time " << e.time().value() << " LumiTestPayload id "
0053                             << payload.beamType() << std::endl;
0054     unsigned int target = e.id().luminosityBlock();
0055     unsigned int found = payload.beamType();
0056     if (target != found) {
0057       boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
0058       std::stringstream msg;
0059       msg << "On time " << boost::posix_time::to_iso_extended_string(now) << " Target " << target << "; found "
0060           << found;
0061       edm::LogError(MSGSOURCE) << msg.str();
0062     } else {
0063       edm::LogInfo(MSGSOURCE) << "Read target payload was ok." << std::endl;
0064     }
0065   }
0066   DEFINE_FWK_MODULE(LumiTestWriteReadAnalyzer);
0067 }  // namespace edmtest