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

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

Function Documentation

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

Definition at line 1129 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, dqm::qstatus::ERROR, sistrip::SpyUtilities::isValid(), cms::DDParsingContext::shapes, cms::DDNamespace::solid(), runonSM::TYPE, and cms::DDParsingContext::unresolvedShapes.

1129  {
1130  cms::DDNamespace ns(context);
1131  xml_dim_t e(element);
1132  string nam = e.nameStr();
1133  string solidName[2];
1134  Solid solids[2];
1135  Solid boolean;
1136  int cnt = 0;
1137  if (e.hasChild(DD_CMU(rSolid))) {
1138  for (xml_coll_t c(element, DD_CMU(rSolid)); cnt < 2 && c; ++c, ++cnt) {
1139  solidName[cnt] = c.attr<string>(_U(name));
1140  solids[cnt] = ns.solid(c.attr<string>(_U(name)));
1141  }
1142  } else {
1143  solidName[0] = e.attr<string>(DD_CMU(firstSolid));
1144  if ((solids[0] = ns.solid(e.attr<string>(DD_CMU(firstSolid)))).isValid())
1145  ++cnt;
1146  solidName[1] = e.attr<string>(DD_CMU(secondSolid));
1147  if ((solids[1] = ns.solid(e.attr<string>(DD_CMU(secondSolid)))).isValid())
1148  ++cnt;
1149  }
1150  if (cnt != 2) {
1151  except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt);
1152  }
1153 
1154 #ifdef EDM_ML_DEBUG
1155 
1156  printout(ns.context()->debug_placements ? ALWAYS : DEBUG,
1157  "DD4CMS",
1158  "+++ BooleanSolid: %s Left: %-32s Right: %-32s",
1159  nam.c_str(),
1160  ((solids[0].ptr() == nullptr) ? solidName[0].c_str() : solids[0]->GetName()),
1161  ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName()));
1162 
1163 #endif
1164 
1165  if (solids[0].isValid() && solids[1].isValid()) {
1166  Transform3D trafo;
1167  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1168  boolean = TYPE(solids[0], solids[1], trafo);
1169  } else {
1170  // Register it for later processing
1171  Transform3D trafo;
1172  Converter<DDLTransform3D>(context->description, context, &trafo)(element);
1173  ns.context()->unresolvedShapes.emplace(nam,
1174  DDParsingContext::BooleanShape<TYPE>(solidName[0], solidName[1], trafo));
1175  if (solids[0].isValid() == false) {
1176  printout(ERROR, "DD4CMS", "++ Solid not defined yet: %s", solidName[0].c_str());
1177  }
1178  if (solids[1].isValid() == false) {
1179  printout(ERROR, "DD4CMS", "++ Solid not defined yet: %s", solidName[1].c_str());
1180  }
1181  printout(ERROR, "DD4CMS", "++ Re-order XML files to prevent references to undefined solids");
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 }
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
static const int ERROR
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.

References GetRecoTauVFromDQM_MC_cff::next.

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 }
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 2158 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, and gpuVertexFinder::wv.

