CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
APVCyclePhaseProducerFromL1TS Class Reference

#include <DPGAnalysis/SiStripTools/plugins/APVCyclePhaseProducerFromL1TS.cc>

Inheritance diagram for APVCyclePhaseProducerFromL1TS:
edm::stream::EDProducer<>

Public Member Functions

 APVCyclePhaseProducerFromL1TS (const edm::ParameterSet &)
 
 ~APVCyclePhaseProducerFromL1TS () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void beginRun (const edm::Run &, const edm::EventSetup &) override
 
bool isBadRun (const unsigned int) const
 
void printConfiguration (std::stringstream &ss) const
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::ESGetToken< SiStripConfObject, SiStripConfObjectRcd_confObjectToken
 
std::vector< std::string > _defpartnames
 
std::vector< int > _defphases
 
const bool _forceSCAL
 
edm::EDGetTokenT< Level1TriggerScalersCollection_l1tscollectionToken
 
long long _lastEventCounter0
 
long long _lastHardReset
 
long long _lastOrbitCounter0
 
long long _lastResync
 
long long _lastStart
 
long long _lastTestEnable
 
int _magicOffset
 
edm::EDGetTokenT< TCDSRecord_tcdsRecordToken
 
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd_tTopoToken
 
bool _useEC0
 
bool m_badRun
 
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
 
edm::ESWatcher< SiStripConfObjectRcdm_eswatcher
 
const bool m_ignoreDB
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Description: EDproducer for APVCyclePhaseCollection which uses the configuration file to assign a phase to the run

Implementation: <Notes on="" implementation>="">

Definition at line 58 of file APVCyclePhaseProducerFromL1TS.cc.

Constructor & Destructor Documentation

◆ APVCyclePhaseProducerFromL1TS()

APVCyclePhaseProducerFromL1TS::APVCyclePhaseProducerFromL1TS ( const edm::ParameterSet iConfig)
explicit

Definition at line 106 of file APVCyclePhaseProducerFromL1TS.cc.

References edm::ParameterSet::getUntrackedParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

107  : m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB", false)),
108  m_eswatcher(),
110  consumes<Level1TriggerScalersCollection>(iConfig.getParameter<edm::InputTag>("l1TSCollection"))),
111  _tcdsRecordToken(consumes<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))),
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;
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 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
edm::ESWatcher< SiStripConfObjectRcd > m_eswatcher
T getUntrackedParameter(std::string const &, T const &) const
Log< level::Info, false > LogInfo
void printConfiguration(std::stringstream &ss) const
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > _tTopoToken
edm::ESGetToken< SiStripConfObject, SiStripConfObjectRcd > _confObjectToken
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken

◆ ~APVCyclePhaseProducerFromL1TS()

APVCyclePhaseProducerFromL1TS::~APVCyclePhaseProducerFromL1TS ( )
override

Definition at line 143 of file APVCyclePhaseProducerFromL1TS.cc.

143  {
144  // do anything here that needs to be done at desctruction time
145  // (e.g. close files, deallocate resources etc.)
146 }

Member Function Documentation

◆ beginRun()

void APVCyclePhaseProducerFromL1TS::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 153 of file APVCyclePhaseProducerFromL1TS.cc.

References _confObjectToken, _defpartnames, _defphases, _magicOffset, _tTopoToken, _useEC0, edm::ESWatcher< T >::check(), edm::EventSetup::getData(), isBadRun(), LogDebug, m_badRun, m_eswatcher, m_ignoreDB, printConfiguration(), edm::RunBase::run(), contentValuesCheck::ss, and edmLumisInFiles::summary.

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 }
edm::ESWatcher< SiStripConfObjectRcd > m_eswatcher
RunNumber_t run() const
Definition: RunBase.h:40
bool getData(T &iHolder) const
Definition: EventSetup.h:122
bool isBadRun(const unsigned int) const
Log< level::Info, false > LogInfo
void printConfiguration(std::stringstream &ss) const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > _tTopoToken
edm::ESGetToken< SiStripConfObject, SiStripConfObjectRcd > _confObjectToken
#define LogDebug(id)

◆ isBadRun()

bool APVCyclePhaseProducerFromL1TS::isBadRun ( const unsigned int  run) const
private

Definition at line 301 of file APVCyclePhaseProducerFromL1TS.cc.

References m_badRun, m_badruns, writedatasetfile::run, edm::second(), and trackerHitRTTI::vector.

Referenced by beginRun(), and produce().

