CMS 3D CMS Logo

LumiScalers.cc
Go to the documentation of this file.
1 
2 /*
3  * File: DataFormats/Scalers/src/LumiScalers.cc (W.Badgett)
4  */
5 
8 #include <cstdio>
9 #include <ostream>
10 
12  : trigType_(0),
13  eventID_(0),
14  sourceID_(0),
15  bunchNumber_(0),
16  version_(0),
17  normalization_(0.0),
18  deadTimeNormalization_(0.0),
19  lumiFill_(0.0),
20  lumiRun_(0.0),
21  liveLumiFill_(0.0),
22  liveLumiRun_(0.0),
23  instantLumi_(0.0),
24  instantLumiErr_(0.0),
25  instantLumiQlty_(0),
26  lumiETFill_(0.0),
27  lumiETRun_(0.0),
28  liveLumiETFill_(0.0),
29  liveLumiETRun_(0.0),
30  instantETLumi_(0.0),
31  instantETLumiErr_(0.0),
32  instantETLumiQlty_(0),
33  lumiOccFill_(nOcc),
34  lumiOccRun_(nOcc),
35  liveLumiOccFill_(nOcc),
36  liveLumiOccRun_(nOcc),
37  instantOccLumi_(nOcc),
38  instantOccLumiErr_(nOcc),
39  instantOccLumiQlty_(nOcc),
40  lumiNoise_(nOcc),
41  sectionNumber_(0),
42  startOrbit_(0),
43  numOrbits_(0),
44  pileup_(0.0),
45  pileupRMS_(0.0),
46  bunchLumi_(0.0),
47  spare_(0.0) {}
48 
49 LumiScalers::LumiScalers(const unsigned char* rawData) {
50  LumiScalers();
51 
52  struct ScalersEventRecordRaw_v1 const* raw = reinterpret_cast<struct ScalersEventRecordRaw_v1 const*>(rawData);
53  trigType_ = (raw->header >> 56) & 0xFULL;
54  eventID_ = (raw->header >> 32) & 0x00FFFFFFULL;
55  sourceID_ = (raw->header >> 8) & 0x00000FFFULL;
56  bunchNumber_ = (raw->header >> 20) & 0xFFFULL;
57  version_ = raw->version;
58 
59  struct LumiScalersRaw_v1 const* lumi = nullptr;
60 
61  if (version_ >= 1) {
62  if (version_ <= 2) {
63  lumi = &(raw->lumi);
64  } else {
65  struct ScalersEventRecordRaw_v3 const* raw3 = reinterpret_cast<struct ScalersEventRecordRaw_v3 const*>(rawData);
66  lumi = &(raw3->lumi);
67  }
68  collectionTime_.set_tv_sec(static_cast<long>(lumi->collectionTime_sec));
69  collectionTime_.set_tv_nsec(lumi->collectionTime_nsec);
70  deadTimeNormalization_ = lumi->DeadtimeNormalization;
71  normalization_ = lumi->Normalization;
72  lumiFill_ = lumi->LumiFill;
73  lumiRun_ = lumi->LumiRun;
74  liveLumiFill_ = lumi->LiveLumiFill;
75  liveLumiRun_ = lumi->LiveLumiRun;
76  instantLumi_ = lumi->InstantLumi;
77  instantLumiErr_ = lumi->InstantLumiErr;
78  instantLumiQlty_ = lumi->InstantLumiQlty;
79  lumiETFill_ = lumi->LumiETFill;
80  lumiETRun_ = lumi->LumiETRun;
81  liveLumiETFill_ = lumi->LiveLumiETFill;
82  liveLumiETRun_ = lumi->LiveLumiETRun;
83  instantETLumi_ = lumi->InstantETLumi;
84  instantETLumiErr_ = lumi->InstantETLumiErr;
85  instantETLumiQlty_ = lumi->InstantETLumiQlty;
86  for (int i = 0; i < ScalersRaw::N_LUMI_OCC_v1; i++) {
87  lumiOccFill_.push_back(lumi->LumiOccFill[i]);
88  lumiOccRun_.push_back(lumi->LumiOccRun[i]);
89  liveLumiOccFill_.push_back(lumi->LiveLumiOccFill[i]);
90  liveLumiOccRun_.push_back(lumi->LiveLumiOccRun[i]);
91  instantOccLumi_.push_back(lumi->InstantOccLumi[i]);
92  instantOccLumiErr_.push_back(lumi->InstantOccLumiErr[i]);
93  instantOccLumiQlty_.push_back(lumi->InstantOccLumiQlty[i]);
94  lumiNoise_.push_back(lumi->lumiNoise[i]);
95  }
96  sectionNumber_ = lumi->sectionNumber;
97  startOrbit_ = lumi->startOrbit;
98  numOrbits_ = lumi->numOrbits;
99 
100  if (version_ >= 7) {
102  float const* fspare = reinterpret_cast<float const*>(raw6->spare);
105  if (version_ >= 8) {
108  } else {
109  bunchLumi_ = (float)0.0;
110  spare_ = (float)0.0;
111  }
112  } else {
113  pileup_ = (float)0.0;
114  pileupRMS_ = (float)0.0;
115  bunchLumi_ = (float)0.0;
116  spare_ = (float)0.0;
117  }
118  }
119 }
120 
122 
124 std::ostream& operator<<(std::ostream& s, const LumiScalers& c) {
125  char zeit[128];
126  constexpr size_t kLineBufferSize = 157;
127  char line[kLineBufferSize];
128  struct tm* hora;
129 
130  s << "LumiScalers Version: " << c.version() << " SourceID: " << c.sourceID() << std::endl;
131 
132  timespec ts = c.collectionTime();
133  hora = gmtime(&ts.tv_sec);
134  strftime(zeit, sizeof(zeit), "%Y.%m.%d %H:%M:%S", hora);
135  snprintf(line, kLineBufferSize, " CollectionTime: %s.%9.9d", zeit, (int)ts.tv_nsec);
136  s << line << std::endl;
137 
138  snprintf(line,
139  kLineBufferSize,
140  " TrigType: %d EventID: %d BunchNumber: %d",
141  c.trigType(),
142  c.eventID(),
143  c.bunchNumber());
144  s << line << std::endl;
145 
146  snprintf(line,
147  kLineBufferSize,
148  " SectionNumber: %10d StartOrbit: %10d NumOrbits: %10d",
149  c.sectionNumber(),
150  c.startOrbit(),
151  c.numOrbits());
152  s << line << std::endl;
153 
154  snprintf(line,
155  kLineBufferSize,
156  " Normalization: %e DeadTimeNormalization: %e",
157  c.normalization(),
158  c.deadTimeNormalization());
159  s << line << std::endl;
160 
161  // Integrated Luminosity
162 
163  snprintf(line, kLineBufferSize, " LumiFill: %e LumiRun: %e", c.lumiFill(), c.lumiRun());
164  s << line << std::endl;
165  snprintf(
166  line, kLineBufferSize, " LiveLumiFill: %e LiveLumiRun: %e", c.liveLumiFill(), c.liveLumiRun());
167  s << line << std::endl;
168 
169  snprintf(line, kLineBufferSize, " LumiETFill: %e LumiETRun: %e", c.lumiFill(), c.lumiRun());
170  s << line << std::endl;
171 
172  snprintf(
173  line, kLineBufferSize, " LiveLumiETFill: %e LiveLumETiRun: %e", c.liveLumiETFill(), c.liveLumiETRun());
174  s << line << std::endl;
175 
176  int length = c.instantOccLumi().size();
177  for (int i = 0; i < length; i++) {
178  snprintf(line,
179  kLineBufferSize,
180  " LumiOccFill[%d]: %e LumiOccRun[%d]: %e",
181  i,
182  c.lumiOccFill()[i],
183  i,
184  c.lumiOccRun()[i]);
185  s << line << std::endl;
186 
187  snprintf(line,
188  kLineBufferSize,
189  " LiveLumiOccFill[%d]: %e LiveLumiOccRun[%d]: %e",
190  i,
191  c.liveLumiOccFill()[i],
192  i,
193  c.liveLumiOccRun()[i]);
194  s << line << std::endl;
195  }
196 
197  // Instantaneous Luminosity
198 
199  snprintf(line,
200  kLineBufferSize,
201  " InstantLumi: %e Err: %e Qlty: %d",
202  c.instantLumi(),
203  c.instantLumiErr(),
204  c.instantLumiQlty());
205  s << line << std::endl;
206 
207  snprintf(line,
208  kLineBufferSize,
209  " InstantETLumi: %e Err: %e Qlty: %d",
210  c.instantETLumi(),
211  c.instantETLumiErr(),
212  c.instantETLumiQlty());
213  s << line << std::endl;
214 
215  for (int i = 0; i < length; i++) {
216  snprintf(line,
217  kLineBufferSize,
218  " InstantOccLumi[%d]: %e Err: %e Qlty: %d",
219  i,
220  c.instantOccLumi()[i],
221  c.instantOccLumiErr()[i],
222  c.instantOccLumiQlty()[i]);
223  s << line << std::endl;
224  snprintf(line, kLineBufferSize, " LumiNoise[%d]: %e", i, c.lumiNoise()[i]);
225  s << line << std::endl;
226  }
227 
228  snprintf(line, kLineBufferSize, " Pileup: %f PileupRMS: %f", c.pileup(), c.pileupRMS());
229  s << line << std::endl;
230 
231  snprintf(line, kLineBufferSize, " BunchLumi: %f Spare: %f", c.bunchLumi(), c.spare());
232  s << line << std::endl;
233 
234  return s;
235 }
float pileup_
Definition: LumiScalers.h:135
std::vector< unsigned char > instantOccLumiQlty_
Definition: LumiScalers.h:128
unsigned char instantLumiQlty_
Definition: LumiScalers.h:111
virtual ~LumiScalers()
Definition: LumiScalers.cc:121
std::vector< float > liveLumiOccRun_
Definition: LumiScalers.h:125
void set_tv_nsec(long value)
Definition: TimeSpec.h:19
std::vector< float > liveLumiOccFill_
Definition: LumiScalers.h:124
float lumiETRun_
Definition: LumiScalers.h:114
unsigned char instantETLumiQlty_
Definition: LumiScalers.h:120
float liveLumiETRun_
Definition: LumiScalers.h:116
std::vector< float > instantOccLumi_
Definition: LumiScalers.h:126
float liveLumiFill_
Definition: LumiScalers.h:107
unsigned long long header
Definition: ScalersRaw.h:182
unsigned long long spare[ScalersRaw::N_SPARE_v5]
Definition: ScalersRaw.h:252
float spare_
Definition: LumiScalers.h:138
std::vector< float > lumiOccRun_
Definition: LumiScalers.h:123
float liveLumiETFill_
Definition: LumiScalers.h:115
float liveLumiRun_
Definition: LumiScalers.h:108
std::vector< float > lumiNoise_
Definition: LumiScalers.h:129
float instantLumiErr_
Definition: LumiScalers.h:110
float deadTimeNormalization_
Definition: LumiScalers.h:103
float lumiETFill_
Definition: LumiScalers.h:113
float pileupRMS_
Definition: LumiScalers.h:136
float lumiFill_
Definition: LumiScalers.h:105
float normalization_
Definition: LumiScalers.h:102
float instantETLumiErr_
Definition: LumiScalers.h:118
unsigned int sectionNumber_
Definition: LumiScalers.h:131
float bunchLumi_
Definition: LumiScalers.h:137
float instantETLumi_
Definition: LumiScalers.h:117
std::vector< float > instantOccLumiErr_
Definition: LumiScalers.h:127
std::vector< float > lumiOccFill_
Definition: LumiScalers.h:122
float lumiRun_
Definition: LumiScalers.h:106
float instantLumi_
Definition: LumiScalers.h:109
unsigned int bunchNumber_
Definition: LumiScalers.h:96
TimeSpec collectionTime_
Definition: LumiScalers.h:100
unsigned int startOrbit_
Definition: LumiScalers.h:132
void set_tv_sec(long value)
Definition: TimeSpec.h:18
struct LumiScalersRaw_v1 lumi
Definition: ScalersRaw.h:204
unsigned int sourceID_
Definition: LumiScalers.h:95
unsigned int eventID_
Definition: LumiScalers.h:94
unsigned int numOrbits_
Definition: LumiScalers.h:133
unsigned int trigType_
Definition: LumiScalers.h:93
struct LumiScalersRaw_v1 lumi
Definition: ScalersRaw.h:185
std::ostream & operator<<(std::ostream &s, const LumiScalers &c)
Pretty-print operator for LumiScalers.
Definition: LumiScalers.cc:124