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

1798 { 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 1136 of file DDDefinitions2Objects.cc.

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

References cms::DDNamespace::addSolid(), c, visDQMUpload::context, cms::DDNamespace::context(), DD_CMU, DEBUG, cms::DDParsingContext::debug_placements, 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 1958 of file DDDefinitions2Objects.cc.

1958  {
1959  while (first != last) {
1960  const auto pos = std::find_first_of(first, last, s_first, s_last);
1961  binary_op(first, pos);
1962  if (pos == last)
1963  break;
1964  first = std::next(pos);
1965  }
1966 }

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

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

References visDQMUpload::context, ztail::d, DD_CMU, debug, DEBUG, boostedTaus_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, AlCaHLTBitMon_QueryRunRegistry::string, RunInfoPI::valid, and gpuVertexFinder::wv.

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

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

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

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.

cms::DDNamespace::assembly
dd4hep::Assembly assembly(const std::string &name, bool exception=true) const
Definition: DDNamespace.cc:247
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HLT_FULL_cff.Class
Class
Definition: HLT_FULL_cff.py:8399
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
boostedTaus_cff.doc
doc
Definition: boostedTaus_cff.py:20
cms::DDParsingContext
Definition: DDParsingContext.h:14
cms::DDNamespace
Definition: DDNamespace.h:22
pos
Definition: PixelAliasList.h:18
cms::DDParsingContext::debug_placements
bool debug_placements
Definition: DDParsingContext.h:71
DDAxes::x
gpuVertexFinder::wv
float *__restrict__ wv
Definition: gpuFitVertices.h:27
cms::PlacedVolume
dd4hep::PlacedVolume PlacedVolume
Definition: DDFilteredView.h:48
l1tVertexFinder::Algorithm
Algorithm
Definition: AlgoSettings.h:12
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
visDQMUpload.context
context
Definition: visDQMUpload.py:37
dqmdumpme.last
last
Definition: dqmdumpme.py:56
debug
#define debug
Definition: HDRShower.cc:19
DDAxes::undefined
DDAxes::z
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
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:125
DDAxes::rho
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:44
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
root
Definition: RooFitFunction.h:10
res
Definition: Electron.h:6
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDAxes::phi
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
cms::DDNamespace::context
DDParsingContext *const context() const
Definition: DDNamespace.h:76
runonSM.TYPE
TYPE
Definition: runonSM.py:21
cms::DDVectorsMap
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
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:56
dqm::qstatus::ERROR
static const int ERROR
Definition: MonitorElement.h:54
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37