CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventWithHistoryProducerFromL1ABC.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventWithHistoryProducerFromL1ABC
4 // Class: EventWithHistoryProducerFromL1ABC
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Jun 30 15:26:20 CET 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <map>
23 
24 // user include files
27 
31 
33 
36 
39 //
40 // class decleration
41 //
42 
44  public:
47 
48  private:
49  virtual void beginJob() override ;
50  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
51  virtual void produce(edm::Event&, const edm::EventSetup&) override;
52  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
53  virtual void endJob() override ;
54 
55  // ----------member data ---------------------------
56 
58  const bool _forceNoOffset;
59  std::map<unsigned int, long long> _offsets;
60  long long _curroffset;
61  unsigned int _curroffevent;
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  _l1abccollection(iConfig.getParameter<edm::InputTag>("l1ABCCollection")),
78  _forceNoOffset(iConfig.getUntrackedParameter<bool>("forceNoOffset",false)),
79  _offsets(), _curroffset(0), _curroffevent(0)
80 {
81 
82  if(_forceNoOffset) edm::LogWarning("NoOffsetComputation") << "Orbit and BX offset will NOT be computed: Be careful!";
83 
84  produces<EventWithHistory>();
85 
86  //now do what ever other initialization is needed
87 
88 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called to produce the data ------------
105 void
107 {
108  using namespace edm;
109 
110  if(iEvent.run() < 110878 ) {
111 
112  std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent));
113  iEvent.put(pOut);
114 
115  }
116  else {
117 
119  iEvent.getByLabel(_l1abccollection,pIn);
120 
121  // offset computation
122 
123  long long orbitoffset = 0;
124  int bxoffset = 0;
125  if(!_forceNoOffset) {
126  for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
127  if(l1abc->l1AcceptOffset()==0) {
128  orbitoffset = (long long)l1abc->orbitNumber() - (long long)iEvent.orbitNumber();
129  bxoffset = l1abc->bunchCrossing() - iEvent.bunchCrossing();
130  }
131  }
132  }
133 
134 
135  std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent,*pIn,orbitoffset,bxoffset));
136  iEvent.put(pOut);
137 
138  // monitor offset
139 
140  long long absbxoffset = orbitoffset*3564 + bxoffset;
141 
142  if(_offsets.size()==0) {
143  _curroffset = absbxoffset;
144  _curroffevent = iEvent.id().event();
145  _offsets[iEvent.id().event()] = absbxoffset;
146  }
147  else {
148  if(_curroffset != absbxoffset || iEvent.id().event() < _curroffevent ) {
149 
150  if( _curroffset != absbxoffset) {
151  edm::LogInfo("AbsoluteBXOffsetChanged") << "Absolute BX offset changed from "
152  << _curroffset << " to "
153  << absbxoffset << " at orbit "
154  << iEvent.orbitNumber() << " and BX "
155  << iEvent.bunchCrossing();
156  for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
157  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *l1abc;
158  }
159  }
160 
161  _curroffset = absbxoffset;
162  _curroffevent = iEvent.id().event();
163  _offsets[iEvent.id().event()] = absbxoffset;
164  }
165  }
166  }
167 }
168 
169 // ------------ method called once each job just before starting event loop ------------
170 void
172 {
173 }
174 
175 void
177 {
178  // reset offset vector
179 
180  _offsets.clear();
181  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
182 
183 }
184 
185 void
187 {
188  // summary of absolute bx offset vector
189 
190  edm::LogInfo("AbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
191  for(std::map<unsigned int, long long>::const_iterator offset=_offsets.begin();offset!=_offsets.end();++offset) {
192  edm::LogVerbatim("AbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
193  }
194 
195 }
196 
197 // ------------ method called once each job just after ending the event loop ------------
198 void
200 }
201 
202 //define this as a plug-in
EventNumber_t event() const
Definition: EventID.h:44
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int bunchCrossing() const
Definition: EventBase.h:62
EventWithHistoryProducerFromL1ABC(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: Event.h:88
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
int orbitNumber() const
Definition: EventBase.h:63
unsigned int offset(bool)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EventID id() const
Definition: EventBase.h:56
volatile std::atomic< bool > shutdown_flag false
std::map< unsigned int, long long > _offsets
Definition: Run.h:41