CMS 3D CMS Logo

Namespaces | Enumerations | Functions
DDDefinitions2Objects.cc File Reference
#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/DetectorHelper.h"
#include "DD4hep/DD4hepUnits.h"
#include "DD4hep/GeoHandler.h"
#include "DD4hep/Printout.h"
#include "DD4hep/Plugins.h"
#include "DD4hep/detail/SegmentationsInterna.h"
#include "DD4hep/detail/DetectorInterna.h"
#include "DD4hep/detail/ObjectsInterna.h"
#include "DD4hep/MatrixHelpers.h"
#include "XML/Utilities.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/thread_safety_macros.h"
#include "DataFormats/Math/interface/CMSUnits.h"
#include "DetectorDescription/DDCMS/interface/DDAlgoArguments.h"
#include "DetectorDescription/DDCMS/interface/DDNamespace.h"
#include "DetectorDescription/DDCMS/interface/DDParsingContext.h"
#include "DetectorDescription/DDCMS/interface/DDDetector.h"
#include "TGeoManager.h"
#include "TGeoMaterial.h"
#include <climits>
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <unordered_map>
#include <utility>

Go to the source code of this file.

Namespaces

 dd4hep
 

Enumerations

enum  DDAxes {
  DDAxes::x, DDAxes::y, DDAxes::z, DDAxes::rho,
  DDAxes::radial3D, DDAxes::phi, DDAxes::undefined
}
 

Functions

template<typename TYPE >
static void convert_boolean (cms::DDParsingContext *context, xml_h element)
 
TGeoCombiTrans * dd4hep::createPlacement (const Rotation3D &iRot, const Position &iTrans)
 
template<class InputIt , class ForwardIt , class BinOp >
void for_each_token (InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last, BinOp binary_op)
 
static long load_dddefinition (Detector &det, xml_h element)
 Converter for <DDDefinition> tags. More...
 
static void placeAssembly (Volume *parentPtr, const string &parentName, Volume *childPtr, const string &childName, int copy, const Transform3D &transform, cms::DDNamespace &ns)
 

Enumeration Type Documentation

◆ DDAxes

enum DDAxes
strong
Enumerator
rho 
radial3D 
phi 
undefined 

Definition at line 1802 of file DDDefinitions2Objects.cc.

Function Documentation

◆ convert_boolean()

template<typename TYPE >
static void convert_boolean ( cms::DDParsingContext context,
xml_h  element 
)
static

Definition at line 1133 of file DDDefinitions2Objects.cc.

References cms::DDNamespace::addSolid(), DummyCfis::c, visDQMUpload::context, cms::DDNamespace::context(), DD_CMU, DEBUG, cms::DDParsingContext::debug_placements, MillePedeFileConverter_cfg::e, dqm::qstatus::ERROR, sistrip::SpyUtilities::isValid(), mergeVDriftHistosByStation::name, cms::DDParsingContext::shapes, cms::DDNamespace::solid(), runonSM::TYPE, and cms::DDParsingContext::unresolvedShapes.

1133  {
1135  xml_dim_t e(element);
1136  string nam = e.nameStr();
1137  string solidName[2];
1138  Solid solids[2];
1139  Solid boolean;
1140  int cnt = 0;
1141  if (e.hasChild(DD_CMU(rSolid))) {
1142  for (xml_coll_t c(element, DD_CMU(rSolid)); cnt < 2 && c; ++c, ++cnt) {
1143  solidName[cnt] = c.attr<string>(_U(name));
1144  solids[cnt] = ns.solid(c.attr<string>(_U(name)));
1145  }
1146  } else {
1147  solidName[0] = e.attr<string>(DD_CMU(firstSolid));
1148  if ((solids[0] = ns.solid(e.attr<string>(DD_CMU(firstSolid)))).isValid())
1149  ++cnt;
1150  solidName[1] = e.attr<string>(DD_CMU(secondSolid));
1151  if ((solids[1] = ns.solid(e.attr<string>(DD_CMU(secondSolid)))).isValid())
1152  ++cnt;
1153  }
1154  if (cnt != 2) {
1155  except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt);
1156  }
1157 
1158 #ifdef EDM_ML_DEBUG
1159 
1160  printout(ns.context()->debug_placements ? ALWAYS : DEBUG,
1161  "DD4CMS",
1162  "+++ BooleanSolid: %s Left: %-32s Right: %-32s",
1163  nam.c_str(),
1164  ((solids[0].ptr() == nullptr) ? solidName[0].c_str() : solids[0]->GetName()),
1165  ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName()));
1166 
1167 #endif
1168 
1169  if (solids[0].isValid() && solids[1].isValid()) {
1170  Transform3D trafo;
1171  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1172  boolean = TYPE(solids[0], solids[1], trafo);
1173  } else {
1174  // Register it for later processing
1175  Transform3D trafo;
1176  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1177  ns.context()->unresolvedShapes.emplace(nam,
1178  DDParsingContext::BooleanShape<TYPE>(solidName[0], solidName[1], trafo));
1179  if (solids[0].isValid() == false) {
1180  printout(ERROR, "DD4CMS", "++ Solid not defined yet: %s", solidName[0].c_str());
1181  }
1182  if (solids[1].isValid() == false) {
1183  printout(ERROR, "DD4CMS", "++ Solid not defined yet: %s", solidName[1].c_str());
1184  }
1185  printout(ERROR, "DD4CMS", "++ Re-order XML files to prevent references to undefined solids");
1186  }
1187  if (!boolean.isValid()) {
1188  // Delay processing the shape
1189  ns.context()->shapes.emplace(nam, dd4hep::Solid(nullptr));
1190  } else
1191  ns.addSolid(nam, boolean);
1192 }
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
#define DD_CMU(a)
Definition: DDXMLTags.h:183
#define DEBUG
Definition: DMRChecker.cc:120
static const int ERROR

