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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
30 
34 
36 
38 
41 
42 #include <map>
43 #include <vector>
44 #include <utility>
45 #include <string>
46 #include <iostream>
47 
50 
53 
54 //
55 // class decleration
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 
74  const bool m_ignoreDB;
76  std::vector<std::string> _defpartnames;
77  std::vector<int> _defphases;
78  bool _useEC0;
80  bool m_badRun;
81 
82  std::vector<std::pair<unsigned int, unsigned int> > m_badruns;
83 
84  long long _lastResync;
85  long long _lastHardReset;
86  long long _lastStart;
87  long long _lastEventCounter0;
88  long long _lastOrbitCounter0;
89  long long _lastTestEnable;
90 
91 
92 };
93 
94 //
95 // constants, enums and typedefs
96 //
97 
98 
99 //
100 // static data member definitions
101 //
102 
103 //
104 // constructors and destructor
105 //
107  m_eswatcher(),
108  _l1tscollectionToken(consumes<Level1TriggerScalersCollection>(iConfig.getParameter<edm::InputTag>("l1TSCollection"))),
109  m_ignoreDB(iConfig.getUntrackedParameter<bool>("ignoreDB",false)),
110  m_rcdLabel(iConfig.getUntrackedParameter<std::string>("recordLabel","apvphaseoffsets")),
111  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
112  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
113  _useEC0(iConfig.getUntrackedParameter<bool>("useEC0",false)),
114  _magicOffset(iConfig.getUntrackedParameter<int>("magicOffset",8)),
115  m_badRun(false),
116  m_badruns(),
119 {
120 
121  std::stringstream ss;
122  printConfiguration(ss);
123  edm::LogInfo("ConfigurationAtConstruction") << ss.str();
124 
125 
126  produces<APVCyclePhaseCollection,edm::InEvent>();
127 
128  m_badruns.push_back(std::pair<unsigned int, unsigned int>(0,131767));
129  m_badruns.push_back(std::pair<unsigned int, unsigned int>(193150,193733));
130 
131  //now do what ever other initialization is needed
132 
133 }
134 
135 
137 {
138 
139  // do anything here that needs to be done at desctruction time
140  // (e.g. close files, deallocate resources etc.)
141 
142 }
143 
144 
145 //
146 // member functions
147 //
148 
149 // ------------ method called to produce the data ------------
150 void
152 
153 {
154 
155  // update the parameters from DB
156 
157  if(!m_ignoreDB && m_eswatcher.check(iSetup)) {
159  iSetup.get<SiStripConfObjectRcd>().get(m_rcdLabel,confObj);
160 
162  iSetup.get<TrackerTopologyRcd>().get(tTopo);
163 
164  std::stringstream summary;
165  confObj->printDebug(summary, tTopo.product());
166  LogDebug("SiStripConfObjectSummary") << summary.str();
167 
168  _defpartnames = confObj->get<std::vector<std::string> >("defaultPartitionNames");
169  _defphases = confObj->get<std::vector<int> >("defaultPhases");
170  _useEC0 = confObj->get<bool>("useEC0");
171  m_badRun = confObj->get<bool>("badRun");
172  _magicOffset = confObj->get<int>("magicOffset");
173 
174  std::stringstream ss;
175  printConfiguration(ss);
176  edm::LogInfo("UpdatedConfiguration") << ss.str();
177 
178 
179  }
180 
181  if(isBadRun(iRun.run())) {
182  LogDebug("UnreliableMissingL1TriggerScalers") <<
183  "In this run L1TriggerScalers is missing or unreliable for phase determination: invlid phase will be returned";
184  }
185 
186 }
187 
188 
189 void
191 
192  using namespace edm;
193 
194  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection() );
195 
196 
197  std::vector<int> phases(_defphases.size(),APVCyclePhaseCollection::invalid);
198 
199  const std::vector<std::string>& partnames = _defpartnames;
200 
201  int phasechange = 0;
202 
203 
205  iEvent.getByToken(_l1tscollectionToken,l1ts);
206 
207  // offset computation
208 
209  long long orbitoffset = 0;
210 
211  if(!l1ts->empty()) {
212 
213  if((*l1ts)[0].lastResync()!=0) {
214  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
215  }
216 
217  if(_lastResync != (*l1ts)[0].lastResync()) {
218  _lastResync = (*l1ts)[0].lastResync();
219  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync ;
220  }
221  if(_lastHardReset != (*l1ts)[0].lastHardReset()) {
222  _lastHardReset = (*l1ts)[0].lastHardReset();
223  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset ;
224  }
225  if(_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
226  _lastTestEnable = (*l1ts)[0].lastTestEnable();
227  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
228  }
229  if(_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
230  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
231  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0 ;
232  }
233  if(_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
234  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
235  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0 ;
236  }
237  if(_lastStart != (*l1ts)[0].lastStart()) {
238  _lastStart = (*l1ts)[0].lastStart();
239  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart ;
240  }
241 
242  if(!isBadRun(iEvent.run())) {
243  phasechange = ((long long)(orbitoffset*3564))%70;
244 
245  for(unsigned int ipart=0;ipart<phases.size();++ipart) {
246  phases[ipart] = (_defphases[ipart]+phasechange)%70;
247  }
248 
249  }
250  }
251 
252 
253  if(phases.size() < partnames.size() ) {
254  // throw exception
255  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent phases/partitions vector sizes: "
256  << phases.size() << " "
257  << partnames.size();
258  }
259 
260  for(unsigned int ipart=0;ipart<partnames.size();++ipart) {
261  // if(phases[ipart]>=0) {
262  // apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
263  apvphases->get()[partnames[ipart]] = phases[ipart];
264 
265  // }
266  }
267 
268 
269  iEvent.put(std::move(apvphases));
270 
271 }
272 
273 bool
274 APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
275 
276  for(std::vector<std::pair<unsigned int, unsigned int> >::const_iterator runpair = m_badruns.begin();runpair!=m_badruns.end();++runpair) {
277  if( run >= runpair->first && run <= runpair->second) return true;
278  }
279 
280  return m_badRun;
281 
282 }
283 
284 void
286 
287  ss << _defpartnames.size() << " default partition names: ";
288  for(std::vector<std::string>::const_iterator part=_defpartnames.begin();part!=_defpartnames.end();++part) {
289  ss << *part << " ";
290  }
291  ss << std::endl;
292  ss << _defphases.size() << " default phases: ";
293  for(std::vector<int>::const_iterator phase=_defphases.begin();phase!=_defphases.end();++phase) {
294  ss << *phase << " ";
295  }
296  ss << std::endl;
297  ss << " Magic offset: " << _magicOffset << std::endl;
298  ss << " use ECO: " << _useEC0 << std::endl;
299  ss << " bad run: " << m_badRun << std::endl;
300 
301 }
302 //define this as a plug-in
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
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:517
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:101
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:71
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