Skip to content

Commit

Permalink
Merge pull request #29169 from alja/geo-gt
Browse files Browse the repository at this point in the history
Fireworks: Auto detect geometry version from global tag.
  • Loading branch information
cmsbuild committed Apr 6, 2020
2 parents 93821d3 + e34e581 commit 0d3828c
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Fireworks/Core/interface/CmsShowNavigator.h
Expand Up @@ -111,6 +111,8 @@ class CmsShowNavigator : public FWNavigatorBase {

const char* frameTitle();
const char* filterStatusMessage();
std::string getCurrentGlobalTag();

int getNSelectedEvents() override;
int getNTotalEvents() override;
bool canEditFiltersExternally();
Expand Down
6 changes: 3 additions & 3 deletions Fireworks/Core/interface/Context.h
Expand Up @@ -47,7 +47,7 @@ namespace fireworks {
FWJobMetadataManager* iJMDM);
virtual ~Context();

void setGeom(const FWGeometry* x) { m_geom = x; }
void setGeom(FWGeometry* x) { m_geom = x; }

// ---------- const member functions ---------------------
FWModelChangeManager* modelChangeManager() const { return m_changeManager; }
Expand All @@ -69,7 +69,7 @@ namespace fireworks {
TEveCaloDataHist* getCaloData() const { return m_caloData; }
TEveCaloDataVec* getCaloDataHF() const { return m_caloDataHF; }

const FWGeometry* getGeom() const { return m_geom; }
FWGeometry* getGeom() const { return m_geom; }

CmsShowCommon* commonPrefs() const;

Expand Down Expand Up @@ -109,7 +109,7 @@ namespace fireworks {
FWColorManager* m_colorManager;
FWJobMetadataManager* m_metadataManager;

const FWGeometry* m_geom;
FWGeometry* m_geom;

TEveTrackPropagator* m_propagator;
TEveTrackPropagator* m_trackerPropagator;
Expand Down
7 changes: 5 additions & 2 deletions Fireworks/Core/interface/FWFileEntry.h
Expand Up @@ -46,7 +46,7 @@ class FWFileEntry {
bool hasSelectedEvents() { return m_eventList && m_eventList->GetN(); }
};

FWFileEntry(const std::string& name, bool checkVersion);
FWFileEntry(const std::string& name, bool checkVersion, bool checkGlobalTag);
virtual ~FWFileEntry();

TFile* file() { return m_file; }
Expand All @@ -57,7 +57,9 @@ class FWFileEntry {

std::list<Filter*>& filters() { return m_filterEntries; }

void openFile(bool);
const std::string& getGlobalTag() const { return m_globalTag; }

void openFile(bool, bool);
void closeFile();

bool isEventSelected(int event);
Expand Down Expand Up @@ -96,6 +98,7 @@ class FWFileEntry {
fwlite::Event* m_event;

bool m_needUpdate; // To be set in navigator::filterChanged/Added, newFile
std::string m_globalTag;

std::list<Filter*> m_filterEntries;
FWTEventList* m_globalEventList;
Expand Down
6 changes: 6 additions & 0 deletions Fireworks/Core/interface/FWGeometry.h
Expand Up @@ -155,6 +155,10 @@ class FWGeometry {

const TrackerTopology* getTrackerTopology() const { return m_trackerTopology.get(); }

void applyGlobalTag(const std::string& gt);

bool isEmpty() const;

private:
mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;

Expand All @@ -166,6 +170,8 @@ class FWGeometry {

int m_producerVersion;

std::string m_fileName;

std::unique_ptr<TrackerTopology> m_trackerTopology;
};

Expand Down
18 changes: 11 additions & 7 deletions Fireworks/Core/src/CmsShowMain.cc
Expand Up @@ -134,7 +134,8 @@ CmsShowMain::CmsShowMain(int argc, char* argv[])
m_liveTimer(new SignalTimer()),
m_liveTimeout(600000),
m_lastXEventSerial(0),
m_noVersionCheck(false) {
m_noVersionCheck(false),
m_globalTagCheck(true) {
try {
TGLWidget* w = TGLWidget::Create(gClient->GetDefaultRoot(), kTRUE, kTRUE, nullptr, 10, 10);
delete w;
Expand Down Expand Up @@ -296,11 +297,9 @@ CmsShowMain::CmsShowMain(int argc, char* argv[])

// geometry
if (vm.count(kGeomFileOpt)) {
m_globalTagCheck = false;
setGeometryFilename(vm[kGeomFileOpt].as<std::string>());
fwLog(fwlog::kInfo) << "Geometry file " << geometryFilename() << "\n";
} else {
// fwLog(fwlog::kInfo) << "No geom file name. Choosing default.\n";
setGeometryFilename("cmsGeom10.root");
}

if (vm.count(kSimGeomFileOpt)) {
Expand Down Expand Up @@ -356,9 +355,10 @@ CmsShowMain::CmsShowMain(int argc, char* argv[])
f = boost::bind(&CmsShowMain::setupSocket, this, vm[kPortCommandOpt].as<unsigned int>());
startupTasks()->addTask(f);
}

f = boost::bind(&CmsShowMainBase::loadGeometry, this);
startupTasks()->addTask(f);
if (!geometryFilename().empty()) {
f = boost::bind(&CmsShowMainBase::loadGeometry, this);
startupTasks()->addTask(f);
}
f = boost::bind(&CmsShowMainBase::setupViewManagers, this);
startupTasks()->addTask(f);

Expand Down Expand Up @@ -495,6 +495,10 @@ void CmsShowMain::fileChangedSlot(const TFile* file) {
if (context()->getField()->getSource() == FWMagField::kNone) {
context()->getField()->resetFieldEstimate();
}
if (geometryFilename().empty()) {
std::string gt = m_navigator->getCurrentGlobalTag();
fireworks::Context::getInstance()->getGeom()->applyGlobalTag(gt);
}
m_metadataManager->update(new FWLiteJobMetadataUpdateRequest(getCurrentEvent(), m_openFile));
}

Expand Down
2 changes: 2 additions & 0 deletions Fireworks/Core/src/CmsShowMain.h
Expand Up @@ -76,6 +76,7 @@ class CmsShowMain : public CmsShowMainBase {
const fwlite::Event* getCurrentEvent() const;
const fireworks::Context* context() const { return m_context.get(); };
bool getVersionCheck() const { return !m_noVersionCheck; }
bool getGlobalTagCheck() const { return m_globalTagCheck; }

void fileChangedSlot(const TFile* file);

Expand Down Expand Up @@ -127,6 +128,7 @@ class CmsShowMain : public CmsShowMainBase {
UInt_t m_lastXEventSerial;

bool m_noVersionCheck;
bool m_globalTagCheck;

std::unique_ptr<TMonitor> m_monitor;
};
Expand Down
2 changes: 1 addition & 1 deletion Fireworks/Core/src/CmsShowMainBase.cc
Expand Up @@ -198,6 +198,7 @@ void CmsShowMainBase::setup(FWNavigatorBase *navigator,
FWJobMetadataManager *metadataManager) {
m_navigatorPtr = navigator;
m_contextPtr = context;
m_contextPtr->setGeom(&m_geom);
m_metadataManagerPtr = metadataManager;

m_colorManager->initialize();
Expand Down Expand Up @@ -389,7 +390,6 @@ void CmsShowMainBase::loadGeometry() { // prepare geometry service
try {
guiManager()->updateStatus("Loading geometry...");
m_geom.loadMap(m_geometryFilename.c_str());
m_contextPtr->setGeom(&m_geom);
} catch (const std::runtime_error &iException) {
fwLog(fwlog::kError) << "CmsShowMain::loadGeometry() caught exception: \n"
<< m_geometryFilename << " " << iException.what() << std::endl;
Expand Down
12 changes: 10 additions & 2 deletions Fireworks/Core/src/CmsShowNavigator.cc
Expand Up @@ -71,7 +71,7 @@ bool CmsShowNavigator::openFile(const std::string& fileName) {
fwLog(fwlog::kDebug) << "CmsShowNavigator::openFile [" << fileName << "]" << std::endl;
FWFileEntry* newFile = nullptr;
try {
newFile = new FWFileEntry(fileName, m_main.getVersionCheck());
newFile = new FWFileEntry(fileName, m_main.getVersionCheck(), m_main.getGlobalTagCheck());
} catch (std::exception& iException) {
fwLog(fwlog::kError) << "Navigator::openFile ecaught exception FWFileEntry constructor " << iException.what()
<< std::endl;
Expand Down Expand Up @@ -110,7 +110,7 @@ bool CmsShowNavigator::appendFile(const std::string& fileName, bool checkFileQue
fwLog(fwlog::kDebug) << "CmsShowNavigator::appendFile [" << fileName << "]" << std::endl;
FWFileEntry* newFile = nullptr;
try {
newFile = new FWFileEntry(fileName, m_main.getVersionCheck());
newFile = new FWFileEntry(fileName, m_main.getVersionCheck(), m_main.getGlobalTagCheck());
} catch (std::exception& iException) {
fwLog(fwlog::kError) << "Navigator::appendFile caught exception FWFileEntry constructor " << iException.what()
<< std::endl;
Expand Down Expand Up @@ -812,3 +812,11 @@ const char* CmsShowNavigator::frameTitle() {
m_currentEvent + 1,
(*m_currentFile)->lastEvent() + 1);
}

std::string CmsShowNavigator::getCurrentGlobalTag() {
std::string res;
if (!m_files.empty()) {
res = (*m_currentFile)->getGlobalTag();
}
return res;
}
123 changes: 97 additions & 26 deletions Fireworks/Core/src/FWFileEntry.cc
Expand Up @@ -11,9 +11,14 @@
#include "DataFormats/Provenance/interface/ProcessConfiguration.h"
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "DataFormats/Provenance/interface/ReleaseVersion.h"
#include "DataFormats/Provenance/interface/ParameterSetBlob.h"
#include "DataFormats/Provenance/interface/ParameterSetID.h"
#include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"

#include "FWCore/Utilities/interface/WrappedClassName.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/Registry.h"

#include "Fireworks/Core/interface/FWEventItem.h"
#include "Fireworks/Core/interface/FWFileEntry.h"
Expand All @@ -27,14 +32,15 @@

#include <boost/bind.hpp>

FWFileEntry::FWFileEntry(const std::string& name, bool checkVersion)
FWFileEntry::FWFileEntry(const std::string& name, bool checkVersion, bool checkGT)
: m_name(name),
m_file(nullptr),
m_eventTree(nullptr),
m_event(nullptr),
m_needUpdate(true),
m_globalTag("gt_undef"),
m_globalEventList(nullptr) {
openFile(checkVersion);
openFile(checkVersion, checkGT);
}

FWFileEntry::~FWFileEntry() {
Expand All @@ -44,7 +50,7 @@ FWFileEntry::~FWFileEntry() {
delete m_globalEventList;
}

void FWFileEntry::openFile(bool checkVersion) {
void FWFileEntry::openFile(bool checkVersion, bool checkGlobalTag) {
gErrorIgnoreLevel = 3000; // suppress warnings about missing dictionaries

TFile* newFile = TFile::Open(m_name.c_str());
Expand All @@ -60,31 +66,96 @@ void FWFileEntry::openFile(bool checkVersion) {
gErrorIgnoreLevel = -1;

// check CMSSW relese version for compatibility
if (checkVersion) {
typedef std::vector<edm::ProcessHistory> provList;

TTree* metaData = dynamic_cast<TTree*>(m_file->Get("MetaData"));
TBranch* b = metaData->GetBranch("ProcessHistory");
provList* x = nullptr;
b->SetAddress(&x);
b->GetEntry(0);

const edm::ProcessConfiguration* dd = nullptr;
int latestVersion = 0;
int currentVersionArr[] = {0, 0, 0};
for (auto const& processHistory : *x) {
for (auto const& processConfiguration : processHistory) {
// std::cout << processConfiguration.releaseVersion() << " " << processConfiguration.processName() << std::endl;
TString dcv = processConfiguration.releaseVersion();
fireworks::getDecomposedVersion(dcv, currentVersionArr);
int nvv = currentVersionArr[0] * 100 + currentVersionArr[1] * 10 + currentVersionArr[2];
if (nvv > latestVersion) {
latestVersion = nvv;
dd = &processConfiguration;
typedef std::vector<edm::ProcessHistory> provList;

TTree* metaData = dynamic_cast<TTree*>(m_file->Get("MetaData"));
TBranch* b = metaData->GetBranch("ProcessHistory");
edm::ProcessHistoryVector phv_;
edm::ProcessHistoryVector* pPhv = &phv_;
metaData->SetBranchAddress("ProcessHistory", &pPhv);

b->GetEntry(0);

typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> ParameterSetMap;
ParameterSetMap psm_;
TTree* psetTree = dynamic_cast<TTree*>(newFile->Get("ParameterSets"));
typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
IdToBlobs idToBlob;
IdToBlobs* pIdToBlob = &idToBlob;
psetTree->SetBranchAddress("IdToParameterSetsBlobs", &pIdToBlob);
for (long long i = 0; i != psetTree->GetEntries(); ++i) {
psetTree->GetEntry(i);
psm_.insert(idToBlob);
}

edm::pset::Registry& psetRegistry = *edm::pset::Registry::instance();
for (auto const& item : psm_) {
edm::ParameterSet pset(item.second.pset());
pset.setID(item.first);
psetRegistry.insertMapped(pset);
}

const edm::ProcessConfiguration* dd = nullptr;
int latestVersion = 0;
int currentVersionArr[] = {0, 0, 0};
for (auto const& processHistory : phv_) {
for (auto const& processConfiguration : processHistory) {
// std::cout << processConfiguration.releaseVersion() << " " << processConfiguration.processName() << std::endl;
TString dcv = processConfiguration.releaseVersion();
fireworks::getDecomposedVersion(dcv, currentVersionArr);
int nvv = currentVersionArr[0] * 100 + currentVersionArr[1] * 10 + currentVersionArr[2];
if (nvv > latestVersion) {
latestVersion = nvv;
dd = &processConfiguration;
}
}
}

// read first global tag for auto detect of geomtery version
if (checkGlobalTag) {
std::map<edm::ProcessConfigurationID, unsigned int> simpleIDs;
m_globalTag = "";
for (auto const& ph : phv_) {
for (auto const& pc : ph) {
unsigned int id = simpleIDs[pc.id()];
if (0 == id) {
id = 1;
simpleIDs[pc.id()] = id;
}
ParameterSetMap::const_iterator itFind = psm_.find(pc.parameterSetID());
if (itFind == psm_.end()) {
std::cout << "No ParameterSetID for " << pc.parameterSetID() << std::endl;
fwLog(fwlog::kInfo) << "FWFileEntry::openFile no ParameterSetID for " << pc.parameterSetID() << std::endl;
} else {
edm::ParameterSet processConfig(itFind->second.pset());
std::vector<std::string> sourceStrings, moduleStrings;
std::vector<std::string> sources = processConfig.getParameter<std::vector<std::string>>("@all_essources");
for (auto& itM : sources) {
edm::ParameterSet const& pset = processConfig.getParameterSet(itM);
std::string name(pset.getParameter<std::string>("@module_label"));
if (name.empty()) {
name = pset.getParameter<std::string>("@module_type");
}
if (name != "GlobalTag")
continue;

for (auto const& item : pset.tbl()) {
if (item.first == "globaltag") {
m_globalTag = item.second.getString();
goto gtEnd;
}
}
}
}
}
}

gtEnd:
fwLog(fwlog::kDebug) << "FWFileEntry::openFile detected global tag " << m_globalTag << "\n";
}

// test compatibility of data with CMSSW
if (checkVersion) {
if (latestVersion) {
fwLog(fwlog::kInfo) << "Checking process history. " << m_name.c_str() << " latest process \"" << dd->processName()
<< "\", version " << dd->releaseVersion() << std::endl;
Expand Down Expand Up @@ -418,7 +489,7 @@ bool FWFileEntry::filterEventsWithCustomParser(Filter* filterEntry) {
boost::sregex_token_iterator j;

// filters and how they enter in the logical expression
std::vector<std::pair<unsigned int, bool> > filters;
std::vector<std::pair<unsigned int, bool>> filters;

while (i != j) {
std::string filter = *i++;
Expand Down Expand Up @@ -449,7 +520,7 @@ bool FWFileEntry::filterEventsWithCustomParser(Filter* filterEntry) {

for (m_event->toBegin(); !m_event->atEnd(); ++(*m_event)) {
hTriggerResults.getByLabel(*m_event, "TriggerResults", "", filterEntry->m_selector->m_triggerProcess.c_str());
std::vector<std::pair<unsigned int, bool> >::const_iterator filter = filters.begin();
std::vector<std::pair<unsigned int, bool>>::const_iterator filter = filters.begin();
bool passed = hTriggerResults->accept(filter->first) == filter->second;
while (++filter != filters.end()) {
if (junction_mode)
Expand Down

0 comments on commit 0d3828c

Please sign in to comment.