ddcms_det_element_DDCMS_rpdalgo_DDRPDPosition

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DetectorDescription/Core/interface/DDSplit.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DD4hep/DetFactoryHelper.h"

#include <string>
#include <vector>
#include <sstream>

//#define EDM_ML_DEBUG

static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
  cms::DDNamespace ns(ctxt, e, true);
  cms::DDAlgoArguments args(ctxt, e);

  const auto& xpos = args.value<std::vector<double> >("positionX");
  const auto& ypos = args.value<double>("positionY");
  const auto& zpos = args.value<double>("positionZ");
  const auto& childName = args.value<std::string>("ChildName");

  dd4hep::Volume parent = ns.volume(args.parentName());
  dd4hep::Volume child = ns.volume(ns.prepend(childName));
#ifdef EDM_ML_DEBUG
  edm::LogVerbatim("ForwardGeom") << "DDRPDPosition: Parameters for positioning-- " << xpos.size() << " copies of "
                                  << child.name() << " to be positioned inside " << parent.name() << " at y = " << ypos
                                  << ", z = " << zpos << " and at x = (";
  std::ostringstream st1;
  for (const auto& x : xpos)
    st1 << x << " ";
  edm::LogVerbatim("ForwardGeom") << st1.str() << ")";
#endif

  for (unsigned int jj = 0; jj < xpos.size(); jj++) {
    dd4hep::Position tran(xpos[jj], ypos, zpos);
    parent.placeVolume(child, jj + 1, tran);
#ifdef EDM_ML_DEBUG
    edm::LogVerbatim("ForwardGeom") << "DDRPDPosition: " << child.name() << " number " << jj + 1 << " positioned in "
                                    << parent.name() << " at " << tran << " with no rotation";
#endif
  }
  return cms::s_executed;
}

// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(DDCMS_rpdalgo_DDRPDPosition, algorithm)