Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0.X] DQMEventInfo: add the possibility to register the GlobalTag name in a MonitorElement #45282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions DQMOffline/Trigger/python/DQMOffline_Trigger_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@

import DQMServices.Components.DQMEnvironment_cfi
dqmEnvHLT = DQMServices.Components.DQMEnvironment_cfi.dqmEnv.clone(
subSystemFolder = 'HLT'
)
subSystemFolder = 'HLT',
showHLTGlobalTag = True)

from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
dqmInfoHLTMon = DQMEDAnalyzer('DQMEventInfo',
subSystemFolder = cms.untracked.string('HLT')
)
subSystemFolder = cms.untracked.string('HLT'),
showHLTGlobalTag = cms.untracked.bool(True))
###################################################################################################
#### SEQUENCES TO BE RUN depending on the input DATAFORMAT
## on MiniAOD
Expand Down
88 changes: 85 additions & 3 deletions DQMServices/Components/plugins/DQMEventInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*
*/
#include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Version/interface/GetReleaseVersion.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Version/interface/GetReleaseVersion.h"

#include <algorithm>
#include <iostream>
Expand All @@ -37,12 +39,19 @@ class DQMEventInfo : public DQMOneEDAnalyzer<> {
/// Destructor
~DQMEventInfo() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

protected:
/// Analyze
void analyze(const edm::Event& e, const edm::EventSetup& c) override;
void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
void analyzeProvInfo(const edm::Event& e);

private:
std::string globalTag_;
bool globalTagRetrieved_;
bool showHLTGlobalTag_;

std::string eventInfoFolder_;
std::string subsystemname_;

Expand Down Expand Up @@ -76,6 +85,7 @@ class DQMEventInfo : public DQMOneEDAnalyzer<> {
MonitorElement* processName_; ///DQM "name" of the job (eg, Hcal or DT)
MonitorElement* workingDir_; ///Current working directory of the job
MonitorElement* cmsswVer_; ///CMSSW version run for this job
MonitorElement* versGlobaltag_; ///GlobalTag name
MonitorElement* dqmPatch_; ///DQM patch version for this job
MonitorElement* errSummary_; ///Subdetector-specific error summary (float)
MonitorElement* errSummaryEtaPhi_; ///Subdetector-specific etaPhi summary (float)
Expand All @@ -97,13 +107,18 @@ DQMEventInfo::DQMEventInfo(const edm::ParameterSet& ps) {
lastAvgTime_ = currentTime_ = stampToReal(now);

// read config parms
showHLTGlobalTag_ = ps.getUntrackedParameter<bool>("showHLTGlobalTag", false);
std::string folder = ps.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo");
subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");

eventInfoFolder_ = subsystemname_ + "/" + folder;
evtRateWindow_ = ps.getUntrackedParameter<double>("eventRateWindow", 0.5);
if (evtRateWindow_ <= 0.15)
evtRateWindow_ = 0.15;

// Initialization of the global tag
globalTag_ = "MODULE::DEFAULT"; // default
globalTagRetrieved_ = false; // set as soon as retrieved from first event
}

void DQMEventInfo::bookHistograms(DQMStore::IBooker& ibooker,
Expand Down Expand Up @@ -150,6 +165,9 @@ void DQMEventInfo::bookHistograms(DQMStore::IBooker& ibooker,
free(pwd);
cmsswVer_ = ibooker.bookString("CMSSW_Version", edm::getReleaseVersion());

// Element: Globaltag
versGlobaltag_ = ibooker.bookString("Globaltag", globalTag_);

// Folder to be populated by sub-systems' code
std::string subfolder = eventInfoFolder_ + "/reportSummaryContents";
ibooker.setCurrentFolder(subfolder);
Expand Down Expand Up @@ -207,8 +225,72 @@ void DQMEventInfo::analyze(const edm::Event& e, const edm::EventSetup& c) {
lastAvgTime_ = currentTime_;
}

analyzeProvInfo(e);

return;
}

void DQMEventInfo::analyzeProvInfo(const edm::Event& event) {
// Only trying to retrieve the global tag for the first event we ever
// encounter.
if (!globalTagRetrieved_) {
// Initialize processName to an empty string
std::string processName;

if (showHLTGlobalTag_) {
// Getting all process names
std::vector<std::string> pnames;
for (const auto& p : event.processHistory()) {
pnames.push_back(p.processName());
}

// Iterate through the process names in reverse to find the last one that contains "HLT"
for (auto it = pnames.rbegin(); it != pnames.rend(); ++it) {
if (it->find("HLT") != std::string::npos) {
processName = *it;
break; // Exit the loop once the last matching process name is found
}
}

// Print the process name containing "HLT"
if (processName.empty()) {
edm::LogError("DQMEventInfo") << "Could not find any processName containing 'HLT' even if 'showHLTGlobalTag' "
"was chosen.\n Falling back to current processing!"
<< std::endl;
processName = event.processHistory()[event.processHistory().size() - 1].processName();
}
} else {
processName = event.processHistory()[event.processHistory().size() - 1].processName();
}

// Getting parameters for that process
edm::ParameterSet ps;
event.getProcessParameterSet(processName, ps);

// Check if the 'PoolDBESSource@GlobalTag' ParameterSet exists
if (ps.exists("PoolDBESSource@GlobalTag")) {
// Getting the global tag
globalTag_ = ps.getParameterSet("PoolDBESSource@GlobalTag").getParameter<std::string>("globaltag");
} else {
// Handle the case where 'PoolDBESSource@GlobalTag' is missing
// You can set a default value or take some other action
edm::LogInfo("Configuration") << "ParameterSet 'PoolDBESSource@GlobalTag' not found. Using default global tag.";
}

versGlobaltag_->Fill(globalTag_);
// Finaly: Setting globalTagRetrieved_ to true, since we got it now
globalTagRetrieved_ = true;
}
}

void DQMEventInfo::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.addUntracked<bool>("showHLTGlobalTag", false);
desc.addUntracked<std::string>("eventInfoFolder", "EventInfo");
desc.addUntracked<std::string>("subSystemFolder", "YourSubsystem");
desc.addUntracked<double>("eventRateWindow", 0.5);
descriptions.addWithDefaultLabel(desc);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(DQMEventInfo);
4 changes: 3 additions & 1 deletion DQMServices/Components/python/DQMEventInfo_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# set the window for eventrate calculation (in minutes)
eventRateWindow = cms.untracked.double(0.5),
# define folder to store event info (default: EventInfo)
eventInfoFolder = cms.untracked.string('EventInfo')
eventInfoFolder = cms.untracked.string('EventInfo'),
# use the Global Tag of the last (!) HLT processing
showHLTGlobalTag = cms.untracked.bool(False)
)