CMS 3D CMS Logo

Namespaces | Macros | 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/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
 

Macros

#define EDM_ML_DEBUG
 

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...
 

Macro Definition Documentation

◆ EDM_ML_DEBUG

#define EDM_ML_DEBUG

Definition at line 32 of file DDDefinitions2Objects.cc.

Enumeration Type Documentation

◆ DDAxes

enum DDAxes
strong
Enumerator
rho 
radial3D 
phi 
undefined 

Definition at line 1691 of file DDDefinitions2Objects.cc.

1691 { x = 1, y = 2, z = 3, rho = 1, phi = 2, undefined };

Function Documentation

◆ convert_boolean()

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

Definition at line 1044 of file DDDefinitions2Objects.cc.

1044  {
1045  cms::DDNamespace ns(context);
1046  xml_dim_t e(element);
1047  string nam = e.nameStr();
1048  string solidName[2];
1049  Solid solids[2];
1050  Solid boolean;
1051  int cnt = 0;
1052  if (e.hasChild(DD_CMU(rSolid))) {
1053  for (xml_coll_t c(element, DD_CMU(rSolid)); cnt < 2 && c; ++c, ++cnt) {
1054  solidName[cnt] = c.attr<string>(_U(name));
1055  solids[cnt] = ns.solid(c.attr<string>(_U(name)));
1056  }
1057  } else {
1058  solidName[0] = e.attr<string>(DD_CMU(firstSolid));
1059  if ((solids[0] = ns.solid(e.attr<string>(DD_CMU(firstSolid)))).isValid())
1060  ++cnt;
1061  solidName[1] = e.attr<string>(DD_CMU(secondSolid));
1062  if ((solids[1] = ns.solid(e.attr<string>(DD_CMU(secondSolid)))).isValid())
1063  ++cnt;
1064  }
1065  if (cnt != 2) {
1066  except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt);
1067  }
1068 
1069 #ifdef EDM_ML_DEBUG
1070 
1071  printout(ns.context()->debug_placements ? ALWAYS : DEBUG,
1072  "DD4CMS",
1073  "+++ BooleanSolid: %s Left: %-32s Right: %-32s",
1074  nam.c_str(),
1075  ((solids[0].ptr() == nullptr) ? solidName[0].c_str() : solids[0]->GetName()),
1076  ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName()));
1077 
1078 #endif
1079 
1080  if (solids[0].isValid() && solids[1].isValid()) {
1081  Transform3D trafo;
1082  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1083  boolean = TYPE(solids[0], solids[1], trafo);
1084  } else {
1085  // Register it for later processing
1086  Transform3D trafo;
1087  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1088  ns.context()->unresolvedShapes.emplace(nam,
1089  DDParsingContext::BooleanShape<TYPE>(solidName[0], solidName[1], trafo));
1090  }
1091  if (!boolean.isValid()) {
1092  // Delay processing the shape
1093  ns.context()->shapes.emplace(nam, dd4hep::Solid(nullptr));
1094  } else
1095  ns.addSolid(nam, boolean);
1096 }

References cms::DDNamespace::addSolid(), HltBtagPostValidation_cff::c, cms::DDNamespace::context(), DD_CMU, DEBUG, cms::DDParsingContext::debug_placements, cms::DDParsingContext::description, MillePedeFileConverter_cfg::e, Skims_PA_cff::name, cms::DDParsingContext::shapes, cms::DDNamespace::solid(), runonSM::TYPE, and cms::DDParsingContext::unresolvedShapes.

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

1852  {
1853  while (first != last) {
1854  const auto pos = std::find_first_of(first, last, s_first, s_last);
1855  binary_op(first, pos);
1856  if (pos == last)
1857  break;
1858  first = std::next(pos);
1859  }
1860 }

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

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

