File indexing completed on 2025-03-10 23:53:31
0001 #ifndef DQMServices_Core_DQMStore_h
0002 #define DQMServices_Core_DQMStore_h
0003
0004 #include "DQMServices/Core/interface/MonitorElement.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006
0007 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0008
0009 #include <type_traits>
0010 #include <functional>
0011 #include <mutex>
0012
0013
0014 #define TRACE(msg) \
0015 std::cout << "TRACE: " << __FILE__ << ":" << __LINE__ << "(" << __FUNCTION__ << ") " << msg << std::endl;
0016 #define TRACE_ TRACE("");
0017
0018 namespace dqm {
0019 namespace implementation {
0020 using MonitorElement = dqm::legacy::MonitorElement;
0021 class DQMStore;
0022
0023
0024 class NavigatorBase {
0025 public:
0026 virtual void cd();
0027
0028 DQM_DEPRECATED
0029 virtual void cd(std::string const& dir);
0030
0031 virtual void setCurrentFolder(std::string const& fullpath);
0032 virtual void goUp();
0033
0034 virtual std::string pwd();
0035
0036 virtual ~NavigatorBase() {}
0037
0038 protected:
0039 NavigatorBase() {};
0040 std::string cwd_ = "";
0041 };
0042
0043 class IBooker : public dqm::implementation::NavigatorBase {
0044 public:
0045
0046 friend class DQMStore;
0047
0048
0049 struct NOOP {
0050 void operator()(TH1*) const {};
0051 void operator()() const {};
0052 };
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0073 MonitorElement* bookInt(TString const& name, FUNC onbooking = NOOP()) {
0074 return bookME(name, MonitorElementData::Kind::INT, [=]() {
0075 onbooking();
0076 return nullptr;
0077 });
0078 }
0079 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0080 MonitorElement* bookFloat(TString const& name, FUNC onbooking = NOOP()) {
0081 return bookME(name, MonitorElementData::Kind ::REAL, [=]() {
0082 onbooking();
0083 return nullptr;
0084 });
0085 }
0086 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0087 MonitorElement* bookString(TString const& name, TString const& value, FUNC onbooking = NOOP()) {
0088 std::string initial_value(value);
0089 auto me = bookME(name, MonitorElementData::Kind::STRING, [=]() {
0090 onbooking();
0091 return nullptr;
0092 });
0093 me->Fill(initial_value);
0094 return me;
0095 }
0096
0097 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0098 MonitorElement* book1D(TString const& name,
0099 TString const& title,
0100 int const nchX,
0101 double const lowX,
0102 double const highX,
0103 FUNC onbooking = NOOP()) {
0104 return bookME(name, MonitorElementData::Kind::TH1F, [=]() {
0105 auto th1 = new TH1F(name, title, nchX, lowX, highX);
0106 onbooking(th1);
0107 return th1;
0108 });
0109 }
0110 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0111 MonitorElement* book1D(
0112 TString const& name, TString const& title, int nchX, float const* xbinsize, FUNC onbooking = NOOP()) {
0113 return bookME(name, MonitorElementData::Kind::TH1F, [=]() {
0114 auto th1 = new TH1F(name, title, nchX, xbinsize);
0115 onbooking(th1);
0116 return th1;
0117 });
0118 }
0119 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0120 MonitorElement* book1D(TString const& name, TH1F* object, FUNC onbooking = NOOP()) {
0121 return bookME(
0122 name,
0123 MonitorElementData::Kind::TH1F,
0124 [=]() {
0125 auto th1 = static_cast<TH1F*>(object->Clone(name));
0126 onbooking(th1);
0127 return th1;
0128 },
0129 true);
0130 }
0131
0132 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0133 MonitorElement* book1S(
0134 TString const& name, TString const& title, int nchX, double lowX, double highX, FUNC onbooking = NOOP()) {
0135 return bookME(name, MonitorElementData::Kind::TH1S, [=]() {
0136 auto th1 = new TH1S(name, title, nchX, lowX, highX);
0137 onbooking(th1);
0138 return th1;
0139 });
0140 }
0141 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0142 MonitorElement* book1S(TString const& name, TH1S* object, FUNC onbooking = NOOP()) {
0143 return bookME(
0144 name,
0145 MonitorElementData::Kind::TH1S,
0146 [=]() {
0147 auto th1 = static_cast<TH1S*>(object->Clone(name));
0148 onbooking(th1);
0149 return th1;
0150 },
0151 true);
0152 }
0153
0154 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0155 MonitorElement* book1DD(
0156 TString const& name, TString const& title, int nchX, double lowX, double highX, FUNC onbooking = NOOP()) {
0157 return bookME(name, MonitorElementData::Kind::TH1D, [=]() {
0158 auto th1 = new TH1D(name, title, nchX, lowX, highX);
0159 onbooking(th1);
0160 return th1;
0161 });
0162 }
0163 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0164 MonitorElement* book1DD(
0165 TString const& name, TString const& title, int nchX, float const* xbinsize, FUNC onbooking = NOOP()) {
0166 return bookME(name, MonitorElementData::Kind::TH1D, [=]() {
0167 auto th1 = new TH1D(name, title, nchX, xbinsize);
0168 onbooking(th1);
0169 return th1;
0170 });
0171 }
0172 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0173 MonitorElement* book1DD(TString const& name, TH1D* object, FUNC onbooking = NOOP()) {
0174 return bookME(
0175 name,
0176 MonitorElementData::Kind::TH1D,
0177 [=]() {
0178 auto th1 = static_cast<TH1D*>(object->Clone(name));
0179 onbooking(th1);
0180 return th1;
0181 },
0182 true);
0183 }
0184
0185 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0186 MonitorElement* book1I(TString const& name,
0187 TString const& title,
0188 int const nchX,
0189 double const lowX,
0190 double const highX,
0191 FUNC onbooking = NOOP()) {
0192 return bookME(name, MonitorElementData::Kind::TH1I, [=]() {
0193 auto th1 = new TH1I(name, title, nchX, lowX, highX);
0194 onbooking(th1);
0195 return th1;
0196 });
0197 }
0198 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0199 MonitorElement* book1I(
0200 TString const& name, TString const& title, int nchX, float const* xbinsize, FUNC onbooking = NOOP()) {
0201 return bookME(name, MonitorElementData::Kind::TH1I, [=]() {
0202 auto th1 = new TH1I(name, title, nchX, xbinsize);
0203 onbooking(th1);
0204 return th1;
0205 });
0206 }
0207 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0208 MonitorElement* book1I(TString const& name, TH1I* object, FUNC onbooking = NOOP()) {
0209 return bookME(
0210 name,
0211 MonitorElementData::Kind::TH1I,
0212 [=]() {
0213 auto th1 = static_cast<TH1I*>(object->Clone(name));
0214 onbooking(th1);
0215 return th1;
0216 },
0217 true);
0218 }
0219
0220 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0221 MonitorElement* book2D(TString const& name,
0222 TString const& title,
0223 int nchX,
0224 double lowX,
0225 double highX,
0226 int nchY,
0227 double lowY,
0228 double highY,
0229 FUNC onbooking = NOOP()) {
0230 return bookME(name, MonitorElementData::Kind::TH2F, [=]() {
0231 auto th2 = new TH2F(name, title, nchX, lowX, highX, nchY, lowY, highY);
0232 onbooking(th2);
0233 return th2;
0234 });
0235 }
0236 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0237 MonitorElement* book2D(TString const& name,
0238 TString const& title,
0239 int nchX,
0240 float const* xbinsize,
0241 int nchY,
0242 float const* ybinsize,
0243 FUNC onbooking = NOOP()) {
0244 return bookME(name, MonitorElementData::Kind::TH2F, [=]() {
0245 auto th2 = new TH2F(name, title, nchX, xbinsize, nchY, ybinsize);
0246 onbooking(th2);
0247 return th2;
0248 });
0249 }
0250 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0251 MonitorElement* book2D(TString const& name, TH2F* object, FUNC onbooking = NOOP()) {
0252 return bookME(
0253 name,
0254 MonitorElementData::Kind::TH2F,
0255 [=]() {
0256 auto th2 = static_cast<TH2F*>(object->Clone(name));
0257 onbooking(th2);
0258 return th2;
0259 },
0260 true);
0261 }
0262 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0263 MonitorElement* book2DPoly(TString const& name,
0264 TString const& title,
0265 double lowX,
0266 double highX,
0267 double lowY,
0268 double highY,
0269 FUNC onbooking = NOOP()) {
0270 return bookME(name, MonitorElementData::Kind::TH2Poly, [=]() {
0271 auto th2poly = new TH2Poly(name, title, lowX, highX, lowY, highY);
0272 onbooking(th2poly);
0273 return th2poly;
0274 });
0275 }
0276 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0277 MonitorElement* book2DPoly(TString const& name, TH2Poly* object, FUNC onbooking = NOOP()) {
0278 return bookME(
0279 name,
0280 MonitorElementData::Kind::TH2Poly,
0281 [=]() {
0282 auto th2 = static_cast<TH2Poly*>(object->Clone(name));
0283 onbooking(th2);
0284 return th2;
0285 },
0286 true);
0287 }
0288 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0289 MonitorElement* book2S(TString const& name,
0290 TString const& title,
0291 int nchX,
0292 double lowX,
0293 double highX,
0294 int nchY,
0295 double lowY,
0296 double highY,
0297 FUNC onbooking = NOOP()) {
0298 return bookME(name, MonitorElementData::Kind::TH2S, [=]() {
0299 auto th2 = new TH2S(name, title, nchX, lowX, highX, nchY, lowY, highY);
0300 onbooking(th2);
0301 return th2;
0302 });
0303 }
0304 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0305 MonitorElement* book2S(TString const& name,
0306 TString const& title,
0307 int nchX,
0308 float const* xbinsize,
0309 int nchY,
0310 float const* ybinsize,
0311 FUNC onbooking = NOOP()) {
0312 return bookME(name, MonitorElementData::Kind::TH2S, [=]() {
0313 auto th2 = new TH2S(name, title, nchX, xbinsize, nchY, ybinsize);
0314 onbooking(th2);
0315 return th2;
0316 });
0317 }
0318 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0319 MonitorElement* book2S(TString const& name, TH2S* object, FUNC onbooking = NOOP()) {
0320 return bookME(
0321 name,
0322 MonitorElementData::Kind::TH2S,
0323 [=]() {
0324 auto th2 = static_cast<TH2S*>(object->Clone(name));
0325 onbooking(th2);
0326 return th2;
0327 },
0328 true);
0329 }
0330 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0331 MonitorElement* book2I(TString const& name,
0332 TString const& title,
0333 int nchX,
0334 double lowX,
0335 double highX,
0336 int nchY,
0337 double lowY,
0338 double highY,
0339 FUNC onbooking = NOOP()) {
0340 return bookME(name, MonitorElementData::Kind::TH2I, [=]() {
0341 auto th2 = new TH2I(name, title, nchX, lowX, highX, nchY, lowY, highY);
0342 onbooking(th2);
0343 return th2;
0344 });
0345 }
0346 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0347 MonitorElement* book2I(TString const& name,
0348 TString const& title,
0349 int nchX,
0350 float const* xbinsize,
0351 int nchY,
0352 float const* ybinsize,
0353 FUNC onbooking = NOOP()) {
0354 return bookME(name, MonitorElementData::Kind::TH2I, [=]() {
0355 auto th2 = new TH2I(name, title, nchX, xbinsize, nchY, ybinsize);
0356 onbooking(th2);
0357 return th2;
0358 });
0359 }
0360 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0361 MonitorElement* book2I(TString const& name, TH2I* object, FUNC onbooking = NOOP()) {
0362 return bookME(
0363 name,
0364 MonitorElementData::Kind::TH2I,
0365 [=]() {
0366 auto th2 = static_cast<TH2I*>(object->Clone(name));
0367 onbooking(th2);
0368 return th2;
0369 },
0370 true);
0371 }
0372 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0373 MonitorElement* book2DD(TString const& name,
0374 TString const& title,
0375 int nchX,
0376 double lowX,
0377 double highX,
0378 int nchY,
0379 double lowY,
0380 double highY,
0381 FUNC onbooking = NOOP()) {
0382 return bookME(name, MonitorElementData::Kind::TH2D, [=]() {
0383 auto th2 = new TH2D(name, title, nchX, lowX, highX, nchY, lowY, highY);
0384 onbooking(th2);
0385 return th2;
0386 });
0387 }
0388 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0389 MonitorElement* book2DD(TString const& name, TH2D* object, FUNC onbooking = NOOP()) {
0390 return bookME(
0391 name,
0392 MonitorElementData::Kind::TH2D,
0393 [=]() {
0394 auto th2 = static_cast<TH2D*>(object->Clone(name));
0395 onbooking(th2);
0396 return th2;
0397 },
0398 true);
0399 }
0400
0401 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0402 MonitorElement* book3D(TString const& name,
0403 TString const& title,
0404 int nchX,
0405 double lowX,
0406 double highX,
0407 int nchY,
0408 double lowY,
0409 double highY,
0410 int nchZ,
0411 double lowZ,
0412 double highZ,
0413 FUNC onbooking = NOOP()) {
0414 return bookME(name, MonitorElementData::Kind::TH3F, [=]() {
0415 auto th3 = new TH3F(name, title, nchX, lowX, highX, nchY, lowY, highY, nchZ, lowZ, highZ);
0416 onbooking(th3);
0417 return th3;
0418 });
0419 }
0420 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0421 MonitorElement* book3D(TString const& name, TH3F* object, FUNC onbooking = NOOP()) {
0422 return bookME(
0423 name,
0424 MonitorElementData::Kind::TH3F,
0425 [=]() {
0426 auto th3 = static_cast<TH3F*>(object->Clone(name));
0427 onbooking(th3);
0428 return th3;
0429 },
0430 true);
0431 }
0432
0433 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0434 MonitorElement* bookProfile(TString const& name,
0435 TString const& title,
0436 int nchX,
0437 double lowX,
0438 double highX,
0439 int ,
0440 double lowY,
0441 double highY,
0442 char const* option = "s",
0443 FUNC onbooking = NOOP()) {
0444 return bookME(name, MonitorElementData::Kind::TPROFILE, [=]() {
0445 auto tprofile = new TProfile(name, title, nchX, lowX, highX, lowY, highY, option);
0446 onbooking(tprofile);
0447 return tprofile;
0448 });
0449 }
0450 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0451 MonitorElement* bookProfile(TString const& name,
0452 TString const& title,
0453 int nchX,
0454 double lowX,
0455 double highX,
0456 double lowY,
0457 double highY,
0458 char const* option = "s",
0459 FUNC onbooking = NOOP()) {
0460 return bookME(name, MonitorElementData::Kind::TPROFILE, [=]() {
0461 auto tprofile = new TProfile(name, title, nchX, lowX, highX, lowY, highY, option);
0462 onbooking(tprofile);
0463 return tprofile;
0464 });
0465 }
0466 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0467 MonitorElement* bookProfile(TString const& name,
0468 TString const& title,
0469 int nchX,
0470 double const* xbinsize,
0471 int ,
0472 double lowY,
0473 double highY,
0474 char const* option = "s",
0475 FUNC onbooking = NOOP()) {
0476 return bookME(name, MonitorElementData::Kind::TPROFILE, [=]() {
0477 auto tprofile = new TProfile(name, title, nchX, xbinsize, lowY, highY, option);
0478 onbooking(tprofile);
0479 return tprofile;
0480 });
0481 }
0482 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0483 MonitorElement* bookProfile(TString const& name,
0484 TString const& title,
0485 int nchX,
0486 double const* xbinsize,
0487 double lowY,
0488 double highY,
0489 char const* option = "s",
0490 FUNC onbooking = NOOP()) {
0491 return bookME(name, MonitorElementData::Kind::TPROFILE, [=]() {
0492 auto tprofile = new TProfile(name, title, nchX, xbinsize, lowY, highY, option);
0493 onbooking(tprofile);
0494 return tprofile;
0495 });
0496 }
0497 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0498 MonitorElement* bookProfile(TString const& name, TProfile* object, FUNC onbooking = NOOP()) {
0499 return bookME(
0500 name,
0501 MonitorElementData::Kind::TPROFILE,
0502 [=]() {
0503 auto tprofile = static_cast<TProfile*>(object->Clone(name));
0504 onbooking(tprofile);
0505 return tprofile;
0506 },
0507 true);
0508 }
0509
0510 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0511 MonitorElement* bookProfile2D(TString const& name,
0512 TString const& title,
0513 int nchX,
0514 double lowX,
0515 double highX,
0516 int nchY,
0517 double lowY,
0518 double highY,
0519 double lowZ,
0520 double highZ,
0521 char const* option = "s",
0522 FUNC onbooking = NOOP()) {
0523 return bookME(name, MonitorElementData::Kind::TPROFILE2D, [=]() {
0524 auto tprofile = new TProfile2D(name, title, nchX, lowX, highX, nchY, lowY, highY, lowZ, highZ, option);
0525 onbooking(tprofile);
0526 return tprofile;
0527 });
0528 }
0529 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0530 MonitorElement* bookProfile2D(TString const& name,
0531 TString const& title,
0532 int nchX,
0533 double lowX,
0534 double highX,
0535 int nchY,
0536 double lowY,
0537 double highY,
0538 int ,
0539 double lowZ,
0540 double highZ,
0541 char const* option = "s",
0542 FUNC onbooking = NOOP()) {
0543 return bookME(name, MonitorElementData::Kind::TPROFILE2D, [=]() {
0544 auto tprofile = new TProfile2D(name, title, nchX, lowX, highX, nchY, lowY, highY, lowZ, highZ, option);
0545 onbooking(tprofile);
0546 return tprofile;
0547 });
0548 }
0549 template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
0550 MonitorElement* bookProfile2D(TString const& name, TProfile2D* object, FUNC onbooking = NOOP()) {
0551 return bookME(
0552 name,
0553 MonitorElementData::Kind::TPROFILE2D,
0554 [=]() {
0555 auto tprofile = static_cast<TProfile2D*>(object->Clone(name));
0556 onbooking(tprofile);
0557 return tprofile;
0558 },
0559 true);
0560 }
0561
0562
0563
0564
0565
0566 virtual MonitorElementData::Scope setScope(MonitorElementData::Scope newscope);
0567
0568 template <MonitorElementData::Scope SCOPE>
0569 struct UseScope {
0570 IBooker& parent;
0571 MonitorElementData::Scope oldscope;
0572 UseScope(IBooker& booker) : parent(booker) { oldscope = parent.setScope(SCOPE); }
0573 ~UseScope() { parent.setScope(oldscope); }
0574 };
0575 using UseLumiScope = UseScope<MonitorElementData::Scope::LUMI>;
0576 using UseRunScope = UseScope<MonitorElementData::Scope::RUN>;
0577 using UseJobScope = UseScope<MonitorElementData::Scope::JOB>;
0578
0579 ~IBooker() override;
0580
0581 private:
0582 IBooker(DQMStore* store);
0583 virtual uint64_t setModuleID(uint64_t moduleID);
0584 virtual edm::LuminosityBlockID setRunLumi(edm::LuminosityBlockID runlumi);
0585 virtual MonitorElement* bookME(TString const& name,
0586 MonitorElementData::Kind kind,
0587 std::function<TH1*()> makeobject,
0588 bool forceReplace = false);
0589
0590 DQMStore* store_ = nullptr;
0591 MonitorElementData::Scope scope_ = MonitorElementData::Scope::JOB;
0592 static constexpr uint64_t kInvalidModuleID = std::numeric_limits<uint64_t>::max();
0593 uint64_t moduleID_ = kInvalidModuleID;
0594 edm::LuminosityBlockID runlumi_ = edm::LuminosityBlockID();
0595 };
0596
0597 class IGetter : public dqm::implementation::NavigatorBase {
0598 public:
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611 virtual std::vector<dqm::harvesting::MonitorElement*> getContents(std::string const& path) const;
0612
0613
0614
0615 virtual std::vector<dqm::harvesting::MonitorElement*> getAllContents(std::string const& path) const;
0616 DQM_DEPRECATED
0617 virtual std::vector<dqm::harvesting::MonitorElement*> getAllContents(std::string const& path,
0618 uint32_t runNumber,
0619 uint32_t lumi) const;
0620
0621
0622 virtual MonitorElement* get(std::string const& fullpath) const;
0623
0624
0625
0626 virtual MonitorElement* get(MonitorElementData::Key const& key) const;
0627
0628
0629
0630 DQM_DEPRECATED
0631 virtual MonitorElement* getElement(std::string const& path) const;
0632
0633
0634
0635
0636 DQM_DEPRECATED
0637 virtual std::vector<std::string> getSubdirs() const;
0638
0639 virtual std::vector<std::string> getMEs() const;
0640
0641 virtual bool dirExists(std::string const& path) const;
0642
0643 ~IGetter() override;
0644
0645 protected:
0646 IGetter(DQMStore* store);
0647
0648 DQMStore* store_;
0649 };
0650
0651 class DQMStore : public IGetter, public IBooker {
0652 public:
0653
0654 friend IGetter;
0655 enum OpenRunDirs { KeepRunDirs, StripRunDirs };
0656
0657 DQMStore(edm::ParameterSet const& pset, edm::ActivityRegistry&);
0658 DQMStore(DQMStore const&) = delete;
0659 DQMStore(DQMStore&&) = delete;
0660 DQMStore& operator=(DQMStore const&) = delete;
0661 ~DQMStore() override;
0662
0663
0664
0665 DQM_DEPRECATED
0666 void save(std::string const& filename, std::string const& path = "");
0667 DQM_DEPRECATED
0668 bool open(std::string const& filename,
0669 bool overwrite = false,
0670 std::string const& path = "",
0671 std::string const& prepend = "",
0672 OpenRunDirs stripdirs = KeepRunDirs,
0673 bool fileMustExist = true);
0674
0675
0676
0677 void cd() override { this->IBooker::cd(); }
0678 void cd(std::string const& dir) override { this->IBooker::cd(dir); }
0679 void goUp() override { this->IBooker::goUp(); }
0680 std::string pwd() override { return this->IBooker::pwd(); }
0681
0682 void setCurrentFolder(std::string const& fullpath) override {
0683
0684 this->IBooker::setCurrentFolder(fullpath);
0685 this->IGetter::setCurrentFolder(fullpath);
0686 }
0687
0688 public:
0689
0690 template <typename iFunc>
0691 void bookTransaction(iFunc f, uint64_t moduleId, bool canSaveByLumi) {
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704 auto lock = std::scoped_lock(this->booking_mutex_);
0705
0706
0707
0708
0709
0710 struct ModuleIdScope {
0711 IBooker& booker_;
0712 uint64_t oldid_;
0713 MonitorElementData::Scope oldscope_;
0714 edm::LuminosityBlockID oldrunlumi_;
0715 ModuleIdScope(IBooker& booker,
0716 uint64_t newid,
0717 MonitorElementData::Scope newscope,
0718 edm::LuminosityBlockID newrunlumi)
0719 : booker_(booker) {
0720 oldid_ = booker_.setModuleID(newid);
0721 oldscope_ = booker_.setScope(newscope);
0722 oldrunlumi_ = booker_.setRunLumi(newrunlumi);
0723 assert(newid != kInvalidModuleID || !"moduleID must be set for normal booking transaction");
0724 assert(oldid_ == kInvalidModuleID || !"Nested booking transaction?");
0725 }
0726 ~ModuleIdScope() {
0727 booker_.setModuleID(oldid_);
0728 booker_.setScope(oldscope_);
0729 booker_.setRunLumi(oldrunlumi_);
0730 }
0731 };
0732
0733 ModuleIdScope booker(
0734 *this,
0735 moduleId,
0736
0737 canSaveByLumi && this->doSaveByLumi_ ? MonitorElementData::Scope::LUMI : MonitorElementData::Scope::RUN,
0738
0739 edm::LuminosityBlockID());
0740
0741 f(booker.booker_);
0742 };
0743
0744 template <typename iFunc>
0745 void meBookerGetter(iFunc f) {
0746 auto lock = std::scoped_lock(this->booking_mutex_);
0747
0748
0749 f(*this, *this);
0750
0751
0752
0753 };
0754
0755
0756 MonitorElement* findOrRecycle(MonitorElementData::Key const&);
0757
0758
0759
0760
0761
0762 void initLumi(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi);
0763 void initLumi(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, uint64_t moduleID);
0764
0765
0766
0767
0768 void enterLumi(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, uint64_t moduleID);
0769 void leaveLumi(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, uint64_t moduleID);
0770
0771
0772
0773
0774 void cleanupLumi(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi);
0775
0776
0777
0778
0779 MonitorElement* putME(MonitorElement* me);
0780
0781 MonitorElement* putME(MonitorElement* me, uint64_t moduleID);
0782
0783
0784 template <typename MELIKE>
0785 MonitorElement* findME(MELIKE const& path);
0786
0787 void printTrace(std::string const& message);
0788
0789 void debugTrackME(const char* message, MonitorElement* me_local, MonitorElement* me_global) const;
0790
0791 const auto& getMEsToSave() const { return MEsToSave_; }
0792
0793 const bool& getMode() const { return onlineMode_; }
0794
0795 private:
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815 std::map<edm::LuminosityBlockID, std::set<MonitorElement*, MonitorElement::MEComparison>> globalMEs_;
0816
0817
0818
0819 std::map<uint64_t, std::set<MonitorElement*, MonitorElement::MEComparison>> localMEs_;
0820
0821
0822
0823 std::recursive_mutex booking_mutex_;
0824
0825
0826
0827 int verbose_;
0828
0829
0830
0831 bool assertLegacySafe_;
0832
0833
0834 bool doSaveByLumi_;
0835
0836 std::vector<std::string> MEsToSave_;
0837
0838
0839
0840 std::string trackME_;
0841
0842
0843 bool onlineMode_;
0844 };
0845 }
0846
0847
0848 namespace legacy {
0849 class DQMStore : public dqm::implementation::DQMStore {
0850 public:
0851 using IBooker = dqm::implementation::IBooker;
0852 using IGetter = dqm::implementation::IGetter;
0853
0854 using dqm::implementation::DQMStore::DQMStore;
0855 };
0856 }
0857 namespace reco {
0858 using DQMStore = dqm::legacy::DQMStore;
0859 }
0860 namespace harvesting {
0861 using DQMStore = dqm::legacy::DQMStore;
0862 }
0863 }
0864
0865 #endif