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  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
65  virtual 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 
161  std::stringstream summary;
162  confObj->printDebug(summary);
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;
172  printConfiguration(ss);
173  edm::LogInfo("UpdatedConfiguration") << ss.str();
174 
175 
176  }
177 
178  if(isBadRun(iRun.run())) {
179  LogDebug("UnreliableMissingL1TriggerScalers") <<
180  "In this run L1TriggerScalers is missing or unreliable for phase determination: invlid phase will be returned";
181  }
182 
183 }
184 
185 
186 void
188 
189  using namespace edm;
190 
191  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection() );
192 
193 
194  std::vector<int> phases(_defphases.size(),APVCyclePhaseCollection::invalid);
195 
196  const std::vector<std::string>& partnames = _defpartnames;
197 
198  int phasechange = 0;
199 
200 
202  iEvent.getByToken(_l1tscollectionToken,l1ts);
203 
204  // offset computation
205 
206  long long orbitoffset = 0;
207 
208  if(l1ts->size()>0) {
209 
210  if((*l1ts)[0].lastResync()!=0) {
211  orbitoffset = _useEC0 ? (*l1ts)[0].lastEventCounter0() + _magicOffset : (*l1ts)[0].lastResync() + _magicOffset;
212  }
213 
214  if(_lastResync != (*l1ts)[0].lastResync()) {
215  _lastResync = (*l1ts)[0].lastResync();
216  LogDebug("TTCSignalReceived") << "New Resync at orbit " << _lastResync ;
217  }
218  if(_lastHardReset != (*l1ts)[0].lastHardReset()) {
219  _lastHardReset = (*l1ts)[0].lastHardReset();
220  LogDebug("TTCSignalReceived") << "New HardReset at orbit " << _lastHardReset ;
221  }
222  if(_lastTestEnable != (*l1ts)[0].lastTestEnable()) {
223  _lastTestEnable = (*l1ts)[0].lastTestEnable();
224  // LogDebug("TTCSignalReceived") << "New TestEnable at orbit " << _lastTestEnable ;
225  }
226  if(_lastOrbitCounter0 != (*l1ts)[0].lastOrbitCounter0()) {
227  _lastOrbitCounter0 = (*l1ts)[0].lastOrbitCounter0();
228  LogDebug("TTCSignalReceived") << "New OrbitCounter0 at orbit " << _lastOrbitCounter0 ;
229  }
230  if(_lastEventCounter0 != (*l1ts)[0].lastEventCounter0()) {
231  _lastEventCounter0 = (*l1ts)[0].lastEventCounter0();
232  LogDebug("TTCSignalReceived") << "New EventCounter0 at orbit " << _lastEventCounter0 ;
233  }
234  if(_lastStart != (*l1ts)[0].lastStart()) {
235  _lastStart = (*l1ts)[0].lastStart();
236  LogDebug("TTCSignalReceived") << "New Start at orbit " << _lastStart ;
237  }
238 
239  if(!isBadRun(iEvent.run())) {
240  phasechange = ((long long)(orbitoffset*3564))%70;
241 
242  for(unsigned int ipart=0;ipart<phases.size();++ipart) {
243  phases[ipart] = (_defphases[ipart]+phasechange)%70;
244  }
245 
246  }
247  }
248 
249 
250  if(phases.size() < partnames.size() ) {
251  // throw exception
252  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent phases/partitions vector sizes: "
253  << phases.size() << " "
254  << partnames.size();
255  }
256 
257  for(unsigned int ipart=0;ipart<partnames.size();++ipart) {
258  // if(phases[ipart]>=0) {
259  // apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;
260  apvphases->get()[partnames[ipart]] = phases[ipart];
261 
262  // }
263  }
264 
265 
266  iEvent.put(std::move(apvphases));
267 
268 }
269 
270 bool
271 APVCyclePhaseProducerFromL1TS::isBadRun(const unsigned int run) const {
272 
273  for(std::vector<std::pair<unsigned int, unsigned int> >::const_iterator runpair = m_badruns.begin();runpair!=m_badruns.end();++runpair) {
274  if( run >= runpair->first && run <= runpair->second) return true;
275  }
276 
277  return m_badRun;
278 
279 }
280 
281 void
283 
284  ss << _defpartnames.size() << " default partition names: ";
285  for(std::vector<std::string>::const_iterator part=_defpartnames.begin();part!=_defpartnames.end();++part) {
286  ss << *part << " ";
287  }
288  ss << std::endl;
289  ss << _defphases.size() << " default phases: ";
290  for(std::vector<int>::const_iterator phase=_defphases.begin();phase!=_defphases.end();++phase) {
291  ss << *phase << " ";
292  }
293  ss << std::endl;
294  ss << " Magic offset: " << _magicOffset << std::endl;
295  ss << " use ECO: " << _useEC0 << std::endl;
296  ss << " bad run: " << m_badRun << std::endl;
297 
298 }
299 //define this as a plug-in
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
RunNumber_t run() const
Definition: RunBase.h:40
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESWatcher< SiStripConfObjectRcd > m_eswatcher
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
RunNumber_t run() const
Definition: Event.h:94
void printConfiguration(std::stringstream &ss) const
bool isBadRun(const unsigned int) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< int > phases
part
Definition: HCALResponse.h:20
const T & get() const
Definition: EventSetup.h:55
void printDebug(std::stringstream &ss) const
Prints the full list of parameters.
std::vector< Level1TriggerScalers > Level1TriggerScalersCollection
valueType get(const std::string &name) const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< std::pair< unsigned int, unsigned int > > m_badruns
HLT enums.
APVCyclePhaseProducerFromL1TS(const edm::ParameterSet &)
edm::EDGetTokenT< Level1TriggerScalersCollection > _l1tscollectionToken
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42