18#include <TGeoManager.h>
19#include <TGeoVolume.h>
20#include <unordered_map>
21#include <unordered_set>
22#include <TGeoMaterial.h>
23#include <TGeoMedium.h>
35void ExternalModule::remapMedia(TGeoVolume* top_volume)
37 std::unordered_map<TGeoMedium*, TGeoMedium*> medium_ptr_mapping;
38 std::unordered_set<TGeoVolume*> volumes_already_treated;
41 auto modulename = GetName();
44 auto transform_media = [&](TGeoVolume* vol_) {
45 if (volumes_already_treated.find(vol_) != volumes_already_treated.end()) {
49 volumes_already_treated.insert(vol_);
51 if (
dynamic_cast<TGeoVolumeAssembly*
>(vol_)) {
56 auto medium = vol_->GetMedium();
61 auto iter = medium_ptr_mapping.find(medium);
62 if (iter != medium_ptr_mapping.end()) {
65 vol_->SetMedium(iter->second);
68 std::cout <<
"Transforming media with name " << medium->GetName() <<
" for volume " << vol_->GetName() <<
"\n";
71 auto curr_mat = medium->GetMaterial();
74 matmgr.Material(modulename,
counter, curr_mat->GetName(), curr_mat->GetA(), curr_mat->GetZ(), curr_mat->GetDensity(), curr_mat->GetRadLen(), curr_mat->GetIntLen());
84 const auto isvol = medium->GetParam(0);
85 const auto isxfld = medium->GetParam(1);
86 const auto sxmgmx = medium->GetParam(2);
87 const auto tmaxfd = medium->GetParam(3);
88 const auto stemax = medium->GetParam(4);
89 const auto deemax = medium->GetParam(5);
90 const auto epsil = medium->GetParam(6);
91 const auto stmin = medium->GetParam(7);
93 matmgr.Medium(modulename,
counter, medium->GetName(),
counter, isvol, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
96 auto new_med = matmgr.getTGeoMedium(modulename,
counter);
99 medium_ptr_mapping[medium] = new_med;
100 vol_->SetMedium(new_med);
106 std::function<
void(TGeoVolume*)> visit_volume;
107 visit_volume = [&](TGeoVolume* vol) ->
void {
113 transform_media(vol);
116 const int nd = vol->GetNdaughters();
117 for (
int i = 0;
i < nd; ++
i) {
118 TGeoNode*
node = vol->GetNode(
i);
122 TGeoVolume* child =
node->GetVolume();
131 visit_volume(top_volume);
137 if (!initGeomBuilderHook()) {
138 LOG(error) <<
" Could not load geometry builder hook";
143 auto module_top = mGeomHook();
145 LOG(error) <<
"No module found\n";
149 remapMedia(
const_cast<TGeoVolume*
>(module_top));
152 auto anchor = gGeoManager->FindVolumeFast(mOptions.
anchor_volume.c_str());
154 LOG(error) <<
"Anchor volume " << mOptions.
anchor_volume <<
" not found. Aborting";
157 anchor->AddNode(
const_cast<TGeoVolume*
>(module_top), 1,
const_cast<TGeoMatrix*
>(mOptions.
placement));
160bool ExternalModule::initGeomBuilderHook()
163 LOG(info) <<
"Initializing the hook for geometry module building";
165 if (std::filesystem::exists(expandedHookFileName)) {
167 mGeomHook = o2::conf::GetFromMacro<GeomBuilderFcn>(mOptions.
root_macro_file,
"get_builder_hook_unchecked()",
"function<TGeoVolume*()>",
"o2_passive_extmodule_builder");
168 LOG(info) <<
"Hook initialized from file " << expandedHookFileName;
std::unique_ptr< expressions::Node > node
static MaterialManager & Instance()
void ConstructGeometry() override
a common base class for passive modules - implementing generic functions
GLuint const GLchar * name
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
std::string expandShellVarsInFileName(std::string const &input)
std::string root_macro_file
TGeoMatrix const * placement
std::string anchor_volume
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"