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 beginRun(const edm::Run&, const edm::EventSetup&) override;
50  virtual void produce(edm::Event&, const edm::EventSetup&) override;
51  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
52 
53  // ----------member data ---------------------------
54 
56  const bool _forceNoOffset;
57  std::map<edm::EventNumber_t, long long> _offsets;
58  long long _curroffset;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  _l1abccollectionToken(mayConsume<L1AcceptBunchCrossingCollection>(iConfig.getParameter<edm::InputTag>("l1ABCCollection"))),
76  _forceNoOffset(iConfig.getUntrackedParameter<bool>("forceNoOffset",false)),
77  _offsets(), _curroffset(0), _curroffevent(0)
78 {
79 
80  if(_forceNoOffset) edm::LogWarning("NoOffsetComputation") << "Orbit and BX offset will NOT be computed: Be careful!";
81 
82  produces<EventWithHistory>();
83 
84  //now do what ever other initialization is needed
85 
86 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to produce the data ------------
103 void
105 {
106  using namespace edm;
107 
108  if(iEvent.run() < 110878 ) {
109 
110  std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent));
111  iEvent.put(pOut);
112 
113  }
114  else {
115 
117  iEvent.getByToken(_l1abccollectionToken,pIn);
118 
119  // offset computation
120 
121  long long orbitoffset = 0;
122  int bxoffset = 0;
123  if(!_forceNoOffset) {
124  for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
125  if(l1abc->l1AcceptOffset()==0) {
126  orbitoffset = (long long)l1abc->orbitNumber() - (long long)iEvent.orbitNumber();
127  bxoffset = l1abc->bunchCrossing() - iEvent.bunchCrossing();
128  }
129  }
130  }
131 
132 
133  std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent,*pIn,orbitoffset,bxoffset));
134  iEvent.put(pOut);
135 
136  // monitor offset
137 
138  long long absbxoffset = orbitoffset*3564 + bxoffset;
139 
140  if(_offsets.size()==0) {
141  _curroffset = absbxoffset;
142  _curroffevent = iEvent.id().event();
143  _offsets[iEvent.id().event()] = absbxoffset;
144  }
145  else {
146  if(_curroffset != absbxoffset || iEvent.id().event() < _curroffevent ) {
147 
148  if( _curroffset != absbxoffset) {
149  edm::LogInfo("AbsoluteBXOffsetChanged") << "Absolute BX offset changed from "
150  << _curroffset << " to "
151  << absbxoffset << " at orbit "
152  << iEvent.orbitNumber() << " and BX "
153  << iEvent.bunchCrossing();
154  for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
155  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *l1abc;
156  }
157  }
158 
159  _curroffset = absbxoffset;
160  _curroffevent = iEvent.id().event();
161  _offsets[iEvent.id().event()] = absbxoffset;
162  }
163  }
164  }
165 }
166 
167 void
169 {
170  // reset offset vector
171 
172  _offsets.clear();
173  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
174 
175 }
176 
177 void
179 {
180  // summary of absolute bx offset vector
181 
182  edm::LogInfo("AbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
183  for(std::map<edm::EventNumber_t, long long>::const_iterator offset=_offsets.begin();offset!=_offsets.end();++offset) {
184  edm::LogVerbatim("AbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
185  }
186 
187 }
188 
189 //define this as a plug-in
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
int bunchCrossing() const
Definition: EventBase.h:66
unsigned long long EventNumber_t
EventWithHistoryProducerFromL1ABC(const edm::ParameterSet &)
std::map< edm::EventNumber_t, long long > _offsets
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: Event.h:87
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
int orbitNumber() const
Definition: EventBase.h:67
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > _l1abccollectionToken
edm::EventID id() const
Definition: EventBase.h:60
volatile std::atomic< bool > shutdown_flag false
Definition: Run.h:41