File indexing completed on 2025-03-13 08:19:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "DD4hep/DetFactoryHelper.h"
0018 #include "DD4hep/Printout.h"
0019 #include "XML/VolumeBuilder.h"
0020 #include "XML/Utilities.h"
0021 #include <memory>
0022
0023 using namespace std;
0024 using namespace dd4hep;
0025 using namespace dd4hep::detail;
0026
0027 static Ref_t create_element(Detector& description, xml_h e, SensitiveDetector sens) {
0028
0029
0030 xml_comp_t x_det(e);
0031 xml_comp_t x_env = e.child(_U(envelope));
0032 xml_comp_t x_shp = x_env.child(_U(shape),false);
0033 xml_h x_dbg = e.child(_U(debug),false);
0034 xml_h x_pos, x_rot, x_tr;
0035 Volume assembly;
0036 xml::tools::VolumeBuilder builder(description, e, sens);
0037
0038 builder.debug = x_dbg != 0;
0039 builder.load(x_det, "include");
0040 builder.buildShapes(x_det);
0041 builder.buildShapes(x_env);
0042 builder.buildVolumes(x_det);
0043 builder.buildVolumes(x_env);
0044
0045
0046 if ( !x_shp ) x_shp = x_env;
0047 if ( x_shp.typeStr() == "Assembly" ) {
0048 assembly = Assembly("lv"+builder.name);
0049 }
0050 else {
0051 Material mat = description.material(x_env.materialStr());
0052 Solid solid = xml::createShape(description, x_shp.typeStr(), x_shp);
0053 assembly = Volume("lv"+builder.name, solid, mat);
0054 }
0055
0056 assembly.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0057
0058 if ( x_env.hasAttr(_U(vis)) )
0059 assembly.setVisAttributes(description, x_env.visStr());
0060
0061 if ( x_env.hasAttr(_U(region)) )
0062 assembly.setRegion(description, x_env.regionStr());
0063
0064 if ( x_env.hasAttr(_U(limits)) )
0065 assembly.setLimitSet(description, x_env.limitsStr());
0066
0067 if ( x_det.hasAttr(_U(sensitive)) )
0068 sens.setType(x_det.attr<string>(_U(sensitive)));
0069 else
0070 builder.detector.setType("compound");
0071
0072 if ( x_env.hasAttr(_U(name)) )
0073 assembly->SetName(x_env.nameStr().c_str());
0074
0075 builder.placeDaughters(builder.detector, assembly, x_env);
0076 builder.placeDaughters(builder.detector, assembly, x_det);
0077 x_pos = x_env.child(_U(position),false);
0078 x_rot = x_env.child(_U(rotation),false);
0079 x_tr = x_env.child(_U(transformation),false);
0080 builder.placeDetector(assembly, (x_pos || x_rot || x_tr) ? x_env : x_det);
0081 printout(builder.debug ? ALWAYS : DEBUG, "VolumeBuilder",
0082 "+++ Created subdetector instance %s vis:",
0083 builder.name.c_str(), x_det.visStr().c_str());
0084 return builder.detector;
0085 }
0086 DECLARE_DETELEMENT(DD4hep_VolumeAssembly,create_element)