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 
72  const bool m_ignoreDB;
78  std::vector<std::string> _defpartnames;
79  std::vector<int> _defphases;
80  bool _useEC0;
82  bool m_badRun;
83  const bool _forceSCAL;
84 
85  std::vector<std::pair<unsigned int, unsigned int> > m_badruns;
86 
87  long long _lastResync;
88  long long _lastHardReset;
89  long long _lastStart;
90  long long _lastEventCounter0;
91  long long _lastOrbitCounter0;
92  long long _lastTestEnable;
93 };
94 
95 //
96 // constants, enums and typedefs
97 //
98 
99 //
100 // static data member definitions
101 //
102 
103 //
104 // constructors and destructor
105 //
107  : m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB", false)),
108  m_eswatcher(),
109  _l1tscollectionToken(
110  consumes<Level1TriggerScalersCollection>(iConfig.getParameter<edm::InputTag>("l1TSCollection"))),
111  _tcdsRecordToken(consumes<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))),
112  _confObjectToken((!m_ignoreDB)
113  ? decltype(_confObjectToken){esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{
114  "", iConfig.getUntrackedParameter<std::string>("recordLabel", "apvphaseoffsets")})}
115  : decltype(_confObjectToken){}),
116  _tTopoToken((!m_ignoreDB) ? decltype(_tTopoToken){esConsumes<edm::Transition::BeginRun>()}
117  : decltype(_tTopoToken){}),
118  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
119  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
120  _useEC0(iConfig.getUntrackedParameter<bool>("useEC0", false)),
121  _magicOffset(iConfig.getUntrackedParameter<int>("magicOffset", 8)),
122  m_badRun(false),
123  _forceSCAL(iConfig.getParameter<bool>("forceSCAL")),
124  m_badruns(),
125  _lastResync(-1),
126  _lastHardReset(-1),
127  _lastStart(-1),
128  _lastEventCounter0(-1),
129  _lastOrbitCounter0(-1),
130  _lastTestEnable(-1) {
131  std::stringstream ss;
132  printConfiguration(ss);
133  edm::LogInfo("ConfigurationAtConstruction") << ss.str();
134 
135  produces<APVCyclePhaseCollection, edm::InEvent>();
136 
137  m_badruns.push_back(std::pair<unsigned int, unsigned int>(0, 131767));
138  m_badruns.push_back(std::pair<unsigned int, unsigned int>(193150, 193733));
139 
140  //now do what ever other initialization is needed
141 }
142 
144  // do anything here that needs to be done at desctruction time
145  // (e.g. close files, deallocate resources etc.)
146 }
147 
148 //
149 // member functions
150 //
151 
152 // ------------ method called to produce the data ------------
154 
155 {
156  // update the parameters from DB
157 
158  if (!m_ignoreDB && m_eswatcher.check(iSetup)) {
159  const auto& confObj = iSetup.getData(_confObjectToken);
160 
161  std::stringstream summary;
162  confObj.printDebug(summary, &iSetup.getData(_tTopoToken));
163  LogDebug("SiStripConfObjectSummary") << summary.str();
164 
165  _defpartnames = confObj.get<std::vector<std::string> >("defaultPartitionNames");
166  _defphases = confObj.get<std::vector<int> >("defaultPhases");
167  _useEC0 = confObj.get<bool>("useEC0");
168  m_badRun = confObj.get<bool>("badRun");
169  _magicOffset = confObj.get<int>("magicOffset");
170 
171  std::stringstream ss;
173  edm::LogInfo("UpdatedConfiguration") << ss.str();
174  }
175 
176  if (isBadRun(iRun.run())) {
177  LogDebug("UnreliableMissingL1TriggerScalers") << "In this run L1TriggerScalers is missing or unreliable for phase "
178  "determination: invlid phase will be returned";
179  }
180 }
181 
183  using namespace edm;
184 
185  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection());
186 
187  std::vector<int> phases(_defphases.size(), APVCyclePhaseCollection::invalid);
188 
189  const std::vector<std::string>& partnames = _defpartnames;
190 
191  int phasechange = 0;
192 
194  iEvent.getByToken(_l1tscollectionToken, l1ts);
195  Handle<TCDSRecord> tcds_pIn;
196  iEvent.getByToken(_tcdsRecordToken, tcds_pIn);
197  bool useTCDS(tcds_pIn.isValid() && !_forceSCAL);
198  const auto* tcdsRecord = useTCDS ? tcds_pIn.product() : nullptr;
199  // offset computation
200 
201  long long orbitoffset = 0;
202 
203  if (useTCDS && iEvent.eventAuxiliary().isRealData()) {
204  // 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
205  if (tcdsRecord->getLastResync() != 0) {
206  orbitoffset =
207  _useEC0 ? tcdsRecord->getLastEventCounter0() + _magicOffset : tcdsRecord->getLastResync() + _magicOffset;
208  }
209 
210  if (_lastResync != tcdsRecord->getLastResync()) {
211  _lastResync = tcdsRecord->getLastResync();
212  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync;
213  }
214  if (_lastHardReset != tcdsRecord->getLastHardReset()) {
215  _lastHardReset = tcdsRecord->getLastHardReset();
216  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset;
217  }
218  if (_lastTestEnable != tcdsRecord->getLastTestEnable()) {
219  _lastTestEnable = tcdsRecord->getLastTestEnable();
220  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
221  }
222  if (_lastOrbitCounter0 != tcdsRecord->getLastOrbitCounter0()) {
223  _lastOrbitCounter0 = tcdsRecord->getLastOrbitCounter0();
224  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0;
225  }
226  if (_lastEventCounter0 != tcdsRecord->getLastEventCounter0()) {
227  _lastEventCounter0 = tcdsRecord->getLastEventCounter0();
228  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0;
229  }
230  if (_lastStart != tcdsRecord->getLastStart()) {
231  _lastStart = tcdsRecord->getLastStart();
232  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart;
233  }
234 
235  if (!isBadRun(iEvent.run())) {
236  phasechange = ((long long)(orbitoffset * 3564)) % 70;
237 
238  for (unsigned int ipart = 0; ipart < phases.size(); ++ipart) {
239  phases[ipart] = (_defphases[ipart] + phasechange) % 70;
240  }
241  }
242 
243  } else {
244  if (!l1ts->empty()) {
245  if ((*l1ts)[0].lastResync() != 0) {
246  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
247  }
248 
249  if (_lastResync != (*l1ts)[0].lastResync()) {
250  _lastResync = (*l1ts)[0].lastResync();
251  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync;
252  }
253  if (_lastHardReset != (*l1ts)[0].lastHardReset()) {
254  _lastHardReset = (*l1ts)[0].lastHardReset();
255  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset;
256  }
257  if (_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
258  _lastTestEnable = (*l1ts)[0].lastTestEnable();
259  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
260  }
261  if (_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
262  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
263  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0;
264  }
265  if (_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
266  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
267  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0;
268  }
269  if (_lastStart != (*l1ts)[0].lastStart()) {
270  _lastStart = (*l1ts)[0].lastStart();
271  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart;
272  }
273 
274  if (!isBadRun(iEvent.run())) {
275  phasechange = ((long long)(orbitoffset * 3564)) % 70;
276 
277  for (unsigned int ipart = 0; ipart < phases.size(); ++ipart) {
278  phases[ipart] = (_defphases[ipart] + phasechange) % 70;
279  }
280  }
281  }
282  }
283 
284  if (phases.size() < partnames.size()) {
285  // throw exception
286  throw cms::Exception("InvalidAPVCyclePhases")
287  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
288  }
289 
290  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
291  // if(phases[ipart]>=0) {
292  // apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
293  apvphases->get()[partnames[ipart]] = phases[ipart];
294 
295  // }
296  }
297 
298  iEvent.put(std::move(apvphases));
299 }
300 
301 bool APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
302  for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator runpair = m_badruns.begin();
303  runpair != m_badruns.end();
304  ++runpair) {
305  if (run >= runpair->first && run <= runpair->second)
306  return true;
307  }
308 
309  return m_badRun;
310 }
311 
313  ss << _defpartnames.size() << " default partition names: ";
314  for (std::vector<std::string>::const_iterator part = _defpartnames.begin(); part != _defpartnames.end(); ++part) {
315  ss << *part << " ";
316  }
317  ss << std::endl;
318  ss << _defphases.size() << " default phases: ";
319  for (std::vector<int>::const_iterator phase = _defphases.begin(); phase != _defphases.end(); ++phase) {
320  ss << *phase << " ";
321  }
322  ss << std::endl;
323  ss << " Magic offset: " << _magicOffset << std::endl;
324  ss << " use ECO: " << _useEC0 << std::endl;
325  ss << " bad run: " << m_badRun << std::endl;
326 }
327 //define this as a plug-in
APVCyclePhaseProducerFromL1TS::APVCyclePhaseProducerFromL1TS
APVCyclePhaseProducerFromL1TS(const edm::ParameterSet &)
Definition: APVCyclePhaseProducerFromL1TS.cc:106
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::ESInputTag
Definition: ESInputTag.h:87
APVCyclePhaseProducerFromL1TS::_defpartnames
std::vector< std::string > _defpartnames
Definition: APVCyclePhaseProducerFromL1TS.cc:78
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::ESWatcher< SiStripConfObjectRcd >
ESHandle.h
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
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
EDProducer.h
APVCyclePhaseProducerFromL1TS::_tcdsRecordToken
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
Definition: APVCyclePhaseProducerFromL1TS.cc:75
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
APVCyclePhaseProducerFromL1TS::_lastResync
long long _lastResync
Definition: APVCyclePhaseProducerFromL1TS.cc:87
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
APVCyclePhaseProducerFromL1TS::_useEC0
bool _useEC0
Definition: APVCyclePhaseProducerFromL1TS.cc:80
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:153
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
APVCyclePhaseCollection::invalid
Definition: APVCyclePhaseCollection.h:21
MakerMacros.h
part
part
Definition: HCALResponse.h:20
APVCyclePhaseProducerFromL1TS::_lastOrbitCounter0
long long _lastOrbitCounter0
Definition: APVCyclePhaseProducerFromL1TS.cc:91
Level1TriggerScalers.h
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:73
APVCyclePhaseProducerFromL1TS::m_ignoreDB
const bool m_ignoreDB
Definition: APVCyclePhaseProducerFromL1TS.cc:72
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
Run.h
APVCyclePhaseProducerFromL1TS::_lastStart
long long _lastStart
Definition: APVCyclePhaseProducerFromL1TS.cc:89
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelPI::phase
phase
Definition: SiPixelPayloadInspectorHelper.h:39
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCondDataRecords.h
APVCyclePhaseProducerFromL1TS::isBadRun
bool isBadRun(const unsigned int) const
Definition: APVCyclePhaseProducerFromL1TS.cc:301
Event.h
APVCyclePhaseCollection.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
APVCyclePhaseProducerFromL1TS::printConfiguration
void printConfiguration(std::stringstream &ss) const
Definition: APVCyclePhaseProducerFromL1TS.cc:312
edm::ESGetToken< SiStripConfObject, SiStripConfObjectRcd >
InputTag.h
APVCyclePhaseProducerFromL1TS::m_badruns
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
Definition: APVCyclePhaseProducerFromL1TS.cc:85
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
APVCyclePhaseProducerFromL1TS::m_badRun
bool m_badRun
Definition: APVCyclePhaseProducerFromL1TS.cc:82
APVCyclePhaseProducerFromL1TS::~APVCyclePhaseProducerFromL1TS
~APVCyclePhaseProducerFromL1TS() override
Definition: APVCyclePhaseProducerFromL1TS.cc:143
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
APVCyclePhaseProducerFromL1TS::_lastEventCounter0
long long _lastEventCounter0
Definition: APVCyclePhaseProducerFromL1TS.cc:90
APVCyclePhaseProducerFromL1TS::_lastHardReset
long long _lastHardReset
Definition: APVCyclePhaseProducerFromL1TS.cc:88
Frameworkfwd.h
ESWatcher.h
APVCyclePhaseProducerFromL1TS::_magicOffset
int _magicOffset
Definition: APVCyclePhaseProducerFromL1TS.cc:81
TCDSRecord
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
Exception
Definition: hltDiff.cc:245
APVCyclePhaseProducerFromL1TS::_defphases
std::vector< int > _defphases
Definition: APVCyclePhaseProducerFromL1TS.cc:79
APVCyclePhaseProducerFromL1TS::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: APVCyclePhaseProducerFromL1TS.cc:182
APVCyclePhaseProducerFromL1TS::_confObjectToken
edm::ESGetToken< SiStripConfObject, SiStripConfObjectRcd > _confObjectToken
Definition: APVCyclePhaseProducerFromL1TS.cc:76
EventSetup.h
APVCyclePhaseProducerFromL1TS::_lastTestEnable
long long _lastTestEnable
Definition: APVCyclePhaseProducerFromL1TS.cc:92
Exception.h
APVCyclePhaseProducerFromL1TS::_forceSCAL
const bool _forceSCAL
Definition: APVCyclePhaseProducerFromL1TS.cc:83
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
APVCyclePhaseProducerFromL1TS::_tTopoToken
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > _tTopoToken
Definition: APVCyclePhaseProducerFromL1TS.cc:77
SiStripConfObject.h
APVCyclePhaseProducerFromL1TS::_l1tscollectionToken
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken
Definition: APVCyclePhaseProducerFromL1TS.cc:74