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 <utility>
#include "tbb/concurrent_unordered_map.h"
#include "tbb/concurrent_vector.h"

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

Enumeration Type Documentation

◆ DDAxes

enum DDAxes
strong
Enumerator
rho 
radial3D 
phi 
undefined 

Definition at line 1539 of file DDDefinitions2Objects.cc.

1539 { 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 1010 of file DDDefinitions2Objects.cc.

1010  {
1011  cms::DDNamespace ns(context);
1012  xml_dim_t e(element);
1013  string nam = e.nameStr();
1014  string solidName[2];
1015  Solid solids[2];
1016  Solid boolean;
1017  int cnt = 0;
1018  if (e.hasChild(DD_CMU(rSolid))) {
1019  for (xml_coll_t c(element, DD_CMU(rSolid)); cnt < 2 && c; ++c, ++cnt) {
1020  solidName[cnt] = c.attr<string>(_U(name));
1021  solids[cnt] = ns.solid(c.attr<string>(_U(name)));
1022  }
1023  } else {
1024  solidName[0] = e.attr<string>(DD_CMU(firstSolid));
1025  if ((solids[0] = ns.solid(e.attr<string>(DD_CMU(firstSolid)))).isValid())
1026  ++cnt;
1027  solidName[1] = e.attr<string>(DD_CMU(secondSolid));
1028  if ((solids[1] = ns.solid(e.attr<string>(DD_CMU(secondSolid)))).isValid())
1029  ++cnt;
1030  }
1031  if (cnt != 2) {
1032  except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt);
1033  }
1034 
1035  printout(ns.context()->debug_placements ? ALWAYS : DEBUG,
1036  "DD4CMS",
1037  "+++ BooleanSolid: %s Left: %-32s Right: %-32s",
1038  nam.c_str(),
1039  ((solids[0].ptr() == nullptr) ? solidName[0].c_str() : solids[0]->GetName()),
1040  ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName()));
1041 
1042  if (solids[0].isValid() && solids[1].isValid()) {
1043  Transform3D trafo;
1044  Converter<DDLTransform3D>(*context->description, context, &trafo)(element);
1045  boolean = TYPE(solids[0], solids[1], trafo);
1046  } else {
1047  // Register it for later processing
1048  Transform3D trafo;
1049  Converter<DDLTransform3D>(*context->description, context, &trafo)(element);
1050  ns.context()->unresolvedShapes.emplace(nam,
1051  DDParsingContext::BooleanShape<TYPE>(solidName[0], solidName[1], trafo));
1052  }
1053  if (!boolean.isValid()) {
1054  // Delay processing the shape
1055  ns.context()->shapes.emplace(nam, dd4hep::Solid(nullptr));
1056  } else
1057  ns.addSolid(nam, boolean);
1058 }

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

1678  {
1679  while (first != last) {
1680  const auto pos = std::find_first_of(first, last, s_first, s_last);
1681  binary_op(first, pos);
1682  if (pos == last)
1683  break;
1684  first = std::next(pos);
1685  }
1686 }

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

