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 
52 
53 //
54 // class decleration
55 //
56 
58 public:
61 
62 private:
63  void beginRun(const edm::Run&, const edm::EventSetup&) override;
64  void produce(edm::Event&, const edm::EventSetup&) override;
65 
66  bool isBadRun(const unsigned int) const;
67  void printConfiguration(std::stringstream& ss) const;
68 
69  // ----------member data ---------------------------
70 
73  const bool m_ignoreDB;
75  std::vector<std::string> _defpartnames;
76  std::vector<int> _defphases;
77  bool _useEC0;
79  bool m_badRun;
80 
81  std::vector<std::pair<unsigned int, unsigned int> > m_badruns;
82 
83  long long _lastResync;
84  long long _lastHardReset;
85  long long _lastStart;
86  long long _lastEventCounter0;
87  long long _lastOrbitCounter0;
88  long long _lastTestEnable;
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103  : m_eswatcher(),
105  consumes<Level1TriggerScalersCollection>(iConfig.getParameter<edm::InputTag>("l1TSCollection"))),
106  m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB", false)),
107  m_rcdLabel(iConfig.getUntrackedParameter<std::string>("recordLabel", "apvphaseoffsets")),
108  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
109  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
110  _useEC0(iConfig.getUntrackedParameter<bool>("useEC0", false)),
111  _magicOffset(iConfig.getUntrackedParameter<int>("magicOffset", 8)),
112  m_badRun(false),
113  m_badruns(),
114  _lastResync(-1),
115  _lastHardReset(-1),
116  _lastStart(-1),
117  _lastEventCounter0(-1),
118  _lastOrbitCounter0(-1),
119  _lastTestEnable(-1) {
120  std::stringstream ss;
121  printConfiguration(ss);
122  edm::LogInfo("ConfigurationAtConstruction") << ss.str();
123 
124  produces<APVCyclePhaseCollection, edm::InEvent>();
125 
126  m_badruns.push_back(std::pair<unsigned int, unsigned int>(0, 131767));
127  m_badruns.push_back(std::pair<unsigned int, unsigned int>(193150, 193733));
128 
129  //now do what ever other initialization is needed
130 }
131 
133  // do anything here that needs to be done at desctruction time
134  // (e.g. close files, deallocate resources etc.)
135 }
136 
137 //
138 // member functions
139 //
140 
141 // ------------ method called to produce the data ------------
143 
144 {
145  // update the parameters from DB
146 
147  if (!m_ignoreDB && m_eswatcher.check(iSetup)) {
149  iSetup.get<SiStripConfObjectRcd>().get(m_rcdLabel, confObj);
150 
152  iSetup.get<TrackerTopologyRcd>().get(tTopo);
153 
154  std::stringstream summary;
155  confObj->printDebug(summary, tTopo.product());
156  LogDebug("SiStripConfObjectSummary") << summary.str();
157 
158  _defpartnames = confObj->get<std::vector<std::string> >("defaultPartitionNames");
159  _defphases = confObj->get<std::vector<int> >("defaultPhases");
160  _useEC0 = confObj->get<bool>("useEC0");
161  m_badRun = confObj->get<bool>("badRun");
162  _magicOffset = confObj->get<int>("magicOffset");
163 
164  std::stringstream ss;
165  printConfiguration(ss);
166  edm::LogInfo("UpdatedConfiguration") << ss.str();
167  }
168 
169  if (isBadRun(iRun.run())) {
170  LogDebug("UnreliableMissingL1TriggerScalers") << "In this run L1TriggerScalers is missing or unreliable for phase "
171  "determination: invlid phase will be returned";
172  }
173 }
174 
176  using namespace edm;
177 
178  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection());
179 
180  std::vector<int> phases(_defphases.size(), APVCyclePhaseCollection::invalid);
181 
182  const std::vector<std::string>& partnames = _defpartnames;
183 
184  int phasechange = 0;
185 
187  iEvent.getByToken(_l1tscollectionToken, l1ts);
188 
189  // offset computation
190 
191  long long orbitoffset = 0;
192 
193  if (!l1ts->empty()) {
194  if ((*l1ts)[0].lastResync() != 0) {
195  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
196  }
197 
198  if (_lastResync != (*l1ts)[0].lastResync()) {
199  _lastResync = (*l1ts)[0].lastResync();
200  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync;
201  }
202  if (_lastHardReset != (*l1ts)[0].lastHardReset()) {
203  _lastHardReset = (*l1ts)[0].lastHardReset();
204  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset;
205  }
206  if (_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
207  _lastTestEnable = (*l1ts)[0].lastTestEnable();
208  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
209  }
210  if (_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
211  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
212  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0;
213  }
214  if (_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
215  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
216  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0;
217  }
218  if (_lastStart != (*l1ts)[0].lastStart()) {
219  _lastStart = (*l1ts)[0].lastStart();
220  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart;
221  }
222 
223  if (!isBadRun(iEvent.run())) {
224  phasechange = ((long long)(orbitoffset * 3564)) % 70;
225 
226  for (unsigned int ipart = 0; ipart < phases.size(); ++ipart) {
227  phases[ipart] = (_defphases[ipart] + phasechange) % 70;
228  }
229  }
230  }
231 
232  if (phases.size() < partnames.size()) {
233  // throw exception
234  throw cms::Exception("InvalidAPVCyclePhases")
235  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
236  }
237 
238  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
239  // if(phases[ipart]>=0) {
240  // apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
241  apvphases->get()[partnames[ipart]] = phases[ipart];
242 
243  // }
244  }
245 
246  iEvent.put(std::move(apvphases));
247 }
248 
249 bool APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
250  for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator runpair = m_badruns.begin();
251  runpair != m_badruns.end();
252  ++runpair) {
253  if (run >= runpair->first && run <= runpair->second)
254  return true;
255  }
256 
257  return m_badRun;
258 }
259 
261  ss << _defpartnames.size() << " default partition names: ";
262  for (std::vector<std::string>::const_iterator part = _defpartnames.begin(); part != _defpartnames.end(); ++part) {
263  ss << *part << " ";
264  }
265  ss << std::endl;
266  ss << _defphases.size() << " default phases: ";
267  for (std::vector<int>::const_iterator phase = _defphases.begin(); phase != _defphases.end(); ++phase) {
268  ss << *phase << " ";
269  }
270  ss << std::endl;
271  ss << " Magic offset: " << _magicOffset << std::endl;
272  ss << " use ECO: " << _useEC0 << std::endl;
273  ss << " bad run: " << m_badRun << std::endl;
274 }
275 //define this as a plug-in
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the full list of parameters.
RunNumber_t run() const
Definition: RunBase.h:40
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::ESWatcher< SiStripConfObjectRcd > m_eswatcher
void beginRun(const edm::Run &, const edm::EventSetup &) override
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
RunNumber_t run() const
Definition: Event.h:107
void printConfiguration(std::stringstream &ss) const
bool isBadRun(const unsigned int) const
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< int > phases
part
Definition: HCALResponse.h:20
std::vector< Level1TriggerScalers > Level1TriggerScalersCollection
valueType get(const std::string &name) const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
HLT enums.
T get() const
Definition: EventSetup.h:73
APVCyclePhaseProducerFromL1TS(const edm::ParameterSet &)
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45