◆ for_each_token()

template<class InputIt , class ForwardIt , class BinOp >
void for_each_token ( InputIt  first,
InputIt  last,
ForwardIt  s_first,
ForwardIt  s_last,
BinOp  binary_op 
)

Definition at line 1962 of file DDDefinitions2Objects.cc.

References dqmdumpme::first, dqmdumpme::last, and GetRecoTauVFromDQM_MC_cff::next.

1962  {
1963  while (first != last) {
1964  const auto pos = std::find_first_of(first, last, s_first, s_last);
1965  binary_op(first, pos);
1966  if (pos == last)
1967  break;
1968  first = std::next(pos);
1969  }
1970 }

◆ load_dddefinition()

static long load_dddefinition ( Detector &  det,
xml_h  element 
)
static

Converter for <DDDefinition> tags.

Unload all XML files after processing

This should be the end of all processing....close the geometry

Definition at line 2162 of file DDDefinitions2Objects.cc.

References triggerObjects_cff::bit, visDQMUpload::context, ztail::d, DD_CMU, debug, DEBUG, ALCARECOEcalPhiSym_cff::doc, MillePedeFileConverter_cfg::e, dqm::qstatus::ERROR, cppFunctionSkipper::exception, alignmentValidation::fname, mps_fire::i, dtDQMClient_cfg::INFO, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, mergeVDriftHistosByStation::name, mps_fire::result, l1trig_cff::shape, AlCaHLTBitMon_QueryRunRegistry::string, and ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::wv.

