Skip to content

Commit

Permalink
Merge pull request #34966 from CMSTrackerDPG/fixTrackerMapsForRun3
Browse files Browse the repository at this point in the history
TkDQM: Fix tracker maps for run3
  • Loading branch information
cmsbuild authored Aug 30, 2021
2 parents 405b802 + 0f15cfc commit e5145fd
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 4 deletions.
9 changes: 6 additions & 3 deletions DQM/SiStripMonitorClient/plugins/SiStripOfflineDQM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

//Run Info
#include "CondFormats/RunInfo/interface/RunInfo.h"
#include "DQMServices/Core/interface/LegacyIOHelper.h"

#include <iostream>
#include <iomanip>
Expand Down Expand Up @@ -199,11 +200,13 @@ void SiStripOfflineDQM::endJob() {
}

bool SiStripOfflineDQM::openInputFile(DQMStore& dqm_store) {
if (inputFileName_.empty())
if (inputFileName_.empty()) {
return false;
}
edm::LogInfo("OpenFile") << "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
dqm_store.open(inputFileName_, false);
return true;
dqm::harvesting::DQMStore* temp = dynamic_cast<dqm::harvesting::DQMStore*>(&dqm_store);
LegacyIOHelper leo(temp);
return leo.open(inputFileName_);
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
3 changes: 3 additions & 0 deletions DQM/SiStripMonitorClient/src/SiStripTrackerMapCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ void SiStripTrackerMapCreator::createForOffline(const edm::ParameterSet& tkmapPs
<< " with range set to 0.0 - 1.0";
trackerMap_->save(true, 0.0, 1.0, map_type + namesuffix + ".svg");
trackerMap_->save(true, 0.0, 1.0, map_type + namesuffix + ".png", 4500, 2400);
// reset the map name to ResidualsMean to restore the
// correct behaviour for the summary file creation
map_type = "ResidualsMean";
} else {
edm::LogInfo("TkMapToBeSaved") << "Ready to save TkMap " << map_type << namesuffix << " with range set to "
<< tkMapMin_ << " - " << tkMapMax_;
Expand Down
4 changes: 4 additions & 0 deletions DQM/SiStripMonitorClient/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<bin name="testSiStripDQM_OfflineTkMap" file="TestDriver.cpp">
<flags TEST_RUNNER_ARGS="/bin/bash DQM/SiStripMonitorClient/test test_SiStripDQM_OfflineTkMap.sh"/>
<use name="FWCore/Utilities"/>
</bin>
2 changes: 2 additions & 0 deletions DQM/SiStripMonitorClient/test/TestDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "FWCore/Utilities/interface/TestHelper.h"
RUNTEST()
14 changes: 14 additions & 0 deletions DQM/SiStripMonitorClient/test/test_SiStripDQM_OfflineTkMap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
function die { echo $1: status $2; exit $2; }
GT=`echo ${@} | python3 -c 'import Configuration.AlCa.autoCond as AC;print(AC.autoCond["run3_data_prompt"])'`
RUN="319176"
DQMFILE="/store/group/comm_dqm/DQMGUI_data/Run2018/ZeroBias/R0003191xx/DQM_V0001_R000319176__ZeroBias__Run2018B-PromptReco-v2__DQMIO.root"
COMMMAND=`xrdfs cms-xrd-global.cern.ch locate $DQMFILE`
STATUS=$?
echo "xrdfs command status = "$STATUS
if [ $STATUS -eq 0 ]; then
echo "Using file ${DQMFILE} and run ${RUN}. Running in ${LOCAL_TEST_DIR}."
(cmsRun "${LOCAL_TEST_DIR}/SiStripDQM_OfflineTkMap_Template_cfg_DB.py" globalTag="$GT" runNumber="$RUN" dqmFile=" root://cms-xrd-global.cern.ch//$DQMFILE" detIdInfoFile="file.root") || die 'failed running SiStripDQM_OfflineTkMap_Template_cfg_DB.py' $?
else
die "SKIPPING test, file ${DQMFILE} not found" 0
fi
30 changes: 29 additions & 1 deletion DQMServices/Core/interface/LegacyIOHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DQMSERVICES_CORE_LEGACYIOHELPER_H

#include "DQMServices/Core/interface/DQMStore.h"
#include "TROOT.h"

// This class encapsulates the TDirectory based file format used for DQMGUI
// uploads and many other use cases.
Expand All @@ -16,8 +17,14 @@ class LegacyIOHelper {
// use internal type here since we call this from the DQMStore itself.
typedef dqm::implementation::DQMStore DQMStore;
typedef dqm::legacy::MonitorElement MonitorElement;
LegacyIOHelper(DQMStore* dqmstore) : dbe_(dqmstore){};

typedef dqm::harvesting::DQMStore HarvestedDQMStore;
typedef dqm::harvesting::MonitorElement HarvestedMonitorElement;

using MEMap = std::set<HarvestedMonitorElement*>;

LegacyIOHelper(DQMStore* dqmstore) : dbe_(dqmstore){};
LegacyIOHelper(HarvestedDQMStore* hdqmstore) : dbe_(hdqmstore){};
// Replace or append to `filename`, a TDirectory ROOT file. If a run number
// is passed, the paths are rewritten to the "Run Summary" format used by
// DQMGUI. The run number does not affect which MEs are saved; this code only
Expand All @@ -32,9 +39,30 @@ class LegacyIOHelper {
bool saveall = true,
std::string const& fileupdate = "RECREATE");

bool open(std::string const& filename, std::string const& path = "", uint32_t const run = 0);

private:
template <class T>
void getMEName(T* h, const std::string& toppath, std::string& meName) {
std::ostringstream fullpath;
fullpath << gDirectory->GetPath() << "/" << h->GetName();
std::string dirpath = fullpath.str();
// Search for the substring in string
size_t pos = dirpath.find(toppath);
if (pos != std::string::npos) {
dirpath.erase(pos, toppath.length());
}
std::string rsummary = "/Run summary";
pos = dirpath.find(rsummary);
if (pos != std::string::npos) {
dirpath.erase(pos, rsummary.length());
}
meName = dirpath;
}
bool readdir(TDirectory* dir, const std::string& toppath);
bool createDirectoryIfNeededAndCd(const std::string& path);
DQMStore* dbe_;
MEMap data_;
};

#endif
102 changes: 102 additions & 0 deletions DQMServices/Core/src/LegacyIOHelper.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "DQMServices/Core/interface/LegacyIOHelper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <cstdio>
#include <cfloat>
Expand All @@ -8,6 +9,7 @@
#include "TString.h"
#include "TSystem.h"
#include "TFile.h"
#include "TKey.h"
#include <sys/stat.h>

void LegacyIOHelper::save(std::string const &filename,
Expand Down Expand Up @@ -164,3 +166,103 @@ bool LegacyIOHelper::createDirectoryIfNeededAndCd(const std::string &path) {

return true;
}

bool LegacyIOHelper::readdir(TDirectory *dir, const std::string &toppath) {
TDirectory *dirsav = gDirectory;
LogDebug("LegacyIOHelper") << "Inside:" << gDirectory->GetPath() << std::endl;
TIter next(dir->GetListOfKeys());
TKey *key;
while ((key = (TKey *)next())) {
if (key->IsFolder()) {
LogDebug("LegacyIOHelper") << key->GetName() << std::endl;
dir->cd(key->GetName());
TDirectory *subdir = gDirectory;
readdir(subdir, toppath);
dirsav->cd();
continue;
} else {
TClass *cl = gROOT->GetClass(key->GetClassName());
std::string meName;
if (cl->InheritsFrom("TProfile")) {
TProfile *h = dynamic_cast<TProfile *>(key->ReadObject<TProfile>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TProfile>(h, toppath, meName);
data_.insert(dbe_->bookProfile(meName, h));
}
} else if (cl->InheritsFrom("TProfile2D")) {
TProfile2D *h = dynamic_cast<TProfile2D *>(key->ReadObject<TProfile2D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TProfile2D>(h, toppath, meName);
data_.insert(dbe_->bookProfile2D(meName, h));
}
} else if (cl->InheritsFrom("TH1F")) {
TH1F *h = dynamic_cast<TH1F *>(key->ReadObject<TH1F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1F>(h, toppath, meName);
data_.insert(dbe_->book1D(meName, h));
}
} else if (cl->InheritsFrom("TH1S")) {
TH1S *h = dynamic_cast<TH1S *>(key->ReadObject<TH1S>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1S>(h, toppath, meName);
data_.insert(dbe_->book1S(meName, h));
}
} else if (cl->InheritsFrom("TH1D")) {
TH1D *h = dynamic_cast<TH1D *>(key->ReadObject<TH1D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1D>(h, toppath, meName);
data_.insert(dbe_->book1DD(meName, h));
}
} else if (cl->InheritsFrom("TH2F")) {
TH2F *h = dynamic_cast<TH2F *>(key->ReadObject<TH2F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2F>(h, toppath, meName);
data_.insert(dbe_->book2D(meName, h));
}
} else if (cl->InheritsFrom("TH2S")) {
TH2S *h = dynamic_cast<TH2S *>(key->ReadObject<TH2S>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2S>(h, toppath, meName);
data_.insert(dbe_->book2S(meName, h));
}
} else if (cl->InheritsFrom("TH2D")) {
TH2D *h = dynamic_cast<TH2D *>(key->ReadObject<TH2D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2D>(h, toppath, meName);
data_.insert(dbe_->book2DD(meName, h));
}
} else if (cl->InheritsFrom("TH3F")) {
TH3F *h = dynamic_cast<TH3F *>(key->ReadObject<TH3F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH3F>(h, toppath, meName);
data_.insert(dbe_->book3D(meName, h));
}
}
}
}
if (!data_.empty())
return true;
return false;
}

bool LegacyIOHelper::open(std::string const &filename, std::string const &path, uint32_t const run) {
TFile *f1 = TFile::Open(filename.c_str());
if (!f1)
return false;
std::ostringstream toppath;
toppath << filename << ":/DQMData/Run " << run << "/";
std::string dirpath = toppath.str();
edm::LogPrint("LegacyIOHelper") << dirpath << std::endl;
bool flag = readdir(f1, dirpath);
f1->Close();
return flag;
}

0 comments on commit e5145fd

Please sign in to comment.