CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 // system include files
20 #include <memory>
21 #include <map>
22 
23 // user include files
26 
30 
32 
35 
39 //
40 // class declarations
41 //
42 
44 public:
47 
48 private:
49  void beginRun(const edm::Run&, const edm::EventSetup&) override;
50  void produce(edm::Event&, const edm::EventSetup&) override;
51  void endRun(const edm::Run&, const edm::EventSetup&) override;
52 
53  // ----------member data ---------------------------
54 
57  const bool _forceNoOffset;
58  const bool _forceSCAL;
59  std::map<edm::EventNumber_t, long long> _offsets;
60  long long _curroffset;
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
76  : _l1abccollectionToken(
77  mayConsume<L1AcceptBunchCrossingCollection>(iConfig.getParameter<edm::InputTag>("l1ABCCollection"))),
78  _tcdsRecordToken(mayConsume<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))),
79  _forceNoOffset(iConfig.getUntrackedParameter<bool>("forceNoOffset", false)),
80  _forceSCAL(iConfig.getParameter<bool>("forceSCAL")),
81  _offsets(),
82  _curroffset(0),
83  _curroffevent(0) {
84  if (_forceNoOffset)
85  edm::LogWarning("NoOffsetComputation") << "Orbit and BX offset will NOT be computed: Be careful!";
86 
87  produces<EventWithHistory>();
88 
89  //now do what ever other initialization is needed
90 }
91 
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95 }
96 
97 //
98 // member functions
99 //
100 
101 // ------------ method called to produce the data ------------
103  using namespace edm;
104 
105  if (iEvent.run() < 110878) {
106  std::unique_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent));
107  iEvent.put(std::move(pOut));
108 
109  } else {
111  iEvent.getByToken(_l1abccollectionToken, pIn);
112  Handle<TCDSRecord> tcds_pIn;
113  iEvent.getByToken(_tcdsRecordToken, tcds_pIn);
114  bool useTCDS(tcds_pIn.isValid() && !_forceSCAL);
115 
116  const auto* tcdsRecord = useTCDS ? tcds_pIn.product() : nullptr;
117  // offset computation
118 
119  long long orbitoffset = 0;
120  int bxoffset = 0;
121 
122  if (useTCDS) {
123  if (!_forceNoOffset) {
124  if (tcdsRecord->getL1aHistoryEntry(0).getIndex() == 0) {
125  orbitoffset = (long long)tcdsRecord->getOrbitNr() - (long long)iEvent.orbitNumber();
126  bxoffset = tcdsRecord->getBXID() - iEvent.bunchCrossing();
127  }
128  }
129  } else {
130  if (!_forceNoOffset) {
131  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
132  if (l1abc->l1AcceptOffset() == 0) {
133  orbitoffset = (long long)l1abc->orbitNumber() - (long long)iEvent.orbitNumber();
134  bxoffset = l1abc->bunchCrossing() - iEvent.bunchCrossing();
135  }
136  }
137  }
138  }
139 
140  std::unique_ptr<EventWithHistory> pOut(useTCDS ? new EventWithHistory(iEvent, *tcdsRecord, orbitoffset, bxoffset)
141  : new EventWithHistory(iEvent, *pIn, orbitoffset, bxoffset));
142  iEvent.put(std::move(pOut));
143 
144  // monitor offset
145 
146  long long absbxoffset = orbitoffset * 3564 + bxoffset;
147 
148  if (_offsets.empty()) {
149  _curroffset = absbxoffset;
150  _curroffevent = iEvent.id().event();
151  _offsets[iEvent.id().event()] = absbxoffset;
152  } else {
153  if (_curroffset != absbxoffset || iEvent.id().event() < _curroffevent) {
154  if (_curroffset != absbxoffset) {
155  edm::LogInfo("AbsoluteBXOffsetChanged")
156  << "Absolute BX offset changed from " << _curroffset << " to " << absbxoffset << " at orbit "
157  << iEvent.orbitNumber() << " and BX " << iEvent.bunchCrossing();
158  if (useTCDS) {
159  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *tcdsRecord; // Not sure about this
160  } else {
161  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
162  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *l1abc;
163  }
164  }
165  }
166 
167  _curroffset = absbxoffset;
168  _curroffevent = iEvent.id().event();
169  _offsets[iEvent.id().event()] = absbxoffset;
170  }
171  }
172  }
173 }
174 
176  // reset offset vector
177 
178  _offsets.clear();
179  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
180 }
181 
183  // summary of absolute bx offset vector
184 
185  edm::LogInfo("AbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
186  for (std::map<edm::EventNumber_t, long long>::const_iterator offset = _offsets.begin(); offset != _offsets.end();
187  ++offset) {
188  edm::LogVerbatim("AbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
189  }
190 }
191 
192 //define this as a plug-in
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int bunchCrossing() const
Definition: EventBase.h:64
unsigned long long EventNumber_t
EventWithHistoryProducerFromL1ABC(const edm::ParameterSet &)
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
std::map< edm::EventNumber_t, long long > _offsets
int iEvent
Definition: GenABIO.cc:224
_forceSCAL(iConfig.getParameter< bool >("forceSCAL"))
void endRun(const edm::Run &, const edm::EventSetup &) override
def move
Definition: eostools.py:511
RunNumber_t run() const
Definition: Event.h:109
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
int orbitNumber() const
Definition: EventBase.h:65
bool isValid() const
Definition: HandleBase.h:70
Log< level::Info, false > LogInfo
T const * product() const
Definition: Handle.h:70
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > _l1abccollectionToken
edm::EventID id() const
Definition: EventBase.h:59
Log< level::Warning, false > LogWarning
Definition: Run.h:45