Skip to content

Commit

Permalink
Merge pull request #43388 from fabiocos/fc-speedupdd4hep
Browse files Browse the repository at this point in the history
MTD Geometry: Optimize speed of MTD ideal geometry dump and improve verbosity
  • Loading branch information
cmsbuild authored Nov 27, 2023
2 parents bc48847 + 61b9f6e commit f7ac574
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 52 deletions.
52 changes: 29 additions & 23 deletions Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "DataFormats/Math/interface/Rounding.h"
#include <DD4hep/DD4hepUnits.h>

//#define EDM_ML_DEBUG

using namespace cms;

class DD4hep_TestMTDIdealGeometry : public edm::one::EDAnalyzer<> {
Expand Down Expand Up @@ -137,6 +135,7 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E
bool isBarrel = true;
bool exitLoop = false;
uint32_t level(0);
uint32_t count(0);

do {
if (dd4hep::dd::noNamespace(fv.name()) == "BarrelTimingLayer") {
Expand All @@ -147,30 +146,27 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E
edm::LogInfo("DD4hep_TestMTDIdealGeometry") << "isBarrel = " << isBarrel;
}

std::stringstream ss;

theBaseNumber(fv);

auto print_path = [&]() {
ss << " - OCMS[0]/";
for (int ii = thisN_.getLevels() - 1; ii-- > 0;) {
ss << thisN_.getLevelName(ii);
ss << "[";
ss << thisN_.getCopyNumber(ii);
ss << "]/";
}
};

if (level > 0 && fv.navPos().size() < level) {
level = 0;
write = false;
exitLoop = true;
if (isBarrel) {
exitLoop = true;
} else if (!isBarrel && count == 2) {
exitLoop = true;
}
}
if (dd4hep::dd::noNamespace(fv.name()) == ddTopNodeName_) {
write = true;
level = fv.navPos().size();
count += 1;
}

#ifdef EDM_ML_DEBUG
edm::LogVerbatim("DD4hep_TestMTDIdealGeometry")
<< "level= " << level << " isBarrel= " << isBarrel << " exitLoop= " << exitLoop << " count= " << count << " "
<< fv.path();
#endif

// Test only the desired subdetector

if (exitLoop && isBarrel) {
Expand All @@ -180,11 +176,21 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E
// Actions for MTD volumes: searchg for sensitive detectors

if (write) {
print_path();
std::stringstream ss;

#ifdef EDM_ML_DEBUG
edm::LogInfo("DD4hep_TestMTDIdealGeometry") << fv.path();
#endif
theBaseNumber(fv);

auto print_path = [&]() {
ss << " - OCMS[0]/";
for (int ii = thisN_.getLevels() - 1; ii-- > 0;) {
ss << thisN_.getLevelName(ii);
ss << "[";
ss << thisN_.getCopyNumber(ii);
ss << "]/";
}
};

print_path();

edm::LogInfo("DD4hep_TestMTDPath") << ss.str();

Expand Down Expand Up @@ -280,7 +286,7 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E
edm::LogVerbatim("MTDUnitTest") << sunitt.str();
}
}
} while (fv.next(0));
} while (fv.next(0) && !(exitLoop == 1 && count == 2));
}

void DD4hep_TestMTDIdealGeometry::theBaseNumber(cms::DDFilteredView& fv) {
Expand All @@ -292,7 +298,7 @@ void DD4hep_TestMTDIdealGeometry::theBaseNumber(cms::DDFilteredView& fv) {
size_t ipos = name.rfind('_');
thisN_.addLevel(name.substr(0, ipos), fv.copyNos()[ii]);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("DD4hep_TestMTDIdealGeometry") << name.substr(0, ipos) << " " << fv.copyNos()[ii];
edm::LogVerbatim("DD4hep_TestMTDIdealGeometry") << ii << " " << name.substr(0, ipos) << " " << fv.copyNos()[ii];
#endif
}
}
Expand Down
49 changes: 28 additions & 21 deletions Geometry/MTDCommonData/test/TestMTDIdealGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "DataFormats/Math/interface/angle_units.h"
#include "DataFormats/Math/interface/Rounding.h"

//#define EDM_ML_DEBUG

