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 1803 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 1134 of file DDDefinitions2Objects.cc.

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

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

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

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

◆ 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 2163 of file DDDefinitions2Objects.cc.

References triggerObjects_cff::bit, visDQMUpload::context, ztail::d, DD_CMU, debug, DEBUG, hcalRecHitTable_cff::doc, MillePedeFileConverter_cfg::e, dqm::qstatus::ERROR, cppFunctionSkipper::exception, alignmentValidation::fname, mps_fire::i, unpackBuffers-CaloStage2::INFO, Skims_PA_cff::name, mps_fire::result, l1trig_cff::shape, AlCaHLTBitMon_QueryRunRegistry::string, and gpuVertexFinder::wv.

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

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

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