CMS 3D CMS Logo

MonitorElementCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_Histograms_MonitorElementCollection_h
2 #define DataFormats_Histograms_MonitorElementCollection_h
3 // -*- C++ -*-
4 //
5 // Package: DataFormats/Histograms
6 // Class : MonitorElementCollection
7 //
27 //
28 // Original Author: Marcel Schneider
29 // Created: 2018-05-02
30 //
31 //
34 
35 #include <cstdint>
36 #include <cassert>
37 #include <vector>
38 #include <string>
39 #include <regex>
40 
41 #include "TH1.h"
42 
44  // This is technically a union, but the struct is safer.
45  struct Scalar {
46  int64_t num = 0;
47  double real = 0;
49  };
50 
51  // Quality test result types.
52  // These are inherited from DQMNet/old DQMStore, and left unchanged to avoid
53  // another layer of wrapping. The APIs are used in some places in subsystem
54  // code, and could be changed, but not removed.
55  class QReport {
56  public:
57  struct QValue {
58  int code;
59  float qtresult;
63  };
64  struct DQMChannel {
65  int binx; //< bin # in x-axis (or bin # for 1D histogram)
66  int biny; //< bin # in y-axis (for 2D or 3D histograms)
67  int binz; //< bin # in z-axis (for 3D histograms)
68  float content; //< bin content
69  float RMS; //< RMS of bin content
70 
71  int getBin() { return getBinX(); }
72  int getBinX() { return binx; }
73  int getBinY() { return biny; }
74  int getBinZ() { return binz; }
75  float getContents() { return content; }
76  float getRMS() { return RMS; }
77 
78  DQMChannel(int bx, int by, int bz, float data, float rms) {
79  binx = bx;
80  biny = by;
81  binz = bz;
82  content = data;
83  RMS = rms;
84  }
85 
87  binx = 0;
88  biny = 0;
89  binz = 0;
90  content = 0;
91  RMS = 0;
92  }
93  };
94 
96  QValue& getValue() { return qvalue_; };
97  QValue const& getValue() const { return qvalue_; };
98 
100  int getStatus() const { return qvalue_.code; }
101 
103  float getQTresult() const { return qvalue_.qtresult; }
104 
106  const std::string& getMessage() const { return qvalue_.message; }
107 
109  const std::string& getQRName() const { return qvalue_.qtname; }
110 
112  const std::string& getAlgorithm() const { return qvalue_.algorithm; }
113 
116  const std::vector<DQMChannel>& getBadChannels() const { return badChannels_; }
117 
118  void setBadChannels(std::vector<DQMChannel> badChannels) { badChannels_ = badChannels; }
119 
121 
122  private:
123  QValue qvalue_; //< Pointer to the actual data.
124  std::vector<DQMChannel> badChannels_; //< Bad channels from QCriterion.
125  };
126 
127  // These values are compatible to DQMNet, but DQMNet is not likely to exist
128  // in the future.
129  enum class Kind {
130  INVALID = 0x0,
131  INT = 0x1,
132  REAL = 0x2,
133  STRING = 0x3,
134  TH1F = 0x10,
135  TH1S = 0x11,
136  TH1D = 0x12,
137  TH2F = 0x20,
138  TH2S = 0x21,
139  TH2D = 0x22,
140  TH3F = 0x30,
141  TPROFILE = 0x40,
142  TPROFILE2D = 0x41
143  };
144 
145  // Which window of time the ME is supposed to cover.
146  // There is space for a granularity level between runs and lumisections,
147  // maybe blocks of 10LS or some fixed number of events or integrated
148  // luminosity. We also want to be able to change the granularity centrally
149  // depending on the use case. That is what the default is for, and it should
150  // be used unless some specific granularity is really required.
151  // We'll also need to switch the default to JOB for multi-run harvesting.
152  enum Scope { JOB = 1, RUN = 2, LUMI = 3 /*, BLOCK = 4 */ };
153 
154  // The main ME data. We don't keep references/QTest results, instead we use
155  // only the fields stored in DQMIO files.
156  struct Value {
159  std::vector<QReport> qreports_;
160  };
161 
162  struct Path {
163  private:
164  // We could use pointers to interned strings here to save some space.
167 
168  public:
169  enum class Type { DIR, DIR_AND_NAME };
170 
171  std::string const& getDirname() const { return dirname_; }
172  std::string const& getObjectname() const { return objname_; }
173  std::string getFullname() const { return dirname_ + objname_; }
174 
175  // Clean up the path and normalize it to preserve certain invariants.
176  // Instead of reasoning about whatever properties of paths, we just parse
177  // the thing and build a normalized instance with no slash in the beginning
178  // and a slash in the end.
179  // Type of string `path` could be just directory name, or
180  // directory name followed by the name of the monitor element
183  std::vector<std::string> buf;
184  static std::regex const dir("^/*([^/]+)");
185  std::smatch m;
186 
187  while (std::regex_search(in, m, dir)) {
188  if (m[1] == "..") {
189  if (!buf.empty()) {
190  buf.pop_back();
191  }
192  } else {
193  buf.push_back(m[1]);
194  }
195  in = m.suffix().str();
196  }
197 
198  // Construct dirname_ and object_name
199  dirname_ = "";
200  objname_ = "";
201  int numberOfItems = buf.size();
202  for (int i = 0; i < numberOfItems; i++) {
203  if (i == numberOfItems - 1) {
204  // Processing last component...
206  objname_ = buf[i];
207  } else if (type == Path::Type::DIR) {
208  dirname_ += buf[i] + "/";
209  }
210  } else {
211  dirname_ += buf[i] + "/";
212  }
213  }
214  }
215 
216  bool operator==(Path const& other) const {
217  return this->dirname_ == other.dirname_ && this->objname_ == other.objname_;
218  }
219  };
220 
221  // Metadata about the ME. The range is included here in case we have e.g.
222  // multiple per-lumi histograms in one collection. For a logical comparison,
223  // one should look only at the name.
224  struct Key {
226 
227  // Run number (and optionally lumi number) that the ME belongs to.
231 
232  bool operator<(Key const& other) const {
233  auto makeKeyTuple = [](Key const& k) {
234  return std::make_tuple(
235  k.path_.getDirname(), k.path_.getObjectname(), k.scope_, k.id_.run(), k.id_.luminosityBlock());
236  };
237 
238  return makeKeyTuple(*this) < makeKeyTuple(other);
239  }
240  };
241 
242  bool operator<(MonitorElementData const& other) const { return this->key_ < other.key_; }
243 
244  // The only non class/struct members
247 };
248 
249 // For now, no additional (meta-)data is needed apart from the MEs themselves.
250 // The framework will take care of tracking the plugin and LS/run that the MEs
251 // belong to.
252 // Unused for now.
254  std::vector<std::unique_ptr<const MonitorElementData>> data_;
255 
256 public:
257  void push_back(std::unique_ptr<const MonitorElementData> value) {
258  // enforce ordering
259  assert(data_.empty() || data_[data_.size() - 1] <= value);
260  data_.push_back(std::move(value));
261  }
262 
264 
265  auto begin() const { return data_.begin(); }
266 
267  auto end() const { return data_.end(); }
268 
269  bool mergeProduct(MonitorElementCollection const& product) {
270  // discussion: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuidePerRunAndPerLumiBlockData#Merging_Run_and_Luminosity_Block
271  assert(!"Not implemented yet.");
272  return false;
273  // Things to decide:
274  // - Should we allow merging collections of different sets of MEs? (probably not.) [0]
275  // - Should we assume the MEs to be ordered? (probably yes.)
276  // - How to handle incompatible MEs (different binning)? (fail hard.) [1]
277  // - Can multiple MEs with same (dirname, objname) exist? (probably yes.) [2]
278  // - Shall we modify the (immutable?) ROOT objects? (probably yes.)
279  //
280  // [0] Merging should increase the statistics, but not change the number of
281  // MEs, at least with the current workflows. It might be convenient to
282  // allow it, but for the beginning, it would only mask errors.
283  // [1] The DQM framework should guarantee same booking parameters as long
284  // as we stay within the Scope of the MEs.
285  // [2] To implement e.g. MEs covering blocks of 10LS, we'd store them in a
286  // run product, but have as many MEs with same name but different range as
287  // needed to perserve the wanted granularity. Merging then can merge or
288  // concatenate as possible/needed.
289  // Problem: We need to keep copies in memory until the end of run, even
290  // though we could save them to the output file as soon as it is clear that
291  // the nexe LS will not fall into the same block. Instead, we could drop
292  // them into the next lumi block we see; the semantics would be weird (the
293  // MEs in the lumi block don't actually correspond to the lumi block they
294  // are in) but the DQMIO output should be able to handle that.
295  }
296 };
297 
298 #endif
MonitorElementData::Path::dirname_
std::string dirname_
Definition: MonitorElementCollection.h:165
mps_fire.i
i
Definition: mps_fire.py:428
MonitorElementData::Scalar
Definition: MonitorElementCollection.h:45
MonitorElementData::LUMI
Definition: MonitorElementCollection.h:152
MonitorElementData::QReport::DQMChannel::getBinX
int getBinX()
Definition: MonitorElementCollection.h:72
MonitorElementData::Path::getFullname
std::string getFullname() const
Definition: MonitorElementCollection.h:173
MonitorElementData::Kind::INT
MonitorElementData::operator<
bool operator<(MonitorElementData const &other) const
Definition: MonitorElementCollection.h:242
MonitorElementData::Path::getObjectname
std::string const & getObjectname() const
Definition: MonitorElementCollection.h:172
propagate_const.h
MonitorElementData::Scalar::num
int64_t num
Definition: MonitorElementCollection.h:46
MonitorElementData::Kind::TH1S
MonitorElementData::Scalar::real
double real
Definition: MonitorElementCollection.h:47
MonitorElementData::Kind::TH1F
MonitorElementData::QReport::DQMChannel::getBinY
int getBinY()
Definition: MonitorElementCollection.h:73
MonitorElementData::Kind::STRING
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
cms::cuda::assert
assert(be >=bs)
MonitorElementData::QReport::badChannels_
std::vector< DQMChannel > badChannels_
Definition: MonitorElementCollection.h:124
MonitorElementData::QReport::QValue::qtresult
float qtresult
Definition: MonitorElementCollection.h:59
MonitorElementData::QReport::DQMChannel::getBinZ
int getBinZ()
Definition: MonitorElementCollection.h:74
MonitorElementCollection::mergeProduct
bool mergeProduct(MonitorElementCollection const &product)
Definition: MonitorElementCollection.h:269
MonitorElementData::QReport::setBadChannels
void setBadChannels(std::vector< DQMChannel > badChannels)
Definition: MonitorElementCollection.h:118
MonitorElementData::QReport::QValue
Definition: MonitorElementCollection.h:57
SiStripPI::rms
Definition: SiStripPayloadInspectorHelper.h:169
MonitorElementData::Key::operator<
bool operator<(Key const &other) const
Definition: MonitorElementCollection.h:232
MonitorElementData::key_
Key key_
Definition: MonitorElementCollection.h:245
LuminosityBlockID.h
MonitorElementData::Key::id_
edm::LuminosityBlockID id_
Definition: MonitorElementCollection.h:228
MonitorElementData::Kind::TH2D
MonitorElementData::QReport::DQMChannel::RMS
float RMS
Definition: MonitorElementCollection.h:69
MonitorElementData::QReport::QValue::algorithm
std::string algorithm
Definition: MonitorElementCollection.h:62
MonitorElementData::QReport::getAlgorithm
const std::string & getAlgorithm() const
get quality test algorithm
Definition: MonitorElementCollection.h:112
MonitorElementData::Kind::TH2F
MonitorElementData::Value::qreports_
std::vector< QReport > qreports_
Definition: MonitorElementCollection.h:159
MonitorElementCollection::swap
void swap(MonitorElementCollection &other)
Definition: MonitorElementCollection.h:263
edm::propagate_const
Definition: propagate_const.h:32
MonitorElementCollection::end
auto end() const
Definition: MonitorElementCollection.h:267
MonitorElementData::Path::Type::DIR_AND_NAME
MonitorElementData::Key
Definition: MonitorElementCollection.h:224
MonitorElementData::Path::getDirname
std::string const & getDirname() const
Definition: MonitorElementCollection.h:171
MonitorElementData::QReport::DQMChannel::getContents
float getContents()
Definition: MonitorElementCollection.h:75
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
MonitorElementData::Path::Type::DIR
MonitorElementData::Value::scalar_
Scalar scalar_
Definition: MonitorElementCollection.h:157
MonitorElementData::QReport::getQTresult
float getQTresult() const
get test result i.e. prob value
Definition: MonitorElementCollection.h:103
MonitorElementData::QReport::QReport
QReport(QValue value)
Definition: MonitorElementCollection.h:120
MonitorElementData::QReport::QValue::message
std::string message
Definition: MonitorElementCollection.h:60
MonitorElementData::Scope
Scope
Definition: MonitorElementCollection.h:152
MonitorElementData::QReport::getValue
QValue const & getValue() const
Definition: MonitorElementCollection.h:97
MonitorElementData::Path::Type
Type
Definition: MonitorElementCollection.h:169
trackingPlots.other
other
Definition: trackingPlots.py:1460
MonitorElementData::Path::objname_
std::string objname_
Definition: MonitorElementCollection.h:166
MonitorElementData::QReport::getBadChannels
const std::vector< DQMChannel > & getBadChannels() const
Definition: MonitorElementCollection.h:116
MonitorElementData::Key::kind_
Kind kind_
Definition: MonitorElementCollection.h:230
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::LuminosityBlockID
Definition: LuminosityBlockID.h:31
MonitorElementData::QReport::DQMChannel::DQMChannel
DQMChannel()
Definition: MonitorElementCollection.h:86
MonitorElementData::QReport::DQMChannel::content
float content
Definition: MonitorElementCollection.h:68
MonitorElementData::value_
Value value_
Definition: MonitorElementCollection.h:246
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MonitorElementData::QReport::QValue::code
int code
Definition: MonitorElementCollection.h:58
MonitorElementData::Key::path_
Path path_
Definition: MonitorElementCollection.h:225
MonitorElementData::QReport::DQMChannel::binz
int binz
Definition: MonitorElementCollection.h:67
MonitorElementData::Path::set
void set(std::string path, Path::Type type)
Definition: MonitorElementCollection.h:181
MonitorElementData::QReport::DQMChannel::getBin
int getBin()
Definition: MonitorElementCollection.h:71
MonitorElementCollection::begin
auto begin() const
Definition: MonitorElementCollection.h:265
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
MonitorElementData::QReport::DQMChannel::biny
int biny
Definition: MonitorElementCollection.h:66
MonitorElementData::Kind
Kind
Definition: MonitorElementCollection.h:129
recoMuon::in
Definition: RecoMuonEnumerators.h:6
MonitorElementData::JOB
Definition: MonitorElementCollection.h:152
MonitorElementData::QReport
Definition: MonitorElementCollection.h:55
MonitorElementData::Value
Definition: MonitorElementCollection.h:156
value
Definition: value.py:1
MonitorElementData::QReport::qvalue_
QValue qvalue_
Definition: MonitorElementCollection.h:123
MonitorElementData::QReport::getQRName
const std::string & getQRName() const
get name of quality test
Definition: MonitorElementCollection.h:109
MonitorElementData::Kind::TH1D
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
MonitorElementData::Key::scope_
Scope scope_
Definition: MonitorElementCollection.h:229
MonitorElementData::QReport::getStatus
int getStatus() const
get test status
Definition: MonitorElementCollection.h:100
MonitorElementData::Kind::TH2S
MonitorElementData::Value::object_
edm::propagate_const< std::unique_ptr< TH1 > > object_
Definition: MonitorElementCollection.h:158
eostools.move
def move(src, dest)
Definition: eostools.py:511
MonitorElementData::Path
Definition: MonitorElementCollection.h:162
MonitorElementData::Kind::TPROFILE2D
MonitorElementData::Kind::TH3F
MonitorElementData::Kind::INVALID
MonitorElementCollection
Definition: MonitorElementCollection.h:253
MonitorElementData::QReport::DQMChannel
Definition: MonitorElementCollection.h:64
relativeConstraints.value
value
Definition: relativeConstraints.py:53
MonitorElementData::QReport::getMessage
const std::string & getMessage() const
get message attached to test
Definition: MonitorElementCollection.h:106
MonitorElementCollection::data_
std::vector< std::unique_ptr< const MonitorElementData > > data_
Definition: MonitorElementCollection.h:254
MonitorElementData::Scalar::str
std::string str
Definition: MonitorElementCollection.h:48
MonitorElementData
Definition: MonitorElementCollection.h:43
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MonitorElementCollection::push_back
void push_back(std::unique_ptr< const MonitorElementData > value)
Definition: MonitorElementCollection.h:257
MonitorElementData::RUN
Definition: MonitorElementCollection.h:152
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
MonitorElementData::QReport::DQMChannel::getRMS
float getRMS()
Definition: MonitorElementCollection.h:76
MonitorElementData::Path::operator==
bool operator==(Path const &other) const
Definition: MonitorElementCollection.h:216
MonitorElementData::QReport::QValue::qtname
std::string qtname
Definition: MonitorElementCollection.h:61
MonitorElementData::Kind::TPROFILE
MonitorElementData::QReport::getValue
QValue & getValue()
access underlying value
Definition: MonitorElementCollection.h:96
MonitorElementData::QReport::DQMChannel::DQMChannel
DQMChannel(int bx, int by, int bz, float data, float rms)
Definition: MonitorElementCollection.h:78
MonitorElementData::Kind::REAL
MonitorElementData::QReport::DQMChannel::binx
int binx
Definition: MonitorElementCollection.h:65
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23