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 <time.h>
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  char line[128];
225  char zeitHeaven[128];
226  struct tm * horaHeaven;
227 
228  sprintf(line, " TrigType: %d EventID: %d BunchNumber: %d",
229  c.trigType(), c.eventID(), c.bunchNumber());
230  s << line << std::endl;
231 
232  struct timespec secondsToHeaven = c.collectionTime();
233  horaHeaven = gmtime(&secondsToHeaven.tv_sec);
234  strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
235  sprintf(line, " CollectionTime: %s.%9.9d" ,
236  zeitHeaven, (int)secondsToHeaven.tv_nsec);
237  s << line << std::endl;
238 
239  sprintf(line,
240  " LumiSegmentNr: %10u LumiSegmentOrbits: %10u",
242  s << line << std::endl;
243 
244  sprintf(line,
245  " LumiSegmentNrLumiSeg: %10u OrbitNr: %10u ",
246  c.lumiSegmentNrLumiSeg(), c.orbitNr());
247  s << line << std::endl;
248 
249  sprintf(line,
250  " GtResets: %10u BunchCrossingErrors: %10u",
251  c.gtResets(), c.bunchCrossingErrors());
252  s << line << std::endl;
253 
254  sprintf(line,
255  " PrescaleIndexAlgo: %10d PrescaleIndexTech: %10d",
257  s << line << std::endl;
258 
259  sprintf(line, " GtTriggers: %20llu %22.3f Hz",
260  c.gtTriggers(), c.gtTriggersRate());
261  s << line << std::endl;
262 
263  sprintf(line, " GtEvents: %20llu %22.3f Hz",
264  c.gtEvents(), c.gtEventsRate());
265  s << line << std::endl;
266 
267  secondsToHeaven = c.collectionTimeLumiSeg();
268  horaHeaven = gmtime(&secondsToHeaven.tv_sec);
269  strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
270  sprintf(line, " CollectionTimeLumiSeg: %s.%9.9d" ,
271  zeitHeaven, (int)secondsToHeaven.tv_nsec);
272  s << line << std::endl;
273 
274 
275  sprintf(line, " TriggersPhysicsGeneratedFDL: %20llu %22.3f Hz",
278  s << line << std::endl;
279 
280  sprintf(line, " TriggersPhysicsLost: %20llu %22.3f Hz",
283  s << line << std::endl;
284 
285  sprintf(line, " TriggersPhysicsLostBeamActive: %20llu %22.3f Hz",
288  s << line << std::endl;
289 
290  sprintf(line, " TriggersPhysicsLostBeamInactive: %20llu %22.3f Hz",
293  s << line << std::endl;
294 
295  sprintf(line, " L1AsPhysics: %20llu %22.3f Hz",
296  c.l1AsPhysics(),
298  s << line << std::endl;
299 
300  sprintf(line, " L1AsRandom: %20llu %22.3f Hz",
301  c.l1AsRandom(),
303  s << line << std::endl;
304 
305  sprintf(line, " L1AsTest: %20llu %22.3f Hz",
306  c.l1AsTest(),
308  s << line << std::endl;
309 
310  sprintf(line, " L1AsCalibration: %20llu %22.3f Hz",
311  c.l1AsCalibration(),
313  s << line << std::endl;
314 
315  sprintf(line, " Deadtime: %20llu %17.3f%%",
316  c.deadtime(),
318  s << line << std::endl;
319 
320  sprintf(line, " DeadtimeBeamActive: %20llu %17.3f%%",
321  c.deadtimeBeamActive(),
323  s << line << std::endl;
324 
325  sprintf(line, " DeadtimeBeamActiveTriggerRules: %20llu %17.3f%%",
328  s << line << std::endl;
329 
330  sprintf(line, " DeadtimeBeamActiveCalibration: %20llu %17.3f%%",
333  s << line << std::endl;
334 
335  sprintf(line, " DeadtimeBeamActivePrivateOrbit: %20llu %17.3f%%",
338  s << line << std::endl;
339 
340  sprintf(line, " DeadtimeBeamActivePartitionController:%20llu %17.3f%%",
343  s << line << std::endl;
344 
345  sprintf(line, " DeadtimeBeamActiveTimeSlot: %20llu %17.3f%%",
348  s << line << std::endl;
349 
350  s << "Physics GtAlgoCounts" << std::endl;
351  const std::vector<unsigned int> gtAlgoCounts = c.gtAlgoCounts();
352  int length = gtAlgoCounts.size() / 4;
353  for ( int i=0; i<length; i++)
354  {
355  sprintf(line," %3.3d: %10u %3.3d: %10u %3.3d: %10u %3.3d: %10u",
356  i, gtAlgoCounts[i],
357  (i+length), gtAlgoCounts[i+length],
358  (i+(length*2)), gtAlgoCounts[i+(length*2)],
359  (i+(length*3)), gtAlgoCounts[i+(length*3)]);
360  s << line << std::endl;
361  }
362 
363  s << "Test GtTechCounts" << std::endl;
364  const std::vector<unsigned int> gtTechCounts = c.gtTechCounts();
365  length = gtTechCounts.size() / 4;
366  for ( int i=0; i<length; i++)
367  {
368  sprintf(line," %3.3d: %10u %3.3d: %10u %3.3d: %10u %3.3d: %10u",
369  i, gtTechCounts[i],
370  (i+length), gtTechCounts[i+length],
371  (i+(length*2)), gtTechCounts[i+(length*2)],
372  (i+(length*3)), gtTechCounts[i+(length*3)]);
373  s << line << std::endl;
374  }
375 
376  if ( c.version() >= 5 )
377  {
378  sprintf(line," LastOrbitCounter0: %10u 0x%8.8X", c.lastOrbitCounter0(),
379  c.lastOrbitCounter0());
380  s << line << std::endl;
381 
382  sprintf(line," LastTestEnable: %10u 0x%8.8X", c.lastTestEnable(),
383  c.lastTestEnable());
384  s << line << std::endl;
385 
386  sprintf(line," LastResync: %10u 0x%8.8X", c.lastResync(),
387  c.lastResync());
388  s << line << std::endl;
389 
390  sprintf(line," LastStart: %10u 0x%8.8X", c.lastStart(),
391  c.lastStart());
392  s << line << std::endl;
393 
394  sprintf(line," LastEventCounter0: %10u 0x%8.8X", c.lastEventCounter0(),
395  c.lastEventCounter0());
396  s << line << std::endl;
397 
398  sprintf(line," LastHardReset: %10u 0x%8.8X", c.lastHardReset(),
399  c.lastHardReset());
400  s << line << std::endl;
401  }
402 
403  return s;
404 }
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_
int i
Definition: DBlmapReader.cc:9
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
unsigned long long l1AsPhysics
Definition: ScalersRaw.h:104
unsigned long long gtEvents_
unsigned long long l1AsRandom_