File indexing completed on 2024-04-06 12:01:39
0001
0002
0003
0004
0005
0006
0007
0008 #include <stdexcept>
0009 #include <string>
0010 #include <iostream>
0011 #include <fstream>
0012
0013 #include "CondCore/CondDB/interface/Time.h"
0014
0015 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0016 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0017
0018 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023
0024 using namespace std;
0025
0026 namespace edmtest {
0027 class LumiTestReadAnalyzer : public edm::one::EDAnalyzer<> {
0028 public:
0029 explicit LumiTestReadAnalyzer(edm::ParameterSet const& p)
0030 : theBSToken_(esConsumes()),
0031 m_processId(p.getUntrackedParameter<std::string>("processId")),
0032 m_pathForLastLumiFile(p.getUntrackedParameter<std::string>("lastLumiFile", "")),
0033 m_pathForErrorFile("") {
0034 std::string pathForErrorFolder = p.getUntrackedParameter<std::string>("pathForErrorFile");
0035 m_pathForErrorFile = pathForErrorFolder + "/lumi_read_" + m_processId + ".txt";
0036 }
0037 explicit LumiTestReadAnalyzer(int i) {}
0038 virtual ~LumiTestReadAnalyzer() = default;
0039 virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
0040
0041 private:
0042 const edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> theBSToken_;
0043 std::string m_processId;
0044 std::string m_pathForLastLumiFile;
0045 std::string m_pathForErrorFile;
0046 };
0047
0048 void LumiTestReadAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0049 static constexpr const char* const MSGSOURCE = "LumiTestReadAnalyzer:";
0050 edm::eventsetup::EventSetupRecordKey recordKey(
0051 edm::eventsetup::EventSetupRecordKey::TypeTag::findType("BeamSpotObjectsRcd"));
0052 if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0053
0054 edm::LogError(MSGSOURCE) << "Record \"BeamSpotObjectsRcd\" does not exist ";
0055 }
0056 auto const& payload = &context.getData(theBSToken_);
0057 edm::LogInfo(MSGSOURCE) << "Event " << e.id().event() << " Run " << e.id().run() << " Lumi "
0058 << e.id().luminosityBlock() << " Time " << e.time().value() << " LumiTestPayload id "
0059 << payload->beamType() << std::endl;
0060
0061 unsigned int target = e.id().luminosityBlock();
0062 unsigned int found = payload->beamType();
0063 if (target != found) {
0064 boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
0065 std::stringstream msg;
0066 msg << "On time " << boost::posix_time::to_iso_extended_string(now) << " Target " << target << "; found "
0067 << found;
0068 edm::LogWarning(MSGSOURCE) << msg.str();
0069 edm::LogPrint("LumiTestReadAnalyzer") << "ERROR ( process " << m_processId << " ) : " << msg.str();
0070 edm::LogPrint("LumiTestReadAnalyzer") << "### dumping in file " << m_pathForErrorFile;
0071 {
0072 std::ofstream errorFile(m_pathForErrorFile, std::ios_base::app);
0073 errorFile << msg.str() << std::endl;
0074 }
0075
0076 } else {
0077 edm::LogPrint("LumiTestReadAnalyzer") << "Info: read was ok.";
0078 }
0079 }
0080 DEFINE_FWK_MODULE(LumiTestReadAnalyzer);
0081 }