1855  {
1856  cms::DDParsingContext context(&det);
1857  cms::DDNamespace ns(context);
1858  ns.addConstantNS("world_x", "101*m", "number");
1859  ns.addConstantNS("world_y", "101*m", "number");
1860  ns.addConstantNS("world_z", "450*m", "number");
1861  ns.addConstantNS("Air", "materials:Air", "string");
1862  ns.addConstantNS("Vacuum", "materials:Vacuum", "string");
1863  ns.addConstantNS("fm", "1e-12*m", "number");
1864  ns.addConstantNS("mum", "1e-6*m", "number");
1865 
1866  xml_elt_t dddef(element);
1867  string fname = xml::DocumentHandler::system_path(element);
1868  bool open_geometry = dddef.hasChild(DD_CMU(open_geometry)) ? dddef.child(DD_CMU(open_geometry)) : true;
1869  bool close_geometry = dddef.hasChild(DD_CMU(close_geometry)) ? dddef.hasChild(DD_CMU(close_geometry)) : true;
1870 
1871  xml_coll_t(dddef, _U(debug)).for_each(Converter<debug>(det, &context));
1872 
1873  // Here we define the order how XML elements are processed.
1874  // Be aware of dependencies. This can only defined once.
1875  // At the end it is a limitation of DOM....
1876  printout(INFO, "DD4CMS", "+++ Processing the CMS detector description %s", fname.c_str());
1877 
1878  xml::Document doc;
1879  Converter<print_xml_doc> print_doc(det, &context);
1880  try {
1881  DDRegistry res;
1882  print_doc((doc = dddef.document()).root());
1883  xml_coll_t(dddef, DD_CMU(DisabledAlgo)).for_each(Converter<disabled_algo>(det, &context, &res));
1884  xml_coll_t(dddef, DD_CMU(ConstantsSection)).for_each(Converter<ConstantsSection>(det, &context, &res));
1885  xml_coll_t(dddef, DD_CMU(VisSection)).for_each(Converter<vissection>(det, &context));
1886  xml_coll_t(dddef, DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
1887  xml_coll_t(dddef, DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
1888 
1889  xml_coll_t(dddef, DD_CMU(IncludeSection)).for_each(DD_CMU(Include), Converter<include_load>(det, &context, &res));
1890 
1891  for (xml::Document d : res.includes) {
1892  print_doc((doc = d).root());
1893  Converter<include_constants>(det, &context, &res)((doc = d).root());
1894  }
1895  // Before we continue, we have to resolve all constants NOW!
1896  Converter<DDRegistry>(det, &context, &res)(dddef);
1897  {
1898  DDVectorsMap* registry = context.description.load()->extension<DDVectorsMap>();
1899 
1900  printout(context.debug_constants ? ALWAYS : DEBUG,
1901  "DD4CMS",
1902  "+++ RESOLVING %ld Vectors.....",
1903  context.unresolvedVectors.size());
1904 
1905  while (!context.unresolvedVectors.empty()) {
1906  for (auto it = context.unresolvedVectors.begin(); it != context.unresolvedVectors.end();) {
1907  auto const& name = it->first;
1908  tbb::concurrent_vector<double> result;
1909  for (const auto& i : it->second) {
1910  result.emplace_back(dd4hep::_toDouble(i));
1911  }
1912  registry->insert({name, result});
1913  // All components are resolved
1914  it = context.unresolvedVectors.erase(it);
1915  }
1916  }
1917  }
1918  // Now we can process the include files one by one.....
1919  for (xml::Document d : res.includes) {
1920  print_doc((doc = d).root());
1921  xml_coll_t(d.root(), DD_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det, &context));
1922  }
1923  {
1924  printout(context.debug_materials ? ALWAYS : DEBUG,
1925  "DD4CMS",
1926  "+++ RESOLVING %ld unknown material constituents.....",
1927  context.unresolvedMaterials.size());
1928 
1929  // Resolve referenced materials (if any)
1930 
1931  while (!context.unresolvedMaterials.empty()) {
1932  for (auto it = context.unresolvedMaterials.begin(); it != context.unresolvedMaterials.end();) {
1933  auto const& name = it->first;
1934  std::vector<bool> valid;
1935 
1936  printout(context.debug_materials ? ALWAYS : DEBUG,
1937  "DD4CMS",
1938  "+++ [%06ld] ---------- %s",
1939  context.unresolvedMaterials.size(),
1940  name.c_str());
1941 
1942  auto mat = ns.material(name);
1943  for (auto& mit : it->second) {
1944  printout(context.debug_materials ? ALWAYS : DEBUG,
1945  "DD4CMS",
1946  "+++ component %-48s Fraction: %.6f",
1947  mit.name.c_str(),
1948  mit.fraction);
1949  auto fmat = ns.material(mit.name);
1950  if (nullptr != fmat.ptr()) {
1951  if (mat.ptr()->GetMaterial()->IsMixture()) {
1952  valid.emplace_back(true);
1953  static_cast<TGeoMixture*>(mat.ptr()->GetMaterial())->AddElement(fmat.ptr()->GetMaterial(), mit.fraction);
1954  }
1955  }
1956  }
1957  // All components are resolved
1958  if (valid.size() == it->second.size())
1959  it = context.unresolvedMaterials.erase(it);
1960  else
1961  ++it;
1962  }
1963  // Do it again if there are unresolved
1964  // materials left after this pass
1965  }
1966  }
1967  if (open_geometry) {
1968  context.geo_inited = true;
1969  det.init();
1970  ns.addVolume(det.worldVolume());
1971  }
1972  for (xml::Document d : res.includes) {
1973  print_doc((doc = d).root());
1974  xml_coll_t(d.root(), DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
1975  }
1976  for (xml::Document d : res.includes) {
1977  print_doc((doc = d).root());
1978  xml_coll_t(d.root(), DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
1979  }
1980  for (xml::Document d : res.includes) {
1981  print_doc((doc = d).root());
1982  xml_coll_t(d.root(), DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
1983  }
1984  for (xml::Document d : res.includes) {
1985  print_doc((doc = d).root());
1986  xml_coll_t(d.root(), DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
1987  }
1988  for (xml::Document d : res.includes) {
1989  print_doc((doc = d).root());
1990  xml_coll_t(d.root(), DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
1991  }
1992  for (xml::Document d : res.includes) {
1993  print_doc((doc = d).root());
1994  xml_coll_t(d.root(), DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
1995  }
1996 
1998  for (xml::Document d : res.includes)
1999  Converter<include_unload>(det, &context, &res)(d.root());
2000 
2001  print_doc((doc = dddef.document()).root());
2002  // Now process the actual geometry items
2003  xml_coll_t(dddef, DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2004  {
2005  // Before we continue, we have to resolve all shapes NOW!
2006  // Note: This only happens in a legacy DB payloads where
2007  // boolean shapes can be defined before thier
2008  // component shapes
2009 
2010  while (!context.unresolvedShapes.empty()) {
2011  for (auto it = context.unresolvedShapes.begin(); it != context.unresolvedShapes.end();) {
2012  auto const& name = it->first;
2013  auto const& aname = std::visit([](auto&& arg) -> std::string { return arg.firstSolidName; }, it->second);
2014  auto const& bname = std::visit([](auto&& arg) -> std::string { return arg.secondSolidName; }, it->second);
2015 
2016  auto const& ait = context.shapes.find(aname);
2017  if (ait->second.isValid()) {
2018  auto const& bit = context.shapes.find(bname);
2019  if (bit->second.isValid()) {
2020  dd4hep::Solid shape = std::visit(
2021  [&ait, &bit](auto&& arg) -> dd4hep::Solid { return arg.make(ait->second, bit->second); }, it->second);
2022  context.shapes[name] = shape;
2023  it = context.unresolvedShapes.erase(it);
2024  } else
2025  ++it;
2026  } else
2027  ++it;
2028  }
2029  }
2030  }
2031  xml_coll_t(dddef, DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2032  xml_coll_t(dddef, DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2033  xml_coll_t(dddef, DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2034  xml_coll_t(dddef, DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2035  } catch (const exception& e) {
2036  printout(ERROR, "DD4CMS", "Exception while processing xml source:%s", doc.uri().c_str());
2037  printout(ERROR, "DD4CMS", "----> %s", e.what());
2038  throw;
2039  }
2040 
2042  if (close_geometry) {
2043  Volume wv = det.worldVolume();
2044  Volume geomv = ns.volume("cms:OCMS", false);
2045  if (geomv.isValid())
2046  wv.placeVolume(geomv, 1);
2047  Volume mfv = ns.volume("cmsMagneticField:MAGF", false);
2048  if (mfv.isValid())
2049  wv.placeVolume(mfv, 1);
2050  Volume mfv1 = ns.volume("MagneticFieldVolumes:MAGF", false);
2051  if (mfv1.isValid())
2052  wv.placeVolume(mfv1, 1);
2053 
2054  det.endDocument();
2055  }
2056  printout(INFO, "DDDefinition", "+++ Finished processing %s", fname.c_str());
2057  return 1;
2058 }

References cms::DDNamespace::addConstantNS(), cms::DDNamespace::addVolume(), HLT_2018_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, cms::DDParsingContext::geo_inited, 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, validateGeometry_cfg::valid, and cms::DDNamespace::volume().

Variable Documentation

◆ allConst

tbb::concurrent_unordered_map<std::string, std::string> allConst

Definition at line 54 of file DDDefinitions2Objects.cc.

◆ includes

tbb::concurrent_vector<xml::Document> includes

◆ originalConst

tbb::concurrent_unordered_map<std::string, std::string> originalConst

Definition at line 54 of file DDDefinitions2Objects.cc.

◆ unresolvedConst

tbb::concurrent_unordered_map<std::string, std::string> unresolvedConst

Definition at line 54 of file DDDefinitions2Objects.cc.

DDAxes::y
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:355
cms::DDVectorsMap
tbb::concurrent_unordered_map< std::string, tbb::concurrent_vector< double > > DDVectorsMap
Definition: DDNamespace.h:14
cms::DDParsingContext
Definition: DDParsingContext.h:14
cms::DDNamespace
Definition: DDNamespace.h:16
pos
Definition: PixelAliasList.h:18
DDAxes::x
dqmdumpme.first
first
Definition: dqmdumpme.py:55
validateGeometry_cfg.valid
valid
Definition: validateGeometry_cfg.py:21
cms::DDParsingContext::description
std::atomic< dd4hep::Detector * > description
Definition: DDParsingContext.h:36
dqmdumpme.last
last
Definition: dqmdumpme.py:56
debug
#define debug
Definition: HDRShower.cc:19
DDAxes::undefined
DDAxes::z
HLT_2018_cff.Algorithm
Algorithm
Definition: HLT_2018_cff.py:8159
DEBUG
#define DEBUG
Definition: GeneralPurposeTrackAnalyzer.cc:79
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:45
cms::DDParsingContext::BooleanShape
Definition: DDParsingContext.h:44
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
DD_CMU
#define DD_CMU(a)
Definition: DDXMLTags.h:189
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
funct::arg
A arg
Definition: Factorize.h:36
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:303
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