CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripSpyExtractRunModule.cc
Go to the documentation of this file.
1 // Original Author: Anne-Marie Magnan
2 // Created: 2010/02/25
3 //
4 
5 #include <sstream>
6 #include <fstream>
7 #include <iostream>
8 #include <memory>
9 #include <list>
10 #include <algorithm>
11 #include <cassert>
12 
24 
27 
29 
30 //
31 // Class declaration
32 //
33 namespace sistrip {
34 
36  {
37  public:
38 
39  explicit SpyExtractRunModule(const edm::ParameterSet&);
41 
42  private:
43 
44  virtual void beginJob() override;
45  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
46  virtual void endJob() override;
47 
48  //check when the current run changes
49  const bool updateRun(const uint32_t aRun);
50 
51  //name of the output file containing the run number
52  //get it from the input file
54 
55  //tag of spydata run number collection
58 
59  //cache of the current and previous run number
60  uint32_t currentRun_;
61  uint32_t previousRun_;
62 
63  //error counter for number of times the run number changes
64  uint32_t errCounter_;
65 
66  };
67 }//namespace
68 
69 using edm::LogError;
70 using edm::LogWarning;
71 using edm::LogInfo;
72 //
73 // Constructors and destructor
74 //
75 namespace sistrip {
76 
78  : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
79  runTag_(iConfig.getParameter<edm::InputTag>("RunNumberTag")),
80  currentRun_(0),
81  previousRun_(0),
82  errCounter_(0)
83  {
84  runToken_ = consumes<uint32_t>(runTag_);
85  }
86 
87 
89 
90  }
91 
93  {
94  currentRun_ = 0;
95  previousRun_ = 0;
96  errCounter_ = 0;
97 
98  }
99 
100  void SpyExtractRunModule::analyze(const edm::Event& aEvt, const edm::EventSetup& aSetup)
101  {
102 
103  static bool lFirstEvent = true;
105  // aEvt.getByLabel( runTag_, lRun );
106  aEvt.getByToken( runToken_, lRun );
107 
108  const bool isUpdated = updateRun(*lRun);
109 
110  if (isUpdated && !lFirstEvent){
111  edm::LogError("SpyExtractRunModule") << " -- Run number changed for event : " << aEvt.id().event()
112  << " (id().run() = " << aEvt.id().run()
113  << ") from " << previousRun_ << " to " << currentRun_
114  << std::endl;
115  }
116 
117 
118  lFirstEvent = false;
119 
120  }
121 
122 
124 
125  //save global run number in text file in local directory
126  //output loginfo with number of errors
127  //or throw exception ?
128 
129 
130  if (errCounter_ == 1){
131  edm::LogInfo("SiStripSpyExtractRun") << " -- Writting run number " << currentRun_
132  << " into file " << fileName_
133  << std::endl;
134  std::ofstream lOutFile;
135  lOutFile.open(fileName_.c_str(),std::ios::out);
136  if (!lOutFile.is_open()) {
137  edm::LogError("SiStripSpyExtractRun") << " -- Cannot open file : " << fileName_ << " for writting run number "
138  << currentRun_
139  << std::endl;
140  }
141  else {
142  lOutFile << currentRun_ << std::endl;
143  lOutFile.close();
144  }
145 
146  }
147  else {
148  edm::LogError("SiStripSpyExtractRun") << " -- Number of times the run number changed in this job = " << errCounter_
149  << ", currentRun = " << currentRun_
150  << ", previousRun = " << previousRun_
151  << std::endl;
152  }
153 
154 
155  }
156 
157  const bool SpyExtractRunModule::updateRun(const uint32_t aRun) {
158  if (aRun != currentRun_){
160  currentRun_ = aRun;
161  errCounter_++;
162  return true;
163  }
164  return false;
165 
166  }
167 
168 }//namespace
169 
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< uint32_t > runToken_
const bool updateRun(const uint32_t aRun)
tuple out
Definition: dbtoconf.py:99
sistrip::SpyExtractRunModule SiStripSpyExtractRunModule
Constants and enumerated types for FED/FEC systems.
edm::EventID id() const
Definition: EventBase.h:56
SpyExtractRunModule(const edm::ParameterSet &)