Skip to content

Commit ccf0ec1

Browse files
authored
Make geometry loadable from the CCDB (#7415)
* TObject cloning by CcdbApi is left for TTree only (to be dropped also) * Make geometry loadable from the CCDB Co-authored-by: shahoian <ruben.shahoyan@cern.ch>
1 parent a3b463c commit ccf0ec1

File tree

8 files changed

+43
-19
lines changed

8 files changed

+43
-19
lines changed

CCDB/src/CcdbApi.cxx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,16 +700,21 @@ void* CcdbApi::extractFromTFile(TFile& file, TClass const* cl)
700700
auto result = object;
701701
// We need to handle some specific cases as ROOT ties them deeply
702702
// to the file they are contained in
703-
if (cl->InheritsFrom("TObject")) {
703+
if (cl->InheritsFrom("TObject")) { // RS not sure why cloning is needed, certainly for the histos it it enough to SetDirectory(nullptr)
704704
// make a clone
705-
auto obj = ((TObject*)object)->Clone();
706705
// detach from the file
707-
if (auto tree = dynamic_cast<TTree*>(obj)) {
706+
auto tree = dynamic_cast<TTree*>((TObject*)object);
707+
if (tree) { // RS At the moment leaving the cloning for TTree
708+
tree = (TTree*)tree->Clone();
708709
tree->SetDirectory(nullptr);
709-
} else if (auto h = dynamic_cast<TH1*>(obj)) {
710-
h->SetDirectory(nullptr);
710+
result = tree;
711+
} else {
712+
auto h = dynamic_cast<TH1*>((TObject*)object);
713+
if (h) {
714+
h->SetDirectory(nullptr);
715+
result = h;
716+
}
711717
}
712-
result = obj;
713718
}
714719
return result;
715720
}

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
6767
return o2::utils::Str::concat_string(prefix, "_", CONFIG_STRING, ".ini");
6868
}
6969

70+
static constexpr std::string_view CCDBOBJECT = "ccdb_object"; // hardcoded
71+
static constexpr std::string_view CCDBMETA = "ccdb_meta"; // hardcoded
72+
static constexpr std::string_view CCDBQUERY = "ccdb_query"; // hardcoded
73+
7074
// Filename to store geometry file
7175
static std::string getGeomFileName(const std::string_view prefix = "");
7276

@@ -83,7 +87,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
8387
static std::string getCutProcFileName(const std::string_view prefix = "");
8488

8589
// TGeometry object name
86-
static constexpr std::string_view GEOMOBJECTNAME = "FAIRGeom"; // hardcoded
90+
static constexpr std::string_view GEOMOBJECTNAME_FAIR = "FAIRGeom"; // hardcoded
8791

8892
// public standard TTree key (for MC ) -- not a function
8993
static constexpr std::string_view MCTTREENAME = "o2sim"; // hardcoded

Detectors/Base/include/DetectorsBase/GeometryManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GeometryManager : public TObject
5151
///< load geometry from file
5252
static void loadGeometry(std::string_view geomFilePath = "", bool applyMisalignment = true);
5353
static bool isGeometryLoaded() { return gGeoManager != nullptr; }
54+
static void applyMisalignent(bool applyMisalignment = true);
5455

5556
///< Get the global transformation matrix (ideal geometry) for a given alignable volume
5657
///< The alignable volume is identified by 'symname' which has to be either a valid symbolic

Detectors/Base/src/GeometryManager.cxx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,33 @@ o2::base::MatBudget GeometryManager::meanMaterialBudget(float x0, float y0, floa
483483
return o2::base::MatBudget(budTotal);
484484
}
485485

486+
//_________________________________
487+
void GeometryManager::applyMisalignent(bool applyMisalignment)
488+
{
489+
///< load geometry from file
490+
if (!isGeometryLoaded()) {
491+
LOG(FATAL) << "geometry is not loaded";
492+
}
493+
if (applyMisalignment) {
494+
auto& aligner = Aligner::Instance();
495+
aligner.applyAlignment();
496+
}
497+
}
498+
486499
//_________________________________
487500
void GeometryManager::loadGeometry(std::string_view geomFileName, bool applyMisalignment)
488501
{
489502
///< load geometry from file
490503
std::string fname = o2::base::NameConf::getGeomFileName(geomFileName);
491-
LOG(INFO) << "Loading geometry " << o2::base::NameConf::GEOMOBJECTNAME << " from " << fname;
504+
LOG(INFO) << "Loading geometry from " << fname;
492505
TFile flGeom(fname.data());
493506
if (flGeom.IsZombie()) {
494507
LOG(FATAL) << "Failed to open file " << fname;
495508
}
496-
if (!flGeom.Get(std::string(o2::base::NameConf::GEOMOBJECTNAME).c_str())) {
497-
LOG(FATAL) << "Did not find geometry named " << o2::base::NameConf::GEOMOBJECTNAME;
498-
}
499-
if (applyMisalignment) {
500-
auto& aligner = Aligner::Instance();
501-
aligner.applyAlignment();
509+
// try under the standard CCDB name
510+
if (!flGeom.Get(std::string(o2::base::NameConf::CCDBOBJECT).c_str()) &&
511+
!flGeom.Get(std::string(o2::base::NameConf::GEOMOBJECTNAME_FAIR).c_str())) {
512+
LOG(FATAL) << "Did not find geometry named " << o2::base::NameConf::CCDBOBJECT << " or " << o2::base::NameConf::GEOMOBJECTNAME_FAIR;
502513
}
514+
applyMisalignent(applyMisalignment);
503515
}

Detectors/MUON/MCH/Geometry/Transformer/src/convert-geometry.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TGeoManager* readFromFile(std::string filename)
5252
throw std::runtime_error("can not open " + filename);
5353
}
5454

55-
auto possibleGeoNames = {"ALICE", "FAIRGeom", "MCH-ONLY", "MCH-BASICS"};
55+
auto possibleGeoNames = {"ccdb_object", "ALICE", "FAIRGeom", "MCH-ONLY", "MCH-BASICS"};
5656

5757
TGeoManager* geo{nullptr};
5858

@@ -64,7 +64,7 @@ TGeoManager* readFromFile(std::string filename)
6464
}
6565
if (!geo) {
6666
f->ls();
67-
throw std::runtime_error("could not find ALICE geometry (using ALICE or FAIRGeom names)");
67+
throw std::runtime_error("could not find ALICE geometry (using ccdb_object, ALICE or FAIRGeom names)");
6868
}
6969
return geo;
7070
}

