CMS 3D CMS Logo

Level1TriggerScalers.cc
Go to the documentation of this file.
1 /*
2  * File: DataFormats/Scalers/src/Level1TriggerScalers.cc (W.Badgett)
3  */
4 
7 
8 #include <iostream>
9 #include <ctime>
10 #include <cstdio>
11 
13  version_(0),
14  trigType_(0),
15  eventID_(0),
16  sourceID_(0),
17  bunchNumber_(0),
18  collectionTime_(0,0),
19  lumiSegmentNr_(0),
20  lumiSegmentOrbits_(0),
21  orbitNr_(0),
22  gtResets_(0),
23  bunchCrossingErrors_(0),
24  gtTriggers_(0),
25  gtEvents_(0),
26  gtTriggersRate_((float)0.0),
27  gtEventsRate_((float)0.0),
28  prescaleIndexAlgo_(0),
29  prescaleIndexTech_(0),
30  collectionTimeLumiSeg_(0,0),
31  lumiSegmentNrLumiSeg_(0),
32  triggersPhysicsGeneratedFDL_(0),
33  triggersPhysicsLost_(0),
34  triggersPhysicsLostBeamActive_(0),
35  triggersPhysicsLostBeamInactive_(0),
36  l1AsPhysics_(0),
37  l1AsRandom_(0),
38  l1AsTest_(0),
39  l1AsCalibration_(0),
40  deadtime_(0),
41  deadtimeBeamActive_(0),
42  deadtimeBeamActiveTriggerRules_(0),
43  deadtimeBeamActiveCalibration_(0),
44  deadtimeBeamActivePrivateOrbit_(0),
45  deadtimeBeamActivePartitionController_(0),
46  deadtimeBeamActiveTimeSlot_(0),
47  gtAlgoCounts_(nLevel1Triggers),
48  gtTechCounts_(nLevel1TestTriggers),
49  lastOrbitCounter0_(0),
50  lastTestEnable_(0),
51  lastResync_(0),
52  lastStart_(0),
53  lastEventCounter0_(0),
54  lastHardReset_(0),
55  spare0_(0ULL),
56  spare1_(0ULL),
57  spare2_(0ULL)
58 {
59 }
60 
61 Level1TriggerScalers::Level1TriggerScalers(const unsigned char * rawData)
62 {
64 
65  struct ScalersEventRecordRaw_v5 const * raw
66  = reinterpret_cast<struct ScalersEventRecordRaw_v5 const *>(rawData);
67 
68  trigType_ = ( raw->header >> 56 ) & 0xFULL;
69  eventID_ = ( raw->header >> 32 ) & 0x00FFFFFFULL;
70  sourceID_ = ( raw->header >> 8 ) & 0x00000FFFULL;
71  bunchNumber_ = ( raw->header >> 20 ) & 0xFFFULL;
72 
73  version_ = raw->version;
74  if ( version_ >= 3 )
75  {
76  collectionTime_.set_tv_sec( static_cast<long>(
77  raw->trig.collectionTime_sec));
80 
83  orbitNr_ = raw->trig.orbitNr;
84  gtResets_ = raw->trig.gtResets;
87  gtEvents_ = raw->trig.gtEvents;
92 
93  collectionTimeLumiSeg_.set_tv_sec( static_cast<long>(
97 
104 
106  l1AsRandom_ = raw->trig.l1AsRandom;
107  l1AsTest_ = raw->trig.l1AsTest;
109  deadtime_ = raw->trig.deadtime;
117 
118  for ( int i=0; i<ScalersRaw::N_L1_TRIGGERS_v1; i++)
119  { gtAlgoCounts_.push_back( raw->trig.gtAlgoCounts[i]);}
120 
121  for ( int i=0; i<ScalersRaw::N_L1_TEST_TRIGGERS_v1; i++)
122  { gtTechCounts_.push_back( raw->trig.gtTechCounts[i]);}
123 
124  if ( version_ >= 5 )
125  {
128  lastResync_ = raw->lastResync;
129  lastStart_ = raw->lastStart;
132  spare0_ = raw->spare[0];
133  spare1_ = raw->spare[1];
134  spare2_ = raw->spare[2];
135  }
136  else
137  {
138  lastOrbitCounter0_ = 0UL;
139  lastTestEnable_ = 0UL;
140  lastResync_ = 0UL;
141  lastStart_ = 0UL;
142  lastEventCounter0_ = 0UL;
143  lastHardReset_ = 0UL;
144  spare0_ = 0ULL;
145  spare1_ = 0ULL;
146  spare2_ = 0ULL;
147  }
148  }
149 }
150 
152 
153 double Level1TriggerScalers::rateLS(unsigned int counts)
154 { return(rateLS(counts,firstShortLSRun));}
155 
156 double Level1TriggerScalers::rateLS(unsigned long long counts)
157 { return(rateLS(counts,firstShortLSRun));}
158 
159 double Level1TriggerScalers::rateLS(unsigned int counts,
160  int runNumber)
161 {
162  unsigned long long counts64 = (unsigned long long)counts;
163  return(rateLS(counts64,runNumber));
164 }
165 
166 double Level1TriggerScalers::rateLS(unsigned long long counts,
167  int runNumber)
168 {
169  double rate;
170  if (( runNumber >= firstShortLSRun ) || ( runNumber <= 1 ))
171  {
172  rate = ((double)counts) / 23.31040958083832;
173  }
174  else
175  {
176  rate = ((double)counts) / 93.24163832335329;
177  }
178  return(rate);
179 }
180 
181 double Level1TriggerScalers::percentLS(unsigned long long counts)
182 { return(percentLS(counts,firstShortLSRun));}
183 
184 double Level1TriggerScalers::percentLS(unsigned long long counts,
185  int runNumber)
186 {
187  double percent;
188  if (( runNumber >= firstShortLSRun ) || ( runNumber <= 1 ))
189  {
190  percent = ((double)counts) / 9342812.16;
191  }
192  else
193  {
194  percent = ((double)counts) / 37371248.64;
195  }
196  if ( percent > 100.0000 ) { percent = 100.0;}
197  return(percent);
198 }
199 
200 double Level1TriggerScalers::percentLSActive(unsigned long long counts)
201 { return(percentLSActive(counts,firstShortLSRun));}
202 
203 double Level1TriggerScalers::percentLSActive(unsigned long long counts,
204  int runNumber)
205 {
206  double percent;
207  if (( runNumber >= firstShortLSRun ) || ( runNumber <= 1 ))
208  {
209  percent = ((double)counts) / 7361003.52;
210  }
211  else
212  {
213  percent = ((double)counts) / 29444014.08;
214  }
215  if ( percent > 100.0000 ) { percent = 100.0;}
216  return(percent);
217 }
218 
220 std::ostream& operator<<(std::ostream& s,Level1TriggerScalers const &c)
221 {
222  s << "Level1TriggerScalers Version:" << c.version() <<
223  " SourceID: " << c.sourceID() << std::endl;
224  constexpr size_t kLineBufferSize = 164;
225  char line[kLineBufferSize];
226  char zeitHeaven[128];
227  struct tm * horaHeaven;
228 
229  snprintf(line, kLineBufferSize, " TrigType: %d EventID: %d BunchNumber: %d",
230  c.trigType(), c.eventID(), c.bunchNumber());
231  s << line << std::endl;
232 
233  struct timespec secondsToHeaven = c.collectionTime();
234  horaHeaven = gmtime(&secondsToHeaven.tv_sec);
235  strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
236  snprintf(line, kLineBufferSize, " CollectionTime: %s.%9.9d" ,
237  zeitHeaven, (int)secondsToHeaven.tv_nsec);
238  s << line << std::endl;
239 
240  snprintf(line, kLineBufferSize,
241  " LumiSegmentNr: %10u LumiSegmentOrbits: %10u",
243  s << line << std::endl;
244 
245  snprintf(line, kLineBufferSize,
246  " LumiSegmentNrLumiSeg: %10u OrbitNr: %10u ",
247  c.lumiSegmentNrLumiSeg(), c.orbitNr());
248  s << line << std::endl;
249 
250  snprintf(line, kLineBufferSize,
251  " GtResets: %10u BunchCrossingErrors: %10u",
252  c.gtResets(), c.bunchCrossingErrors());
253  s << line << std::endl;
254 
255  snprintf(line, kLineBufferSize,
256  " PrescaleIndexAlgo: %10d PrescaleIndexTech: %10d",
258  s << line << std::endl;
259 
260  snprintf(line, kLineBufferSize, " GtTriggers: %20llu %22.3f Hz",
261  c.gtTriggers(), c.gtTriggersRate());
262  s << line << std::endl;
263 
264  snprintf(line, kLineBufferSize, " GtEvents: %20llu %22.3f Hz",
265  c.gtEvents(), c.gtEventsRate());
266  s << line << std::endl;
267 
268  secondsToHeaven = c.collectionTimeLumiSeg();
269  horaHeaven = gmtime(&secondsToHeaven.tv_sec);
270  strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
271  snprintf(line, kLineBufferSize, " CollectionTimeLumiSeg: %s.%9.9d" ,
272  zeitHeaven, (int)secondsToHeaven.tv_nsec);
273  s << line << std::endl;
274 
275 
276  snprintf(line, kLineBufferSize, " TriggersPhysicsGeneratedFDL: %20llu %22.3f Hz",
279  s << line << std::endl;
280 
281  snprintf(line, kLineBufferSize, " TriggersPhysicsLost: %20llu %22.3f Hz",
284  s << line << std::endl;
285 
286  snprintf(line, kLineBufferSize, " TriggersPhysicsLostBeamActive: %20llu %22.3f Hz",
289  s << line << std::endl;
290 
291  snprintf(line, kLineBufferSize, " TriggersPhysicsLostBeamInactive: %20llu %22.3f Hz",
294  s << line << std::endl;
295 
296  snprintf(line, kLineBufferSize, " L1AsPhysics: %20llu %22.3f Hz",
297  c.l1AsPhysics(),
299  s << line << std::endl;
300 
301  snprintf(line, kLineBufferSize, " L1AsRandom: %20llu %22.3f Hz",
302  c.l1AsRandom(),
304  s << line << std::endl;
305 
306  snprintf(line, kLineBufferSize, " L1AsTest: %20llu %22.3f Hz",
307  c.l1AsTest(),
309  s << line << std::endl;
310 
311  snprintf(line, kLineBufferSize, " L1AsCalibration: %20llu %22.3f Hz",
312  c.l1AsCalibration(),
314  s << line << std::endl;
315 
316  snprintf(line, kLineBufferSize, " Deadtime: %20llu %17.3f%%",
317  c.deadtime(),
319  s << line << std::endl;
320 
321  snprintf(line, kLineBufferSize, " DeadtimeBeamActive: %20llu %17.3f%%",
322  c.deadtimeBeamActive(),
324  s << line << std::endl;
325 
326  snprintf(line, kLineBufferSize, " DeadtimeBeamActiveTriggerRules: %20llu %17.3f%%",
329  s << line << std::endl;
330 
331  snprintf(line, kLineBufferSize, " DeadtimeBeamActiveCalibration: %20llu %17.3f%%",
334  s << line << std::endl;
335 
336  snprintf(line, kLineBufferSize, " DeadtimeBeamActivePrivateOrbit: %20llu %17.3f%%",
339  s << line << std::endl;
340 
341  snprintf(line, kLineBufferSize, " DeadtimeBeamActivePartitionController:%20llu %17.3f%%",
344  s << line << std::endl;
345 
346  snprintf(line, kLineBufferSize, " DeadtimeBeamActiveTimeSlot: %20llu %17.3f%%",
349  s << line << std::endl;
350 
351  s << "Physics GtAlgoCounts" << std::endl;
352  const std::vector<unsigned int> gtAlgoCounts = c.gtAlgoCounts();
353  int length = gtAlgoCounts.size() / 4;
354  for ( int i=0; i<length; i++)
355  {
356  snprintf(line, kLineBufferSize," %3.3d: %10u %3.3d: %10u %3.3d: %10u %3.3d: %10u",
357  i, gtAlgoCounts[i],
358  (i+length), gtAlgoCounts[i+length],
359  (i+(length*2)), gtAlgoCounts[i+(length*2)],
360  (i+(length*3)), gtAlgoCounts[i+(length*3)]);
361  s << line << std::endl;
362  }
363 
364  s << "Test GtTechCounts" << std::endl;
365  const std::vector<unsigned int> gtTechCounts = c.gtTechCounts();
366  length = gtTechCounts.size() / 4;
367  for ( int i=0; i<length; i++)
368  {
369  snprintf(line, kLineBufferSize," %3.3d: %10u %3.3d: %10u %3.3d: %10u %3.3d: %10u",
370  i, gtTechCounts[i],
371  (i+length), gtTechCounts[i+length],
372  (i+(length*2)), gtTechCounts[i+(length*2)],
373  (i+(length*3)), gtTechCounts[i+(length*3)]);
374  s << line << std::endl;
375  }
376 
377  if ( c.version() >= 5 )
378  {
379  snprintf(line, kLineBufferSize," LastOrbitCounter0: %10u 0x%8.8X", c.lastOrbitCounter0(),
380  c.lastOrbitCounter0());
381  s << line << std::endl;
382 
383  snprintf(line, kLineBufferSize," LastTestEnable: %10u 0x%8.8X", c.lastTestEnable(),
384  c.lastTestEnable());
385  s << line << std::endl;
386 
387  snprintf(line, kLineBufferSize," LastResync: %10u 0x%8.8X", c.lastResync(),
388  c.lastResync());
389  s << line << std::endl;
390 
391  snprintf(line, kLineBufferSize," LastStart: %10u 0x%8.8X", c.lastStart(),
392  c.lastStart());
393  s << line << std::endl;
394 
395  snprintf(line, kLineBufferSize," LastEventCounter0: %10u 0x%8.8X", c.lastEventCounter0(),
396  c.lastEventCounter0());
397  s << line << std::endl;
398 
399  snprintf(line, kLineBufferSize," LastHardReset: %10u 0x%8.8X", c.lastHardReset(),
400  c.lastHardReset());
401  s << line << std::endl;
402  }
403 
404  return s;
405 }
unsigned long long deadtimeBeamActivePartitionController_
unsigned int gtTechCounts[ScalersRaw::N_L1_TEST_TRIGGERS_v1]
Definition: ScalersRaw.h:117
unsigned long long l1AsTest
Definition: ScalersRaw.h:106
unsigned long long spare1_
unsigned int orbitNr
Definition: ScalersRaw.h:87
static double rateLS(unsigned long long counts)
unsigned long long deadtimeBeamActiveTriggerRules_
unsigned long long gtEvents() const
unsigned long long deadtimeBeamActive() const
unsigned long long deadtimeBeamActivePrivateOrbit() const
unsigned long long triggersPhysicsGeneratedFDL() const
unsigned int bunchNumber() const
unsigned int lastTestEnable() const
void set_tv_nsec(long value)
Definition: TimeSpec.h:27
unsigned int lastResync
Definition: ScalersRaw.h:243
unsigned long long spare[ScalersRaw::N_SPARE_v5]
Definition: ScalersRaw.h:247
unsigned long long l1AsRandom() const
unsigned long long triggersPhysicsLostBeamInactive_
unsigned long long deadtimeBeamActiveTimeSlot_
unsigned int lastResync() const
std::vector< unsigned int > gtTechCounts() const
unsigned long long l1AsRandom
Definition: ScalersRaw.h:105
unsigned int trigType() const
unsigned long long triggersPhysicsLost() const
unsigned long long triggersPhysicsLostBeamActive() const
unsigned int collectionTime_sec
Definition: ScalersRaw.h:83
unsigned int lastStart() const
unsigned int collectionTime_nsec
Definition: ScalersRaw.h:84
unsigned long long gtTriggers_
unsigned int gtResets() const
unsigned long long l1AsCalibration() const
std::vector< unsigned int > gtTechCounts_
std::vector< unsigned int > gtAlgoCounts_
unsigned long long l1AsCalibration
Definition: ScalersRaw.h:107
unsigned long long deadtimeBeamActivePartitionController
Definition: ScalersRaw.h:113
unsigned long long deadtimeBeamActiveTimeSlot
Definition: ScalersRaw.h:114
unsigned long long triggersPhysicsLostBeamInactive
Definition: ScalersRaw.h:103
unsigned long long deadtime_
unsigned long long deadtimeBeamActiveTriggerRules
Definition: ScalersRaw.h:110
unsigned long long l1AsTest_
unsigned int bunchCrossingErrors() const
unsigned int orbitNr() const
unsigned int lastEventCounter0() const
struct TriggerScalersRaw_v3 trig
Definition: ScalersRaw.h:237
std::vector< unsigned int > gtAlgoCounts() const
std::ostream & operator<<(std::ostream &s, Level1TriggerScalers const &c)
Pretty-print operator for Level1TriggerScalers.
unsigned int collectionTimeLumiSeg_nsec
Definition: ScalersRaw.h:98
unsigned long long triggersPhysicsLost_
unsigned int lumiSegmentOrbits
Definition: ScalersRaw.h:86
unsigned long long l1AsPhysics() const
unsigned int lumiSegmentOrbits() const
static double percentLSActive(unsigned long long counts)
unsigned long long l1AsCalibration_
unsigned int lastHardReset
Definition: ScalersRaw.h:246
unsigned long long deadtimeBeamActiveTriggerRules() const
unsigned long long deadtimeBeamActivePrivateOrbit_
unsigned int lastHardReset() const
unsigned int lastStart
Definition: ScalersRaw.h:244
unsigned int lumiSegmentNrLumiSeg_
unsigned long long l1AsTest() const
unsigned int lastOrbitCounter0() const
unsigned int lumiSegmentNr() const
unsigned int lastEventCounter0
Definition: ScalersRaw.h:245
unsigned long long deadtimeBeamActive_
unsigned long long deadtimeBeamActivePrivateOrbit
Definition: ScalersRaw.h:112
unsigned long long deadtime() const
unsigned int gtAlgoCounts[ScalersRaw::N_L1_TRIGGERS_v1]
Definition: ScalersRaw.h:116
unsigned int lastTestEnable
Definition: ScalersRaw.h:242
unsigned long long gtTriggers() const
static double percentLS(unsigned long long counts)
unsigned int eventID() const
float gtTriggersRate() const
unsigned int sourceID() const
struct timespec collectionTimeLumiSeg() const
unsigned long long deadtimeBeamActiveTimeSlot() const
unsigned long long triggersPhysicsLostBeamActive
Definition: ScalersRaw.h:102
unsigned long long l1AsPhysics_
unsigned long long gtEvents
Definition: ScalersRaw.h:91
unsigned long long deadtimeBeamActiveCalibration() const
double rate(double x)
Definition: Constants.cc:3
unsigned long long deadtime
Definition: ScalersRaw.h:108
unsigned long long gtTriggers
Definition: ScalersRaw.h:90
unsigned long long triggersPhysicsLostBeamActive_
unsigned int collectionTimeLumiSeg_sec
Definition: ScalersRaw.h:97
unsigned int lastOrbitCounter0
Definition: ScalersRaw.h:241
unsigned long long deadtimeBeamActiveCalibration
Definition: ScalersRaw.h:111
unsigned int gtResets
Definition: ScalersRaw.h:88
unsigned long long triggersPhysicsLostBeamInactive() const
unsigned long long spare2_
void set_tv_sec(long value)
Definition: TimeSpec.h:26
unsigned long long header
Definition: ScalersRaw.h:235
unsigned int lumiSegmentNrLumiSeg
Definition: ScalersRaw.h:99
unsigned long long spare0_
unsigned long long deadtimeBeamActiveCalibration_
unsigned long long deadtimeBeamActivePartitionController() const
unsigned int lumiSegmentNrLumiSeg() const
unsigned long long deadtimeBeamActive
Definition: ScalersRaw.h:109
unsigned long long triggersPhysicsGeneratedFDL
Definition: ScalersRaw.h:100
unsigned long long triggersPhysicsLost
Definition: ScalersRaw.h:101
unsigned long long triggersPhysicsGeneratedFDL_
unsigned int bunchCrossingErrors
Definition: ScalersRaw.h:89
unsigned int lumiSegmentNr
Definition: ScalersRaw.h:85
struct timespec collectionTime() const
#define constexpr
unsigned long long l1AsPhysics
Definition: ScalersRaw.h:104
unsigned long long gtEvents_
unsigned long long l1AsRandom_