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.getByToken( runToken_, lRun );
106 
107  const bool isUpdated = updateRun(*lRun);
108 
109  if (isUpdated && !lFirstEvent){
110  edm::LogError("SpyExtractRunModule") << " -- Run number changed for event : " << aEvt.id().event()
111  << " (id().run() = " << aEvt.id().run()
112  << ") from " << previousRun_ << " to " << currentRun_
113  << std::endl;
114  }
115 
116 
117  lFirstEvent = false;
118 
119  }
120 
121 
123 
124  //save global run number in text file in local directory
125  //output loginfo with number of errors
126  //or throw exception ?
127 
128 
129  if (errCounter_ == 1){
130  edm::LogInfo("SiStripSpyExtractRun") << " -- Writting run number " << currentRun_
131  << " into file " << fileName_
132  << std::endl;
133  std::ofstream lOutFile;
134  lOutFile.open(fileName_.c_str(),std::ios::out);
135  if (!lOutFile.is_open()) {
136  edm::LogError("SiStripSpyExtractRun") << " -- Cannot open file : " << fileName_ << " for writting run number "
137  << currentRun_
138  << std::endl;
139  }
140  else {
141  lOutFile << currentRun_ << std::endl;
142  lOutFile.close();
143  }
144 
145  }
146  else {
147  edm::LogError("SiStripSpyExtractRun") << " -- Number of times the run number changed in this job = " << errCounter_
148  << ", currentRun = " << currentRun_
149  << ", previousRun = " << previousRun_
150  << std::endl;
151  }
152 
153 
154  }
155 
156  const bool SpyExtractRunModule::updateRun(const uint32_t aRun) {
157  if (aRun != currentRun_){
159  currentRun_ = aRun;
160  errCounter_++;
161  return true;
162  }
163  return false;
164 
165  }
166 
167 }//namespace
168 
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#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:60
SpyExtractRunModule(const edm::ParameterSet &)