class TestMTDIdealGeometry : public edm::one::EDAnalyzer<> {
public:
explicit TestMTDIdealGeometry(const edm::ParameterSet&);
Expand Down Expand Up @@ -98,7 +96,9 @@ void TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::EventSet

bool write = false;
bool isBarrel = true;
bool exitLoop = false;
size_t limit = 0;
uint32_t count(0);

do {
nav_type pos = fv.navPos();
Expand All @@ -108,37 +108,44 @@ void TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::EventSet

if (num <= limit) {
write = false;
if (isBarrel && count == 1) {
exitLoop = true;
} else if (!isBarrel && count == 2) {
exitLoop = true;
}
}
if (fv.geoHistory()[num - 1].logicalPart().name() == "btl:BarrelTimingLayer") {
isBarrel = true;
limit = num;
write = true;
#ifdef EDM_ML_DEBUG
edm::LogInfo("TestMTDIdealGeometry") << "isBarrel = " << isBarrel;
#endif
} else if (fv.geoHistory()[num - 1].logicalPart().name() == "etl:EndcapTimingLayer") {
isBarrel = false;
limit = num;
}
if (fv.geoHistory()[num - 1].logicalPart().name().name() == ddTopNodeName_) {
write = true;
count += 1;
}

#ifdef EDM_ML_DEBUG
edm::LogInfo("TestMTDIdealGeometry") << "isBarrel = " << isBarrel;
edm::LogVerbatim("TestMTDIdealGeometry")
<< "level= " << num << " isBarrel= " << isBarrel << " "
<< " exitLoop= " << exitLoop << " count= " << count << " " << fv.geoHistory()[num - 1].logicalPart().name();
#endif
}

// Actions for MTD volumes: searchg for sensitive detectors

std::stringstream ss;
auto print_path = [&]() {
ss << " - OCMS[0]/";
for (uint i = 1; i < fv.geoHistory().size(); i++) {
ss << fv.geoHistory()[i].logicalPart().name().fullname();
ss << "[";
ss << std::to_string(fv.geoHistory()[i].copyno());
ss << "]/";
}
};

if (write && fv.geoHistory()[limit - 1].logicalPart().name().name() == ddTopNodeName_) {
std::stringstream ss;
auto print_path = [&]() {
ss << " - OCMS[0]/";
for (uint i = 1; i < fv.geoHistory().size(); i++) {
ss << fv.geoHistory()[i].logicalPart().name().fullname();
ss << "[";
ss << std::to_string(fv.geoHistory()[i].copyno());
ss << "]/";
}
};

print_path();
edm::LogInfo("TestMTDPath") << ss.str();

Expand Down Expand Up @@ -242,7 +249,7 @@ void TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::EventSet
}
}
++id;
} while (fv.next());
} while (fv.next() && !(exitLoop == 1));
}

void TestMTDIdealGeometry::theBaseNumber(const DDGeoHistory& gh) {
Expand All @@ -252,7 +259,7 @@ void TestMTDIdealGeometry::theBaseNumber(const DDGeoHistory& gh) {
for (uint i = gh.size(); i-- > 0;) {
thisN_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
#ifdef EDM_ML_DEBUG
edm::LogInfo("TestMTDIdealGeometry") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
edm::LogVerbatim("TestMTDIdealGeometry") << i << " " << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
#endif
}
}
Expand Down
12 changes: 8 additions & 4 deletions Geometry/MTDCommonData/test/testMTDinDD4hep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.DD4hep_TestMTDIdealGeometry = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.DD4hep_TestMTDNumbering = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.DD4hep_TestMTDPath = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.DD4hep_TestMTDPosition = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.files.mtdCommonDataDD4hep = cms.untracked.PSet(
DEBUG = cms.untracked.PSet(
Expand Down
12 changes: 8 additions & 4 deletions Geometry/MTDCommonData/test/testMTDinDDD.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.TestMTDIdealGeometry = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.TestMTDNumbering = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.TestMTDPath = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.cerr.TestMTDPosition = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
# limit = cms.untracked.int32(-1)
limit = cms.untracked.int32(0)
)
process.MessageLogger.files.mtdCommonDataDDD = cms.untracked.PSet(
DEBUG = cms.untracked.PSet(
Expand Down

0 comments on commit f7ac574

Please sign in to comment.