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 // $Id: SiStripSpyExtractRunModule.cc,v 1.2 2010/03/15 03:33:35 wmtan Exp $
4 //
5 
6 #include <sstream>
7 #include <fstream>
8 #include <iostream>
9 #include <memory>
10 #include <list>
11 #include <algorithm>
12 #include <cassert>
13 
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();
45  virtual void analyze(const edm::Event&, const edm::EventSetup&);
46  virtual void endJob();
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
53  std::string fileName_;
54 
55  //tag of spydata run number collection
57 
58  //cache of the current and previous run number
59  uint32_t currentRun_;
60  uint32_t previousRun_;
61 
62  //error counter for number of times the run number changes
63  uint32_t errCounter_;
64 
65  };
66 }//namespace
67 
68 using edm::LogError;
69 using edm::LogWarning;
70 using edm::LogInfo;
71 //
72 // Constructors and destructor
73 //
74 namespace sistrip {
75 
77  : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
78  runTag_(iConfig.getParameter<edm::InputTag>("RunNumberTag")),
79  currentRun_(0),
80  previousRun_(0),
81  errCounter_(0)
82  {
83 
84  }
85 
86 
88 
89  }
90 
92  {
93  currentRun_ = 0;
94  previousRun_ = 0;
95  errCounter_ = 0;
96 
97  }
98 
99  void SpyExtractRunModule::analyze(const edm::Event& aEvt, const edm::EventSetup& aSetup)
100  {
101 
102  static bool lFirstEvent = true;
104  aEvt.getByLabel( runTag_, lRun );
105 
106  const bool isUpdated = updateRun(*lRun);
107 
108  if (isUpdated && !lFirstEvent){
109  edm::LogError("SpyExtractRunModule") << " -- Run number changed for event : " << aEvt.id().event()
110  << " (id().run() = " << aEvt.id().run()
111  << ") from " << previousRun_ << " to " << currentRun_
112  << std::endl;
113  }
114 
115 
116  lFirstEvent = false;
117 
118  }
119 
120 
122 
123  //save global run number in text file in local directory
124  //output loginfo with number of errors
125  //or throw exception ?
126 
127 
128  if (errCounter_ == 1){
129  edm::LogInfo("SiStripSpyExtractRun") << " -- Writting run number " << currentRun_
130  << " into file " << fileName_
131  << std::endl;
132  std::ofstream lOutFile;
133  lOutFile.open(fileName_.c_str(),std::ios::out);
134  if (!lOutFile.is_open()) {
135  edm::LogError("SiStripSpyExtractRun") << " -- Cannot open file : " << fileName_ << " for writting run number "
136  << currentRun_
137  << std::endl;
138  }
139  else {
140  lOutFile << currentRun_ << std::endl;
141  lOutFile.close();
142  }
143 
144  }
145  else {
146  edm::LogError("SiStripSpyExtractRun") << " -- Number of times the run number changed in this job = " << errCounter_
147  << ", currentRun = " << currentRun_
148  << ", previousRun = " << previousRun_
149  << std::endl;
150  }
151 
152 
153  }
154 
155  const bool SpyExtractRunModule::updateRun(const uint32_t aRun) {
156  if (aRun != currentRun_){
158  currentRun_ = aRun;
159  errCounter_++;
160  return true;
161  }
162  return false;
163 
164  }
165 
166 }//namespace
167 
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const bool updateRun(const uint32_t aRun)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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 &)