2052  {
2053  xml_elt_t dddef(element);
2054  if (dddef) {
2055  cms::DDParsingContext context(det);
2056  cms::DDNamespace ns(context);
2057  ns.addConstantNS("world_x", "101*m", "number");
2058  ns.addConstantNS("world_y", "101*m", "number");
2059  ns.addConstantNS("world_z", "450*m", "number");
2060  ns.addConstantNS("Air", "materials:Air", "string");
2061  ns.addConstantNS("Vacuum", "materials:Vacuum", "string");
2062  ns.addConstantNS("fm", "1e-12*m", "number");
2063  ns.addConstantNS("mum", "1e-6*m", "number");
2064 
2065  string fname = xml::DocumentHandler::system_path(element);
2066  bool open_geometry = dddef.hasChild(DD_CMU(open_geometry)) ? dddef.child(DD_CMU(open_geometry)) : true;
2067  bool close_geometry = dddef.hasChild(DD_CMU(close_geometry)) ? dddef.hasChild(DD_CMU(close_geometry)) : true;
2068 
2069  xml_coll_t(dddef, _U(debug)).for_each(Converter<debug>(det, &context));
2070 
2071  // Here we define the order how XML elements are processed.
2072  // Be aware of dependencies. This can only defined once.
2073  // At the end it is a limitation of DOM....
2074  printout(INFO, "DD4CMS", "+++ Processing the CMS detector description %s", fname.c_str());
2075 
2076  xml::Document doc;
2077  Converter<print_xml_doc> print_doc(det, &context);
2078  try {
2079  DDRegistry res;
2080  res.unresolvedConst.reserve(2000);
2081  res.originalConst.reserve(6000);
2082  print_doc((doc = dddef.document()).root());
2083  xml_coll_t(dddef, DD_CMU(ConstantsSection)).for_each(Converter<ConstantsSection>(det, &context, &res));
2084  xml_coll_t(dddef, DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
2085  xml_coll_t(dddef, DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
2086 
2087  xml_coll_t(dddef, DD_CMU(IncludeSection)).for_each(DD_CMU(Include), Converter<include_load>(det, &context, &res));
2088 
2089  for (xml::Document d : res.includes) {
2090  print_doc((doc = d).root());
2091  Converter<include_constants>(det, &context, &res)((doc = d).root());
2092  }
2093  // Before we continue, we have to resolve all constants NOW!
2094  Converter<DDRegistry>(det, &context, &res)(dddef);
2095  {
2096  DDVectorsMap* registry = context.description.extension<DDVectorsMap>();
2097 
2098  printout(context.debug_constants ? ALWAYS : DEBUG,
2099  "DD4CMS",
2100  "+++ RESOLVING %ld Vectors.....",
2101  context.unresolvedVectors.size());
2102 
2103  while (!context.unresolvedVectors.empty()) {
2104  for (auto it = context.unresolvedVectors.begin(); it != context.unresolvedVectors.end();) {
2105  std::vector<double> result;
2106  for (const auto& i : it->second) {
2107  result.emplace_back(dd4hep::_toDouble(i));
2108  }
2109  registry->insert({it->first, result});
2110  // All components are resolved
2111  it = context.unresolvedVectors.erase(it);
2112  }
2113  }
2114  }
2115  // Now we can process the include files one by one.....
2116  for (xml::Document d : res.includes) {
2117  print_doc((doc = d).root());
2118  xml_coll_t(d.root(), DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
2119  }
2120  {
2121  printout(context.debug_materials ? ALWAYS : DEBUG,
2122  "DD4CMS",
2123  "+++ RESOLVING %ld unknown material constituents.....",
2124  context.unresolvedMaterials.size());
2125 
2126  // Resolve referenced materials (if any)
2127 
2128  while (!context.unresolvedMaterials.empty()) {
2129  for (auto it = context.unresolvedMaterials.begin(); it != context.unresolvedMaterials.end();) {
2130  auto const& name = it->first;
2131  std::vector<bool> valid;
2132 
2133  printout(context.debug_materials ? ALWAYS : DEBUG,
2134  "DD4CMS",
2135  "+++ [%06ld] ---------- %s",
2136  context.unresolvedMaterials.size(),
2137  name.c_str());
2138 
2139  auto mat = ns.material(name);
2140  for (auto& mit : it->second) {
2141  printout(context.debug_materials ? ALWAYS : DEBUG,
2142  "DD4CMS",
2143  "+++ component %-48s Fraction: %.6f",
2144  mit.name.c_str(),
2145  mit.fraction);
2146  auto fmat = ns.material(mit.name);
2147  if (nullptr != fmat.ptr()) {
2148  if (mat.ptr()->GetMaterial()->IsMixture()) {
2149  valid.emplace_back(true);
2150  static_cast<TGeoMixture*>(mat.ptr()->GetMaterial())
2151  ->AddElement(fmat.ptr()->GetMaterial(), mit.fraction);
2152  }
2153  }
2154  }
2155  // All components are resolved
2156  if (valid.size() == it->second.size())
2157  it = context.unresolvedMaterials.erase(it);
2158  else
2159  ++it;
2160  }
2161  // Do it again if there are unresolved
2162  // materials left after this pass
2163  }
2164  }
2165  if (open_geometry) {
2166  det.init();
2167  ns.addVolume(det.worldVolume());
2168  }
2169  for (xml::Document d : res.includes) {
2170  print_doc((doc = d).root());
2171  xml_coll_t(d.root(), DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
2172  }
2173  for (xml::Document d : res.includes) {
2174  print_doc((doc = d).root());
2175  xml_coll_t(d.root(), DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2176  }
2177  for (xml::Document d : res.includes) {
2178  print_doc((doc = d).root());
2179  xml_coll_t(d.root(), DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2180  }
2181  for (xml::Document d : res.includes) {
2182  print_doc((doc = d).root());
2183  xml_coll_t(d.root(), DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2184  }
2185  for (xml::Document d : res.includes) {
2186  print_doc((doc = d).root());
2187  xml_coll_t(d.root(), DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2188  }
2189  for (xml::Document d : res.includes) {
2190  print_doc((doc = d).root());
2191  xml_coll_t(d.root(), DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2192  }
2193 
2195  for (xml::Document d : res.includes)
2196  Converter<include_unload>(det, &context, &res)(d.root());
2197 
2198  print_doc((doc = dddef.document()).root());
2199  // Now process the actual geometry items
2200  xml_coll_t(dddef, DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2201  {
2202  // Before we continue, we have to resolve all shapes NOW!
2203  // Note: This only happens in a legacy DB payloads where
2204  // boolean shapes can be defined before thier
2205  // component shapes
2206 
2207  while (!context.unresolvedShapes.empty()) {
2208  for (auto it = context.unresolvedShapes.begin(); it != context.unresolvedShapes.end();) {
2209  auto const& name = it->first;
2210  auto const& aname = std::visit([](auto&& arg) -> std::string { return arg.firstSolidName; }, it->second);
2211  auto const& bname = std::visit([](auto&& arg) -> std::string { return arg.secondSolidName; }, it->second);
2212 
2213  auto const& ait = context.shapes.find(aname);
2214  if (ait->second.isValid()) {
2215  auto const& bit = context.shapes.find(bname);
2216  if (bit->second.isValid()) {
2217  dd4hep::Solid shape =
2218  std::visit([&ait, &bit](auto&& arg) -> dd4hep::Solid { return arg.make(ait->second, bit->second); },
2219  it->second);
2220  context.shapes[name] = shape;
2221  it = context.unresolvedShapes.erase(it);
2222  } else
2223  ++it;
2224  } else
2225  ++it;
2226  }
2227  }
2228  }
2229  xml_coll_t(dddef, DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2230  xml_coll_t(dddef, DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2231  xml_coll_t(dddef, DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2232  xml_coll_t(dddef, DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2233  } catch (const exception& e) {
2234  printout(ERROR, "DD4CMS", "Exception while processing xml source:%s", doc.uri().c_str());
2235  printout(ERROR, "DD4CMS", "----> %s", e.what());
2236  throw;
2237  }
2238 
2240  if (close_geometry) {
2241  Volume wv = det.worldVolume();
2242  Volume geomv = ns.volume("cms:OCMS", false);
2243  if (geomv.isValid())
2244  wv.placeVolume(geomv, 1);
2245  Volume mfv = ns.volume("cmsMagneticField:MAGF", false);
2246  if (mfv.isValid())
2247  wv.placeVolume(mfv, 1);
2248  Volume mfv1 = ns.volume("MagneticFieldVolumes:MAGF", false);
2249  if (mfv1.isValid())
2250  wv.placeVolume(mfv1, 1);
2251 
2252  // Can not deal with reflections without closed geometry
2253  det.manager().CloseGeometry();
2254 
2255  det.endDocument();
2256  }
2257  printout(INFO, "DDDefinition", "+++ Finished processing %s", fname.c_str());
2258  return 1;
2259  }
2260  except("DDDefinition", "+++ FAILED to process unknown DOM tree [Invalid Handle]");
2261  return 0;
2262 }

References cms::DDNamespace::addConstantNS(), cms::DDNamespace::addVolume(), HLT_FULL_cff::Algorithm, ztail::d, DD_CMU, debug, DEBUG, cms::DDParsingContext::debug_constants, cms::DDParsingContext::debug_materials, cms::DDParsingContext::description, common_cff::doc, MillePedeFileConverter_cfg::e, dqm::qstatus::ERROR, cppFunctionSkipper::exception, alignmentValidation::fname, mps_fire::i, unpackBuffers-CaloStage2::INFO, cms::DDNamespace::material(), Skims_PA_cff::name, mps_fire::result, cms::DDParsingContext::shapes, AlCaHLTBitMon_QueryRunRegistry::string, cms::DDParsingContext::unresolvedMaterials, cms::DDParsingContext::unresolvedShapes, cms::DDParsingContext::unresolvedVectors, RunInfoPI::valid, and cms::DDNamespace::volume().

Variable Documentation

◆ includes

std::vector<xml::Document> includes

◆ originalConst

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

Definition at line 56 of file DDDefinitions2Objects.cc.

◆ unresolvedConst

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

Definition at line 55 of file DDDefinitions2Objects.cc.

DDAxes::y
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:428
cms::DDParsingContext
Definition: DDParsingContext.h:13
cms::DDNamespace
Definition: DDNamespace.h:16
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.Algorithm
Algorithm
Definition: HLT_FULL_cff.py:9543
DDAxes::x
dqmdumpme.first
first
Definition: dqmdumpme.py:55
dqmdumpme.last
last
Definition: dqmdumpme.py:56
debug
#define debug
Definition: HDRShower.cc:19
DDAxes::undefined
DDAxes::z
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
unpackBuffers-CaloStage2.INFO
INFO
Definition: unpackBuffers-CaloStage2.py:170
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
cms::DDParsingContext::BooleanShape
Definition: DDParsingContext.h:36
root
Definition: RooFitFunction.h:10
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
res
Definition: Electron.h:6
DDAxes::phi
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
runonSM.TYPE
TYPE
Definition: runonSM.py:21
cms::DDVectorsMap
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:14
DD_CMU
#define DD_CMU(a)
Definition: DDXMLTags.h:183
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DEBUG
#define DEBUG
Definition: DMRChecker.cc:121
funct::arg
A arg
Definition: Factorize.h:31
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
dqm::qstatus::ERROR
static const int ERROR
Definition: MonitorElement.h:54
cms::DDParsingContext::description
dd4hep::Detector & description
Definition: DDParsingContext.h:68
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37