CMS 3D CMS Logo

APVCyclePhaseProducerFromL1TS.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVCyclePhaseProducerFromL1TS
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Jan 12 09:05:45 CET 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
29 
33 
35 
37 
40 
41 #include <map>
42 #include <vector>
43 #include <utility>
44 #include <string>
45 #include <iostream>
46 
49 
53 
54 //
55 // class declaration
56 //
57 
59 public:
62 
63 private:
64  void beginRun(const edm::Run&, const edm::EventSetup&) override;
65  void produce(edm::Event&, const edm::EventSetup&) override;
66 
67  bool isBadRun(const unsigned int) const;
68  void printConfiguration(std::stringstream& ss) const;
69 
70  // ----------member data ---------------------------
71 
75  const bool m_ignoreDB;
77  std::vector<std::string> _defpartnames;
78  std::vector<int> _defphases;
79  bool _useEC0;
81  bool m_badRun;
82  const bool _forceSCAL;
83 
84  std::vector<std::pair<unsigned int, unsigned int> > m_badruns;
85 
86  long long _lastResync;
87  long long _lastHardReset;
88  long long _lastStart;
89  long long _lastEventCounter0;
90  long long _lastOrbitCounter0;
91  long long _lastTestEnable;
92 };
93 
94 //
95 // constants, enums and typedefs
96 //
97 
98 //
99 // static data member definitions
100 //
101 
102 //
103 // constructors and destructor
104 //
106  : m_eswatcher(),
107  _l1tscollectionToken(
108  consumes<Level1TriggerScalersCollection>(iConfig.getParameter<edm::InputTag>("l1TSCollection"))),
109  _tcdsRecordToken(consumes<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))),
110  m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB", false)),
111  m_rcdLabel(iConfig.getUntrackedParameter<std::string>("recordLabel", "apvphaseoffsets")),
112  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
113  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
114  _useEC0(iConfig.getUntrackedParameter<bool>("useEC0", false)),
115  _magicOffset(iConfig.getUntrackedParameter<int>("magicOffset", 8)),
116  m_badRun(false),
117  _forceSCAL(iConfig.getParameter<bool>("forceSCAL")),
118  m_badruns(),
119  _lastResync(-1),
120  _lastHardReset(-1),
121  _lastStart(-1),
122  _lastEventCounter0(-1),
123  _lastOrbitCounter0(-1),
124  _lastTestEnable(-1) {
125  std::stringstream ss;
127  edm::LogInfo("ConfigurationAtConstruction") << ss.str();
128 
129  produces<APVCyclePhaseCollection, edm::InEvent>();
130 
131  m_badruns.push_back(std::pair<unsigned int, unsigned int>(0, 131767));
132  m_badruns.push_back(std::pair<unsigned int, unsigned int>(193150, 193733));
133 
134  //now do what ever other initialization is needed
135 }
136 
138  // do anything here that needs to be done at desctruction time
139  // (e.g. close files, deallocate resources etc.)
140 }
141 
142 //
143 // member functions
144 //
145 
146 // ------------ method called to produce the data ------------
148 
149 {
150  // update the parameters from DB
151 
152  if (!m_ignoreDB && m_eswatcher.check(iSetup)) {
154  iSetup.get<SiStripConfObjectRcd>().get(m_rcdLabel, confObj);
155 
157  iSetup.get<TrackerTopologyRcd>().get(tTopo);
158 
159  std::stringstream summary;
160  confObj->printDebug(summary, tTopo.product());
161  LogDebug("SiStripConfObjectSummary") << summary.str();
162 
163  _defpartnames = confObj->get<std::vector<std::string> >("defaultPartitionNames");
164  _defphases = confObj->get<std::vector<int> >("defaultPhases");
165  _useEC0 = confObj->get<bool>("useEC0");
166  m_badRun = confObj->get<bool>("badRun");
167  _magicOffset = confObj->get<int>("magicOffset");
168 
169  std::stringstream ss;
171  edm::LogInfo("UpdatedConfiguration") << ss.str();
172  }
173 
174  if (isBadRun(iRun.run())) {
175  LogDebug("UnreliableMissingL1TriggerScalers") << "In this run L1TriggerScalers is missing or unreliable for phase "
176  "determination: invlid phase will be returned";
177  }
178 }
179 
181  using namespace edm;
182 
183  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection());
184 
185  std::vector<int> phases(_defphases.size(), APVCyclePhaseCollection::invalid);
186 
187  const std::vector<std::string>& partnames = _defpartnames;
188 
189  int phasechange = 0;
190 
192  iEvent.getByToken(_l1tscollectionToken, l1ts);
193  Handle<TCDSRecord> tcds_pIn;
194  iEvent.getByToken(_tcdsRecordToken, tcds_pIn);
195  bool useTCDS(tcds_pIn.isValid() && !_forceSCAL);
196  const auto* tcdsRecord = useTCDS ? tcds_pIn.product() : nullptr;
197  // offset computation
198 
199  long long orbitoffset = 0;
200 
201  if (useTCDS && iEvent.eventAuxiliary().isRealData()) {
202  // l1ts->empty() always retuns false (last commit as of today: https://github.com/cms-sw/cmssw/commit/f4694d795d4b268d541c633dfb68283d889264b0 ), so the check is likely not necessary---and TCDSRecord hasn't anything similar
203  if (tcdsRecord->getLastResync() != 0) {
204  orbitoffset =
205  _useEC0 ? tcdsRecord->getLastEventCounter0() + _magicOffset : tcdsRecord->getLastResync() + _magicOffset;
206  }
207 
208  if (_lastResync != tcdsRecord->getLastResync()) {
209  _lastResync = tcdsRecord->getLastResync();
210  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync;
211  }
212  if (_lastHardReset != tcdsRecord->getLastHardReset()) {
213  _lastHardReset = tcdsRecord->getLastHardReset();
214  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset;
215  }
216  if (_lastTestEnable != tcdsRecord->getLastTestEnable()) {
217  _lastTestEnable = tcdsRecord->getLastTestEnable();
218  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
219  }
220  if (_lastOrbitCounter0 != tcdsRecord->getLastOrbitCounter0()) {
221  _lastOrbitCounter0 = tcdsRecord->getLastOrbitCounter0();
222  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0;
223  }
224  if (_lastEventCounter0 != tcdsRecord->getLastEventCounter0()) {
225  _lastEventCounter0 = tcdsRecord->getLastEventCounter0();
226  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0;
227  }
228  if (_lastStart != tcdsRecord->getLastStart()) {
229  _lastStart = tcdsRecord->getLastStart();
230  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart;
231  }
232 
233  if (!isBadRun(iEvent.run())) {
234  phasechange = ((long long)(orbitoffset * 3564)) % 70;
235 
236  for (unsigned int ipart = 0; ipart < phases.size(); ++ipart) {
237  phases[ipart] = (_defphases[ipart] + phasechange) % 70;
238  }
239  }
240 
241  } else {
242  if (!l1ts->empty()) {
243  if ((*l1ts)[0].lastResync() != 0) {
244  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
245  }
246 
247  if (_lastResync != (*l1ts)[0].lastResync()) {
248  _lastResync = (*l1ts)[0].lastResync();
249  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync;
250  }
251  if (_lastHardReset != (*l1ts)[0].lastHardReset()) {
252  _lastHardReset = (*l1ts)[0].lastHardReset();
253  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset;
254  }
255  if (_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
256  _lastTestEnable = (*l1ts)[0].lastTestEnable();
257  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
258  }
259  if (_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
260  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
261  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0;
262  }
263  if (_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
264  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
265  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0;
266  }
267  if (_lastStart != (*l1ts)[0].lastStart()) {
268  _lastStart = (*l1ts)[0].lastStart();
269  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart;
270  }
271 
272  if (!isBadRun(iEvent.run())) {
273  phasechange = ((long long)(orbitoffset * 3564)) % 70;
274 
275  for (unsigned int ipart = 0; ipart < phases.size(); ++ipart) {
276  phases[ipart] = (_defphases[ipart] + phasechange) % 70;
277  }
278  }
279  }
280  }
281 
282  if (phases.size() < partnames.size()) {
283  // throw exception
284  throw cms::Exception("InvalidAPVCyclePhases")
285  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
286  }
287 
288  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
289  // if(phases[ipart]>=0) {
290  // apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
291  apvphases->get()[partnames[ipart]] = phases[ipart];
292 
293  // }
294  }
295 
296  iEvent.put(std::move(apvphases));
297 }
298 
299 bool APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
300  for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator runpair = m_badruns.begin();
301  runpair != m_badruns.end();
302  ++runpair) {
303  if (run >= runpair->first && run <= runpair->second)
304  return true;
305  }
306 
307  return m_badRun;
308 }
309 
311  ss << _defpartnames.size() << " default partition names: ";
312  for (std::vector<std::string>::const_iterator part = _defpartnames.begin(); part != _defpartnames.end(); ++part) {
313  ss << *part << " ";
314  }
315  ss << std::endl;
316  ss << _defphases.size() << " default phases: ";
317  for (std::vector<int>::const_iterator phase = _defphases.begin(); phase != _defphases.end(); ++phase) {
318  ss << *phase << " ";
319  }
320  ss << std::endl;
321  ss << " Magic offset: " << _magicOffset << std::endl;
322  ss << " use ECO: " << _useEC0 << std::endl;
323  ss << " bad run: " << m_badRun << std::endl;
324 }
325 //define this as a plug-in
APVCyclePhaseProducerFromL1TS::APVCyclePhaseProducerFromL1TS
APVCyclePhaseProducerFromL1TS(const edm::ParameterSet &)
Definition: APVCyclePhaseProducerFromL1TS.cc:105
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
electrons_cff.bool
bool
Definition: electrons_cff.py:372
APVCyclePhaseProducerFromL1TS::_defpartnames
std::vector< std::string > _defpartnames
Definition: APVCyclePhaseProducerFromL1TS.cc:77
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::ESWatcher< SiStripConfObjectRcd >
ESHandle.h
SiStripConfObject::printDebug
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the full list of parameters.
Definition: SiStripConfObject.cc:115
edm::Run
Definition: Run.h:45
phases
std::vector< int > phases
Definition: compareAlignments.cc:30
edm::EDGetTokenT< Level1TriggerScalersCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogInfo
Definition: MessageLogger.h:254
EDProducer.h
APVCyclePhaseProducerFromL1TS::_tcdsRecordToken
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
Definition: APVCyclePhaseProducerFromL1TS.cc:74
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
APVCyclePhaseProducerFromL1TS::_lastResync
long long _lastResync
Definition: APVCyclePhaseProducerFromL1TS.cc:86
HLT_2018_cff.phase
phase
Definition: HLT_2018_cff.py:5346
APVCyclePhaseProducerFromL1TS::_useEC0
bool _useEC0
Definition: APVCyclePhaseProducerFromL1TS.cc:79
edm::Handle
Definition: AssociativeIterator.h:50
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
APVCyclePhaseProducerFromL1TS::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1TS.cc:147
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MakerMacros.h
part
part
Definition: HCALResponse.h:20
APVCyclePhaseProducerFromL1TS::_lastOrbitCounter0
long long _lastOrbitCounter0
Definition: APVCyclePhaseProducerFromL1TS.cc:90
Level1TriggerScalers.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TCDSRecord.h
APVCyclePhaseProducerFromL1TS::m_eswatcher
edm::ESWatcher< SiStripConfObjectRcd > m_eswatcher
Definition: APVCyclePhaseProducerFromL1TS.cc:72
APVCyclePhaseProducerFromL1TS::m_ignoreDB
const bool m_ignoreDB
Definition: APVCyclePhaseProducerFromL1TS.cc:75
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
APVCyclePhaseProducerFromL1TS::_lastStart
long long _lastStart
Definition: APVCyclePhaseProducerFromL1TS.cc:88
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
SiStripCondDataRecords.h
APVCyclePhaseProducerFromL1TS::isBadRun
bool isBadRun(const unsigned int) const
Definition: APVCyclePhaseProducerFromL1TS.cc:299
Event.h
APVCyclePhaseCollection.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
APVCyclePhaseProducerFromL1TS::printConfiguration
void printConfiguration(std::stringstream &ss) const
Definition: APVCyclePhaseProducerFromL1TS.cc:310
get
#define get
InputTag.h
APVCyclePhaseProducerFromL1TS::m_badruns
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
Definition: APVCyclePhaseProducerFromL1TS.cc:84
APVCyclePhaseProducerFromL1TS::m_badRun
bool m_badRun
Definition: APVCyclePhaseProducerFromL1TS.cc:81
SiStripConfObject::get
valueType get(const std::string &name) const
Definition: SiStripConfObject.h:63
APVCyclePhaseProducerFromL1TS::~APVCyclePhaseProducerFromL1TS
~APVCyclePhaseProducerFromL1TS() override
Definition: APVCyclePhaseProducerFromL1TS.cc:137
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
APVCyclePhaseProducerFromL1TS::_lastEventCounter0
long long _lastEventCounter0
Definition: APVCyclePhaseProducerFromL1TS.cc:89
APVCyclePhaseProducerFromL1TS::_lastHardReset
long long _lastHardReset
Definition: APVCyclePhaseProducerFromL1TS.cc:87
Frameworkfwd.h
ESWatcher.h
APVCyclePhaseProducerFromL1TS::_magicOffset
int _magicOffset
Definition: APVCyclePhaseProducerFromL1TS.cc:80
TCDSRecord
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
Exception
Definition: hltDiff.cc:246
APVCyclePhaseProducerFromL1TS::_defphases
std::vector< int > _defphases
Definition: APVCyclePhaseProducerFromL1TS.cc:78
APVCyclePhaseProducerFromL1TS::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1TS.cc:180
EventSetup.h
SiStripConfObjectRcd
Definition: SiStripCondDataRecords.h:56
APVCyclePhaseProducerFromL1TS::_lastTestEnable
long long _lastTestEnable
Definition: APVCyclePhaseProducerFromL1TS.cc:91
Exception.h
APVCyclePhaseProducerFromL1TS::m_rcdLabel
const std::string m_rcdLabel
Definition: APVCyclePhaseProducerFromL1TS.cc:76
APVCyclePhaseProducerFromL1TS::_forceSCAL
const bool _forceSCAL
Definition: APVCyclePhaseProducerFromL1TS.cc:82
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
Level1TriggerScalersCollection
std::vector< Level1TriggerScalers > Level1TriggerScalersCollection
Definition: Level1TriggerScalers.h:183
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
APVCyclePhaseProducerFromL1TS
Definition: APVCyclePhaseProducerFromL1TS.cc:58
APVCyclePhaseCollection::invalid
Definition: APVCyclePhaseCollection.h:21
SiStripConfObject.h
APVCyclePhaseProducerFromL1TS::_l1tscollectionToken
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken
Definition: APVCyclePhaseProducerFromL1TS.cc:73