Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <sstream>
00007 #include <fstream>
00008 #include <iostream>
00009 #include <memory>
00010 #include <list>
00011 #include <algorithm>
00012 #include <cassert>
00013
00014 #include "FWCore/Framework/interface/Frameworkfwd.h"
00015 #include "FWCore/Framework/interface/EDAnalyzer.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/Framework/interface/ESHandle.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/Utilities/interface/InputTag.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/ServiceRegistry/interface/Service.h"
00023 #include "FWCore/Utilities/interface/Exception.h"
00024
00025 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00026 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
00027
00028 #include "DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h"
00029
00030
00031
00032
00033 namespace sistrip {
00034
00035 class SpyExtractRunModule : public edm::EDAnalyzer
00036 {
00037 public:
00038
00039 explicit SpyExtractRunModule(const edm::ParameterSet&);
00040 ~SpyExtractRunModule();
00041
00042 private:
00043
00044 virtual void beginJob();
00045 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00046 virtual void endJob();
00047
00048
00049 const bool updateRun(const uint32_t aRun);
00050
00051
00052
00053 std::string fileName_;
00054
00055
00056 edm::InputTag runTag_;
00057
00058
00059 uint32_t currentRun_;
00060 uint32_t previousRun_;
00061
00062
00063 uint32_t errCounter_;
00064
00065 };
00066 }
00067
00068 using edm::LogError;
00069 using edm::LogWarning;
00070 using edm::LogInfo;
00071
00072
00073
00074 namespace sistrip {
00075
00076 SpyExtractRunModule::SpyExtractRunModule(const edm::ParameterSet& iConfig)
00077 : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
00078 runTag_(iConfig.getParameter<edm::InputTag>("RunNumberTag")),
00079 currentRun_(0),
00080 previousRun_(0),
00081 errCounter_(0)
00082 {
00083
00084 }
00085
00086
00087 SpyExtractRunModule::~SpyExtractRunModule() {
00088
00089 }
00090
00091 void SpyExtractRunModule::beginJob()
00092 {
00093 currentRun_ = 0;
00094 previousRun_ = 0;
00095 errCounter_ = 0;
00096
00097 }
00098
00099 void SpyExtractRunModule::analyze(const edm::Event& aEvt, const edm::EventSetup& aSetup)
00100 {
00101
00102 static bool lFirstEvent = true;
00103 edm::Handle<uint32_t> lRun;
00104 aEvt.getByLabel( runTag_, lRun );
00105
00106 const bool isUpdated = updateRun(*lRun);
00107
00108 if (isUpdated && !lFirstEvent){
00109 edm::LogError("SpyExtractRunModule") << " -- Run number changed for event : " << aEvt.id().event()
00110 << " (id().run() = " << aEvt.id().run()
00111 << ") from " << previousRun_ << " to " << currentRun_
00112 << std::endl;
00113 }
00114
00115
00116 lFirstEvent = false;
00117
00118 }
00119
00120
00121 void SpyExtractRunModule::endJob() {
00122
00123
00124
00125
00126
00127
00128 if (errCounter_ == 1){
00129 edm::LogInfo("SiStripSpyExtractRun") << " -- Writting run number " << currentRun_
00130 << " into file " << fileName_
00131 << std::endl;
00132 std::ofstream lOutFile;
00133 lOutFile.open(fileName_.c_str(),std::ios::out);
00134 if (!lOutFile.is_open()) {
00135 edm::LogError("SiStripSpyExtractRun") << " -- Cannot open file : " << fileName_ << " for writting run number "
00136 << currentRun_
00137 << std::endl;
00138 }
00139 else {
00140 lOutFile << currentRun_ << std::endl;
00141 lOutFile.close();
00142 }
00143
00144 }
00145 else {
00146 edm::LogError("SiStripSpyExtractRun") << " -- Number of times the run number changed in this job = " << errCounter_
00147 << ", currentRun = " << currentRun_
00148 << ", previousRun = " << previousRun_
00149 << std::endl;
00150 }
00151
00152
00153 }
00154
00155 const bool SpyExtractRunModule::updateRun(const uint32_t aRun) {
00156 if (aRun != currentRun_){
00157 previousRun_ = currentRun_;
00158 currentRun_ = aRun;
00159 errCounter_++;
00160 return true;
00161 }
00162 return false;
00163
00164 }
00165
00166 }
00167
00168 #include "FWCore/Framework/interface/MakerMacros.h"
00169 typedef sistrip::SpyExtractRunModule SiStripSpyExtractRunModule;
00170 DEFINE_FWK_MODULE(SiStripSpyExtractRunModule);