From 6f551f5e9b2930b3450677c49eb3c1cb7296a29a Mon Sep 17 00:00:00 2001 From: mmusich Date: Tue, 28 Sep 2021 12:19:58 +0200 Subject: [PATCH] update BeamSpotOnline payload inspector to include parameters added in #35338 --- .../BeamSpotPayloadInspectorHelper.h | 39 ++++-- .../BeamSpotOnline_PayloadInspector.cc | 126 +++++++++++++++--- 2 files changed, 136 insertions(+), 29 deletions(-) diff --git a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h index a0d992f6ee90e..2fb7fa5c644bf 100644 --- a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h +++ b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h @@ -28,20 +28,31 @@ namespace BeamSpotPI { } enum parameters { - X, - Y, - Z, - sigmaX, - sigmaY, - sigmaZ, - dxdz, - dydz, - lastLumi, - lastRun, - lastFill, - nTracks, - nPVs, - creationTime, + X, // 1 regular BS methods + Y, // 2 + Z, // 3 + sigmaX, // 4 + sigmaY, // 5 + sigmaZ, // 6 + dxdz, // 7 + dydz, // 8 + lastLumi, // 9 additional int's + lastRun, // 10 + lastFill, // 11 + nTracks, // 12 + nPVs, // 13 + nUsedEvents, // 14 + maxPVs, // 15 + meanPV, // 16 additional float's + meanErrorPV, // 17 + rmsPV, // 18 + rmsErrorPV, // 19 + creationTime, // 20 additional cond::Time_t + startTimeStamp, // 21 + endTimeStamp, // 22 + startTime, // 23 additional std::string + endTime, // 24 + lumiRange, // 25 END_OF_TYPES }; diff --git a/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc b/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc index 6a5a087f2b0a0..ff83562484d0f 100644 --- a/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc +++ b/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc @@ -62,11 +62,12 @@ namespace { public: std::shared_ptr fillTheExtraHistogram() const override { gStyle->SetHistMinimumZero(); - auto h2_ExtraBSParameters = std::make_shared("ExtraParameters", "", 1, 0.0, 1.0, 6, 0, 6.); + auto h2_ExtraBSParameters = std::make_shared("ExtraParameters", "", 1, 0.0, 1.0, 14, 0, 14.); h2_ExtraBSParameters->SetStats(false); - std::function mycutFunctor = [this](parameters my_param) { - int ret(-999.); + //_____________________________________________________________________________ + std::function myIntFunctor = [this](parameters my_param) { + int ret(-999); switch (my_param) { case lastLumi: return this->m_payload->GetLastAnalyzedLumi(); @@ -78,28 +79,85 @@ namespace { return this->m_payload->GetNumTracks(); case nPVs: return this->m_payload->GetNumPVs(); - case END_OF_TYPES: + case nUsedEvents: + return this->m_payload->GetUsedEvents(); + case maxPVs: + return this->m_payload->GetMaxPVs(); + default: + return ret; + } + }; + + //_____________________________________________________________________________ + std::function myFloatFunctor = [this](parameters my_param) { + float ret(-999.); + switch (my_param) { + case meanPV: + return this->m_payload->GetMeanPV(); + case meanErrorPV: + return this->m_payload->GetMeanErrorPV(); + case rmsPV: + return this->m_payload->GetRmsPV(); + case rmsErrorPV: + return this->m_payload->GetRmsErrorPV(); + default: return ret; + } + }; + + //_____________________________________________________________________________ + std::function myStringFunctor = [this](parameters my_param) { + std::string ret(""); + switch (my_param) { + case startTime: + return this->m_payload->GetStartTime(); + case endTime: + return this->m_payload->GetEndTime(); + case lumiRange: + return this->m_payload->GetLumiRange(); default: return ret; } }; - unsigned int yBin = 6; - for (int foo = parameters::lastLumi; foo != parameters::END_OF_TYPES; foo++) { + //_____________________________________________________________________________ + std::function myTimeFunctor = [this](parameters my_param) { + cond::Time_t ret(1); + switch (my_param) { + case creationTime: + return this->m_payload->GetCreationTime(); + case startTimeStamp: + return this->m_payload->GetStartTimeStamp(); + case endTimeStamp: + return this->m_payload->GetEndTimeStamp(); + default: + return ret; + } + }; + + unsigned int yBin = 14; + for (int foo = parameters::lastLumi; foo != parameters::startTime; foo++) { parameters param = static_cast(foo); std::string theLabel = this->getStringFromTypeEnum(param); h2_ExtraBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str()); - edm::LogInfo("BeamSpotOnline_PayloadInspector") - << theLabel.c_str() << " : " << mycutFunctor(param) << std::endl; - - if (param == BeamSpotPI::creationTime) { - h2_ExtraBSParameters->SetBinContent(1, yBin, m_payload->GetCreationTime()); - } else { - h2_ExtraBSParameters->SetBinContent(1, yBin, mycutFunctor(param)); + if (foo <= parameters::maxPVs) { + const auto output = try_(std::bind(myIntFunctor, param), print_error); + edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl; + h2_ExtraBSParameters->SetBinContent(1, yBin, output); + } else if (foo <= parameters::rmsErrorPV) { + const auto output = try_(std::bind(myFloatFunctor, param), print_error); + edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl; + h2_ExtraBSParameters->SetBinContent(1, yBin, output); + } else if (foo <= parameters::endTimeStamp) { + const auto output = try_(std::bind(myTimeFunctor, param), print_error); + edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl; + h2_ExtraBSParameters->SetBinContent(1, yBin, output); + //} else if( foo <=parameters::lumiRange){ + // const auto output = try_(std::bind(myStringFunctor, param), print_error); + //edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl; + //h2_ExtraBSParameters->SetBinContent(1, yBin, output); } - yBin--; } @@ -141,12 +199,50 @@ namespace { return "# tracks"; case nPVs: return "# PVs"; + case nUsedEvents: + return "# events"; + case maxPVs: + return "max PVs"; + case meanPV: + return "#LT # PV #GT"; + case meanErrorPV: + return "#LT PV error #GT [cm]"; + case rmsPV: + return "rms PV [cm]"; + case rmsErrorPV: + return "rms PV error [cm]"; case creationTime: - return "time"; + return "creation time"; + case startTimeStamp: + return "start timestamp"; + case endTimeStamp: + return "end timestamp"; + case startTime: + return "startTime"; + case endTime: + return "endTime"; + case lumiRange: + return "lumiRange"; default: return "should never be here"; } } + + //slightly better error handler + static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; } + + // method to catch exceptions + template + T try_(Func f, Response r) const { + try { + std::cout << "I have tried" << std::endl; + return f(); + } catch (Except& e) { + std::cout << "I have caught!" << std::endl; + r(e); + return static_cast(-999); + } + } }; } // namespace