CMS 3D CMS Logo

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
EventWithHistoryProducerFromL1ABC::~EventWithHistoryProducerFromL1ABC
~EventWithHistoryProducerFromL1ABC() override
Definition: EventWithHistoryProducerFromL1ABC.cc:92
EventWithHistoryProducerFromL1ABC
Definition: EventWithHistoryProducerFromL1ABC.cc:43
electrons_cff.bool
bool
Definition: electrons_cff.py:393
EventWithHistoryProducerFromL1ABC::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: EventWithHistoryProducerFromL1ABC.cc:175
EventWithHistoryProducerFromL1ABC::_l1abccollectionToken
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > _l1abccollectionToken
Definition: EventWithHistoryProducerFromL1ABC.cc:55
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EventWithHistoryProducerFromL1ABC::_forceNoOffset
const bool _forceNoOffset
Definition: EventWithHistoryProducerFromL1ABC.cc:57
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< L1AcceptBunchCrossingCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
L1AcceptBunchCrossing.h
EDProducer.h
EventWithHistory.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
TCDSRecord::getOrbitNr
uint64_t getOrbitNr() const
Definition: TCDSRecord.h:88
EventWithHistoryProducerFromL1ABC::_tcdsRecordToken
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
Definition: EventWithHistoryProducerFromL1ABC.cc:56
EventWithHistoryProducerFromL1ABC::_curroffset
long long _curroffset
Definition: EventWithHistoryProducerFromL1ABC.cc:60
MakerMacros.h
EventWithHistoryProducerFromL1ABC::_curroffevent
edm::EventNumber_t _curroffevent
Definition: EventWithHistoryProducerFromL1ABC.cc:61
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TCDSRecord.h
L1AcceptBunchCrossingCollection
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
Definition: L1AcceptBunchCrossing.h:83
Run.h
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
edm::ParameterSet
Definition: ParameterSet.h:47
EventWithHistoryProducerFromL1ABC::EventWithHistoryProducerFromL1ABC
EventWithHistoryProducerFromL1ABC(const edm::ParameterSet &)
Definition: EventWithHistoryProducerFromL1ABC.cc:75
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
EventWithHistoryProducerFromL1ABC::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: EventWithHistoryProducerFromL1ABC.cc:182
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
EventWithHistory
Definition: EventWithHistory.h:17
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TCDSRecord
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
EventWithHistoryProducerFromL1ABC::_offsets
std::map< edm::EventNumber_t, long long > _offsets
Definition: EventWithHistoryProducerFromL1ABC.cc:59
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Event
Definition: Event.h:73
EventWithHistoryProducerFromL1ABC::_forceSCAL
const bool _forceSCAL
Definition: EventWithHistoryProducerFromL1ABC.cc:58
EventWithHistoryProducerFromL1ABC::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EventWithHistoryProducerFromL1ABC.cc:102