2162  {
2163  xml_elt_t dddef(element);
2164  if (dddef) {
2165  cms::DDParsingContext& context = *det.extension<DDParsingContext>();
2167  ns.addConstantNS("world_x", "101*m", "number");
2168  ns.addConstantNS("world_y", "101*m", "number");
2169  ns.addConstantNS("world_z", "450*m", "number");
2170  ns.addConstantNS("Air", "materials:Air", "string");
2171  ns.addConstantNS("Vacuum", "materials:Vacuum", "string");
2172 
2173  string fname = xml::DocumentHandler::system_path(element);
2174  bool open_geometry = dddef.hasChild(DD_CMU(open_geometry)) ? dddef.child(DD_CMU(open_geometry)) : true;
2175  bool close_geometry = dddef.hasChild(DD_CMU(close_geometry)) ? dddef.hasChild(DD_CMU(close_geometry)) : true;
2176 
2177  xml_coll_t(dddef, _U(debug)).for_each(Converter<debug>(det, &context));
2178 
2179  // Here we define the order how XML elements are processed.
2180  // Be aware of dependencies. This can only defined once.
2181  // At the end it is a limitation of DOM....
2182  printout(INFO, "DD4CMS", "+++ Processing the CMS detector description %s", fname.c_str());
2183 
2184  xml::Document doc;
2185  Converter<print_xml_doc> print_doc(det, &context);
2186  try {
2187  DDRegistry res;
2188  res.unresolvedConst.reserve(2000);
2189  res.originalConst.reserve(6000);
2190  print_doc((doc = dddef.document()).root());
2191  xml_coll_t(dddef, DD_CMU(ConstantsSection)).for_each(Converter<ConstantsSection>(det, &context, &res));
2192  xml_coll_t(dddef, DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
2193  xml_coll_t(dddef, DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
2194 
2195  xml_coll_t(dddef, DD_CMU(IncludeSection)).for_each(DD_CMU(Include), Converter<include_load>(det, &context, &res));
2196 
2197  for (xml::Document d : res.includes) {
2198  print_doc((doc = d).root());
2199  Converter<include_constants>(det, &context, &res)((doc = d).root());
2200  }
2201  // Before we continue, we have to resolve all constants NOW!
2202  Converter<DDRegistry>(det, &context, &res)(dddef);
2203  {
2204  DDVectorsMap* registry = context.description.extension<DDVectorsMap>();
2205 
2206  printout(context.debug_constants ? ALWAYS : DEBUG,
2207  "DD4CMS",
2208  "+++ RESOLVING %ld Vectors.....",
2209  context.unresolvedVectors.size());
2210 
2211  while (!context.unresolvedVectors.empty()) {
2212  for (auto it = context.unresolvedVectors.begin(); it != context.unresolvedVectors.end();) {
2213  std::vector<double> result;
2214  for (const auto& i : it->second) {
2215  result.emplace_back(dd4hep::_toDouble(i));
2216  }
2217  registry->insert({it->first, result});
2218  // All components are resolved
2219  it = context.unresolvedVectors.erase(it);
2220  }
2221  }
2222  }
2223  // Now we can process the include files one by one.....
2224  for (xml::Document d : res.includes) {
2225  print_doc((doc = d).root());
2226  xml_coll_t(d.root(), DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
2227  }
2228  if (open_geometry) {
2229  det.init();
2230  ns.addVolume(det.worldVolume());
2231  }
2232  for (xml::Document d : res.includes) {
2233  print_doc((doc = d).root());
2234  xml_coll_t(d.root(), DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
2235  }
2236  for (xml::Document d : res.includes) {
2237  print_doc((doc = d).root());
2238  xml_coll_t(d.root(), DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2239  }
2240  for (xml::Document d : res.includes) {
2241  print_doc((doc = d).root());
2242  xml_coll_t(d.root(), DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2243  }
2244  for (xml::Document d : res.includes) {
2245  print_doc((doc = d).root());
2246  xml_coll_t(d.root(), DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2247  }
2248  for (xml::Document d : res.includes) {
2249  print_doc((doc = d).root());
2250  xml_coll_t(d.root(), DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2251  }
2252  for (xml::Document d : res.includes) {
2253  print_doc((doc = d).root());
2254  xml_coll_t(d.root(), DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2255  }
2256 
2258  for (xml::Document d : res.includes)
2259  Converter<include_unload>(det, &context, &res)(d.root());
2260 
2261  print_doc((doc = dddef.document()).root());
2262  // Now process the actual geometry items
2263  xml_coll_t(dddef, DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2264  {
2265  // Before we continue, we have to resolve all shapes NOW!
2266  // Note: This only happens in a legacy DB payloads where
2267  // boolean shapes can be defined before thier
2268  // component shapes
2269 
2270  while (!context.unresolvedShapes.empty()) {
2271  for (auto it = context.unresolvedShapes.begin(); it != context.unresolvedShapes.end();) {
2272  auto const& name = it->first;
2273  auto const& aname = std::visit([](auto&& arg) -> std::string { return arg.firstSolidName; }, it->second);
2274  auto const& bname = std::visit([](auto&& arg) -> std::string { return arg.secondSolidName; }, it->second);
2275 
2276  auto const& ait = context.shapes.find(aname);
2277  if (ait->second.isValid()) {
2278  auto const& bit = context.shapes.find(bname);
2279  if (bit->second.isValid()) {
2280  dd4hep::Solid shape =
2281  std::visit([&ait, &bit](auto&& arg) -> dd4hep::Solid { return arg.make(ait->second, bit->second); },
2282  it->second);
2283  context.shapes[name] = shape;
2284  it = context.unresolvedShapes.erase(it);
2285  } else
2286  ++it;
2287  } else
2288  ++it;
2289  }
2290  }
2291  }
2292  xml_coll_t(dddef, DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2293  xml_coll_t(dddef, DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2294  xml_coll_t(dddef, DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2295  xml_coll_t(dddef, DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2296  } catch (const exception& e) {
2297  printout(ERROR, "DD4CMS", "Exception while processing xml source:%s", doc.uri().c_str());
2298  printout(ERROR, "DD4CMS", "----> %s", e.what());
2299  throw;
2300  }
2301 
2303  if (close_geometry) {
2304  Volume wv = det.worldVolume();
2305  Volume geomv = ns.volume("cms:OCMS", false);
2306  if (geomv.isValid())
2307  wv.placeVolume(geomv, 1);
2308  Volume mfv = ns.volume("cmsMagneticField:MAGF", false);
2309  if (mfv.isValid())
2310  wv.placeVolume(mfv, 1);
2311  Volume mfv1 = ns.volume("MagneticFieldVolumes:MAGF", false);
2312  if (mfv1.isValid())
2313  wv.placeVolume(mfv1, 1);
2314 
2315  // Can not deal with reflections without closed geometry
2316  det.manager().CloseGeometry("nv");
2317 
2318  det.endDocument();
2319  }
2320  printout(INFO, "DDDefinition", "+++ Finished processing %s", fname.c_str());
2321  return 1;
2322  }
2323  except("DDDefinition", "+++ FAILED to process unknown DOM tree [Invalid Handle]");
2324  return 0;
2325 }
A arg
Definition: Factorize.h:31
Definition: Electron.h:6
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
#define DD_CMU(a)
Definition: DDXMLTags.h:183
dd4hep::Volume Volume
d
Definition: ztail.py:151
#define debug
Definition: HDRShower.cc:19
string fname
main script
#define DEBUG
Definition: DMRChecker.cc:120
static const int ERROR

◆ placeAssembly()

static void placeAssembly ( Volume parentPtr,
const string &  parentName,
Volume childPtr,
const string &  childName,
int  copy,
const Transform3D &  transform,
cms::DDNamespace ns 
)
static

Definition at line 866 of file DDDefinitions2Objects.cc.

References cms::DDNamespace::assembly(), HLT_2024v14_cff::Class, cms::DDNamespace::context(), filterCSVwithJSON::copy, DEBUG, cms::DDParsingContext::debug_placements, geometryDiff::epsilon, dqm::qstatus::ERROR, create_idmaps::n, MetAnalyzer::pv(), l1trig_cff::shape, HcalDetIdTransform::transform(), and cms::DDParsingContext::validate.

872  {
873 #ifdef EDM_ML_DEBUG
874 
875  printout(ns.context()->debug_placements ? ALWAYS : DEBUG,
876  "DD4CMS",
877  "+++ Parent vol: %-24s Child: %-32s, copy:%d",
878  parentName.c_str(),
879  childName.c_str(),
880  copy);
881 
882 #endif
883 
884  TGeoShape* shape = (*childPtr)->GetShape();
885  // Need to fix the daughter's BBox of assemblies, if the BBox was not calculated....
886  if (shape->IsA() == TGeoShapeAssembly::Class()) {
887  TGeoShapeAssembly* as = (TGeoShapeAssembly*)shape;
888  if (std::fabs(as->GetDX()) < numeric_limits<double>::epsilon() &&
889  std::fabs(as->GetDY()) < numeric_limits<double>::epsilon() &&
890  std::fabs(as->GetDZ()) < numeric_limits<double>::epsilon()) {
891  as->NeedsBBoxRecompute();
892  as->ComputeBBox();
893  }
894  }
895  if (ns.context()->validate) {
896  TGeoNode* n;
897  TString nam_id = TString::Format("%s_%d", (*childPtr)->GetName(), copy);
898  n = static_cast<TGeoNode*>((*parentPtr)->GetNode(nam_id));
899  if (n != nullptr) {
900  printout(ERROR, "PlacedVolume", "++ Attempt to add already existing node %s", (const char*)nam_id);
901  return;
902  }
903  }
904 
906  if ((*childPtr)->IsAssembly()) {
907  pv = parentPtr->placeVolume(ns.assembly(childName), copy, transform);
908  } else {
909  pv = parentPtr->placeVolume(*childPtr, copy, transform);
910  }
911 
912  if (!pv.isValid()) {
913  printout(ERROR, "DD4CMS", "+++ Placement FAILED! Parent:%s Child:%s", parentName.c_str(), childName.c_str());
914  }
915 }
DDParsingContext *const context() const
Definition: DDNamespace.h:76
dd4hep::PlacedVolume PlacedVolume
def pv(vc)
Definition: MetAnalyzer.py:7
#define DEBUG
Definition: DMRChecker.cc:120
static const int ERROR
dd4hep::Assembly assembly(const std::string &name, bool exception=true) const
Definition: DDNamespace.cc:259
unsigned transform(const HcalDetId &id, unsigned transformCode)

Variable Documentation

◆ includes

std::vector<xml::Document> includes

◆ originalConst

std::unordered_map<std::string, std::string> originalConst

Definition at line 57 of file DDDefinitions2Objects.cc.

◆ unresolvedConst

std::unordered_map<std::string, std::string> unresolvedConst

Definition at line 56 of file DDDefinitions2Objects.cc.