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

1695 { 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 1048 of file DDDefinitions2Objects.cc.

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

References cms::DDNamespace::addSolid(), c, cms::DDNamespace::context(), DD_CMU, DEBUG, cms::DDParsingContext::debug_placements, cms::DDParsingContext::description, MillePedeFileConverter_cfg::e, sistrip::SpyUtilities::isValid(), 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 1856 of file DDDefinitions2Objects.cc.

1856  {
1857  while (first != last) {
1858  const auto pos = std::find_first_of(first, last, s_first, s_last);
1859  binary_op(first, pos);
1860  if (pos == last)
1861  break;
1862  first = std::next(pos);
1863  }
1864 }

References 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 2056 of file DDDefinitions2Objects.cc.

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

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, cms::DDNamespace::volume(), and gpuVertexFinder::wv.

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:9477
DDAxes::x
gpuVertexFinder::wv
float *__restrict__ wv
Definition: gpuFitVertices.h:27
dqmdumpme.last
last
Definition: dqmdumpme.py:56
debug
#define debug
Definition: HDRShower.cc:19
DDAxes::undefined
DDAxes::z
sistrip::SpyUtilities::isValid
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Definition: SiStripSpyUtilities.cc:124
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
unpackBuffers-CaloStage2.INFO
INFO
Definition: unpackBuffers-CaloStage2.py:169
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
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:119
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
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
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