CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

enum DDAxes
strong
Enumerator
x 
y 
z 
rho 
radial3D 
phi 
undefined 

Definition at line 1796 of file DDDefinitions2Objects.cc.

1796 { x = 1, y = 2, z = 3, rho = 1, phi = 2, undefined };
float float float z
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39

Function Documentation

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(), c, visDQMUpload::context, cms::DDNamespace::context(), DD_CMU, DEBUG, cms::DDParsingContext::debug_placements, cms::DDParsingContext::description, alignCSCRings::e, sistrip::SpyUtilities::isValid(), cms::DDParsingContext::shapes, cms::DDNamespace::solid(), runonSM::TYPE, and cms::DDParsingContext::unresolvedShapes.

1134  {
1135  cms::DDNamespace ns(context);
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  }
1181  if (!boolean.isValid()) {
1182  // Delay processing the shape
1183  ns.context()->shapes.emplace(nam, dd4hep::Solid(nullptr));
1184  } else
1185  ns.addSolid(nam, boolean);
1186 }
const edm::EventSetup & c
list TYPE
Definition: runonSM.py:21
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
dd4hep::Detector & description
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 1956 of file DDDefinitions2Objects.cc.

References GetRecoTauVFromDQM_MC_cff::next.

1956  {
1957  while (first != last) {
1958  const auto pos = std::find_first_of(first, last, s_first, s_last);
1959  binary_op(first, pos);
1960  if (pos == last)
1961  break;
1962  first = std::next(pos);
1963  }
1964 }
tuple last
Definition: dqmdumpme.py:56
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 2156 of file DDDefinitions2Objects.cc.

References visDQMUpload::context, ztail::d, DD_CMU, debug, dqm::qstatus::ERROR, cppFunctionSkipper::exception, mps_fire::i, dtDQMClient_cfg::INFO, mergeVDriftHistosByStation::name, mps_fire::result, AlCaHLTBitMon_QueryRunRegistry::string, dqm::qstatus::WARNING, and gpuVertexFinder::wv.

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

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

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

Variable Documentation

std::vector<xml::Document> includes
std::unordered_map<std::string, std::string> originalConst

Definition at line 56 of file DDDefinitions2Objects.cc.

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

Definition at line 55 of file DDDefinitions2Objects.cc.