301  {
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 }
U second(std::pair< T, U > const &p)
std::vector< std::pair< unsigned int, unsigned int > > m_badruns

◆ printConfiguration()

void APVCyclePhaseProducerFromL1TS::printConfiguration ( std::stringstream &  ss) const
private

Definition at line 312 of file APVCyclePhaseProducerFromL1TS.cc.

References _defpartnames, _defphases, _magicOffset, _useEC0, m_badRun, and contentValuesCheck::ss.

Referenced by beginRun().

312  {
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 }
part
Definition: HCALResponse.h:20

◆ produce()

void APVCyclePhaseProducerFromL1TS::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 182 of file APVCyclePhaseProducerFromL1TS.cc.

References _defpartnames, _defphases, _forceSCAL, _l1tscollectionToken, _lastEventCounter0, _lastHardReset, _lastOrbitCounter0, _lastResync, _lastStart, _lastTestEnable, _magicOffset, _tcdsRecordToken, _useEC0, Exception, iEvent, APVCyclePhaseCollection::invalid, isBadRun(), edm::HandleBase::isValid(), LogDebug, eostools::move(), configurableapvcyclephaseproducer_CRAFT08_cfi::phases, edm::Handle< T >::product(), and BeamMonitor_cff::tcdsRecord.

182  {
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 }
edm::EDGetTokenT< TCDSRecord > _tcdsRecordToken
T const * product() const
Definition: Handle.h:70
int iEvent
Definition: GenABIO.cc:224
bool isBadRun(const unsigned int) const
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

Member Data Documentation

◆ _confObjectToken

edm::ESGetToken<SiStripConfObject, SiStripConfObjectRcd> APVCyclePhaseProducerFromL1TS::_confObjectToken
private

Definition at line 76 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun().

◆ _defpartnames

std::vector<std::string> APVCyclePhaseProducerFromL1TS::_defpartnames
private

Definition at line 78 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun(), printConfiguration(), and produce().

◆ _defphases

std::vector<int> APVCyclePhaseProducerFromL1TS::_defphases
private

Definition at line 79 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun(), printConfiguration(), and produce().

◆ _forceSCAL

const bool APVCyclePhaseProducerFromL1TS::_forceSCAL
private

Definition at line 83 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _l1tscollectionToken

edm::EDGetTokenT<Level1TriggerScalersCollection> APVCyclePhaseProducerFromL1TS::_l1tscollectionToken
private

Definition at line 74 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastEventCounter0

long long APVCyclePhaseProducerFromL1TS::_lastEventCounter0
private

Definition at line 90 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastHardReset

long long APVCyclePhaseProducerFromL1TS::_lastHardReset
private

Definition at line 88 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastOrbitCounter0

long long APVCyclePhaseProducerFromL1TS::_lastOrbitCounter0
private

Definition at line 91 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastResync

long long APVCyclePhaseProducerFromL1TS::_lastResync
private

Definition at line 87 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastStart

long long APVCyclePhaseProducerFromL1TS::_lastStart
private

Definition at line 89 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _lastTestEnable

long long APVCyclePhaseProducerFromL1TS::_lastTestEnable
private

Definition at line 92 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _magicOffset

int APVCyclePhaseProducerFromL1TS::_magicOffset
private

Definition at line 81 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun(), printConfiguration(), and produce().

◆ _tcdsRecordToken

edm::EDGetTokenT<TCDSRecord> APVCyclePhaseProducerFromL1TS::_tcdsRecordToken
private

Definition at line 75 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by produce().

◆ _tTopoToken

edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> APVCyclePhaseProducerFromL1TS::_tTopoToken
private

Definition at line 77 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun().

◆ _useEC0

bool APVCyclePhaseProducerFromL1TS::_useEC0
private

Definition at line 80 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun(), printConfiguration(), and produce().

◆ m_badRun

bool APVCyclePhaseProducerFromL1TS::m_badRun
private

Definition at line 82 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun(), isBadRun(), and printConfiguration().

◆ m_badruns

std::vector<std::pair<unsigned int, unsigned int> > APVCyclePhaseProducerFromL1TS::m_badruns
private

Definition at line 85 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by isBadRun().

◆ m_eswatcher

edm::ESWatcher<SiStripConfObjectRcd> APVCyclePhaseProducerFromL1TS::m_eswatcher
private

Definition at line 73 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun().

◆ m_ignoreDB

const bool APVCyclePhaseProducerFromL1TS::m_ignoreDB
private

Definition at line 72 of file APVCyclePhaseProducerFromL1TS.cc.

Referenced by beginRun().