2158  {
2159  xml_elt_t dddef(element);
2160  if (dddef) {
2161  cms::DDParsingContext& context = *det.extension<DDParsingContext>();
2162  cms::DDNamespace ns(context);
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  if (open_geometry) {
2225  det.init();
2226  ns.addVolume(det.worldVolume());
2227  }
2228  for (xml::Document d : res.includes) {
2229  print_doc((doc = d).root());
2230  xml_coll_t(d.root(), DD_CMU(RotationSection)).for_each(Converter<RotationSection>(det, &context));
2231  }
2232  for (xml::Document d : res.includes) {
2233  print_doc((doc = d).root());
2234  xml_coll_t(d.root(), DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2235  }
2236  for (xml::Document d : res.includes) {
2237  print_doc((doc = d).root());
2238  xml_coll_t(d.root(), DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2239  }
2240  for (xml::Document d : res.includes) {
2241  print_doc((doc = d).root());
2242  xml_coll_t(d.root(), DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2243  }
2244  for (xml::Document d : res.includes) {
2245  print_doc((doc = d).root());
2246  xml_coll_t(d.root(), DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2247  }
2248  for (xml::Document d : res.includes) {
2249  print_doc((doc = d).root());
2250  xml_coll_t(d.root(), DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2251  }
2252 
2254  for (xml::Document d : res.includes)
2255  Converter<include_unload>(det, &context, &res)(d.root());
2256 
2257  print_doc((doc = dddef.document()).root());
2258  // Now process the actual geometry items
2259  xml_coll_t(dddef, DD_CMU(SolidSection)).for_each(Converter<SolidSection>(det, &context));
2260  {
2261  // Before we continue, we have to resolve all shapes NOW!
2262  // Note: This only happens in a legacy DB payloads where
2263  // boolean shapes can be defined before thier
2264  // component shapes
2265 
2266  while (!context.unresolvedShapes.empty()) {
2267  for (auto it = context.unresolvedShapes.begin(); it != context.unresolvedShapes.end();) {
2268  auto const& name = it->first;
2269  auto const& aname = std::visit([](auto&& arg) -> std::string { return arg.firstSolidName; }, it->second);
2270  auto const& bname = std::visit([](auto&& arg) -> std::string { return arg.secondSolidName; }, it->second);
2271 
2272  auto const& ait = context.shapes.find(aname);
2273  if (ait->second.isValid()) {
2274  auto const& bit = context.shapes.find(bname);
2275  if (bit->second.isValid()) {
2276  dd4hep::Solid shape =
2277  std::visit([&ait, &bit](auto&& arg) -> dd4hep::Solid { return arg.make(ait->second, bit->second); },
2278  it->second);
2279  context.shapes[name] = shape;
2280  it = context.unresolvedShapes.erase(it);
2281  } else
2282  ++it;
2283  } else
2284  ++it;
2285  }
2286  }
2287  }
2288  xml_coll_t(dddef, DD_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det, &context));
2289  xml_coll_t(dddef, DD_CMU(Algorithm)).for_each(Converter<DDLAlgorithm>(det, &context));
2290  xml_coll_t(dddef, DD_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det, &context));
2291  xml_coll_t(dddef, DD_CMU(SpecParSection)).for_each(Converter<SpecParSection>(det, &context));
2292  } catch (const exception& e) {
2293  printout(ERROR, "DD4CMS", "Exception while processing xml source:%s", doc.uri().c_str());
2294  printout(ERROR, "DD4CMS", "----> %s", e.what());
2295  throw;
2296  }
2297 
2299  if (close_geometry) {
2300  Volume wv = det.worldVolume();
2301  Volume geomv = ns.volume("cms:OCMS", false);
2302  if (geomv.isValid())
2303  wv.placeVolume(geomv, 1);
2304  Volume mfv = ns.volume("cmsMagneticField:MAGF", false);
2305  if (mfv.isValid())
2306  wv.placeVolume(mfv, 1);
2307  Volume mfv1 = ns.volume("MagneticFieldVolumes:MAGF", false);
2308  if (mfv1.isValid())
2309  wv.placeVolume(mfv1, 1);
2310 
2311  // Can not deal with reflections without closed geometry
2312  det.manager().CloseGeometry();
2313 
2314  det.endDocument();
2315  }
2316  printout(INFO, "DDDefinition", "+++ Finished processing %s", fname.c_str());
2317  return 1;
2318  }
2319  except("DDDefinition", "+++ FAILED to process unknown DOM tree [Invalid Handle]");
2320  return 0;
2321 }
std::unordered_map< std::string, std::vector< double >> DDVectorsMap
Definition: DDNamespace.h:20
float *__restrict__ wv
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 867 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().

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

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

Definition at line 56 of file DDDefinitions2Objects.cc.