Detectors/TOF/prototyping/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# or submit itself to any jurisdiction.
1111

1212
o2_add_test_root_macro(checkRotation.C
13-
PUBLIC_LINK_LIBRARIES O2::TOFBase
13+
PUBLIC_LINK_LIBRARIES O2::TOFBase O2::DetectorsBase
1414
LABELS tof)
1515

1616
o2_add_test_root_macro(convertTreeTo02object.C

Detectors/TOF/prototyping/checkRotation.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if !defined(__CLING__) || defined(__ROOTCLING__)
22
#include "TFile.h"
33
#include "TOFBase/Geo.h"
4+
#include "DetectorsBase/GeometryManager.h"
45
#endif
56

67
void checkRotation(const char* nameinput = "../../../macro/geometry.root")
@@ -16,8 +17,7 @@ void checkRotation(const char* nameinput = "../../../macro/geometry.root")
1617

1718
Int_t n = 1;
1819

19-
TFile* fin = new TFile(nameinput);
20-
fin->Get("FAIRGeom");
20+
o2::base::GeometryManager::loadGeometry(nameinput, false);
2121

2222
Int_t isector;
2323

Steer/src/O2MCApplication.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ bool O2MCApplicationBase::MisalignGeometry()
151151

152152
auto& confref = o2::conf::SimConfig::Instance();
153153
auto geomfile = o2::base::NameConf::getGeomFileName(confref.getOutPrefix());
154+
// since in general the geometry is a CCDB object, it must be exported under the standard name
155+
gGeoManager->SetName(std::string(o2::base::NameConf::CCDBOBJECT).c_str());
154156
gGeoManager->Export(geomfile.c_str());
155157

156158
// apply alignment for included detectors AFTER exporting ideal geometry

0 commit comments

Comments
 (0)