DDCompactView

Macros

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
#ifndef DETECTOR_DESCRIPTION_CORE_DD_COMPACT_VIEW_H
#define DETECTOR_DESCRIPTION_CORE_DD_COMPACT_VIEW_H

#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>

#include "DetectorDescription/Core/interface/DDRotationMatrix.h"
#include "DetectorDescription/Core/interface/DDTranslation.h"
#include "DetectorDescription/Core/interface/Store.h"
#include "DetectorDescription/Core/interface/DDLogicalPart.h"
#include "DetectorDescription/Core/interface/DDPosData.h"
#include "DetectorDescription/Core/interface/DDTransform.h"
#include "DataFormats/Math/interface/Graph.h"
#include "DataFormats/Math/interface/GraphWalker.h"

class DDCompactViewImpl;
class DDDivision;
class DDName;
struct DDPosData;

namespace DDI {
  class LogicalPart;
  class Material;
  class Solid;
  class Specific;
}  // namespace DDI

/**
  Navigation through the compact view of the detector ...
*/
//MEC: these comments are kept from original... Will we ever do this? don't think so.
//FIXME: DDCompactView: check for proper acyclic directed graph structure!!
//FIXME:
//FIXME:         X          [A-X] ... LogicalPart
//FIXME:        / \             | ... PosPart (directed parten to child)
//FIXME:       A   A
//FIXME:       |   |
//FIXME:       B   C
//FIXME:
//FIXME:    THIS IS NOT ALLOWED, but currently can be specified using DDL ....
//FIXME:

//! Compact representation of the geometrical detector hierarchy
/** A DDCompactView represents the detector as an acyclic directed multigraph.
    The nodes are instances of DDLogicalPart while the edges are pointers to
    DDPosData. Edges are directed from parent-node to child-node. 
    Edges represented by DDPosData are the relative translation and rotation
    accompanied by a copy-number of the child-node towards the parent-node.
    
    One node is explicitly marked as the root node. It is the DDLogicalPart which
    defines the base coordinate system for the detector. All subdetectors are
    directly or inderectly positioned inside the root-node. 
    
    Example:
    
    The figureshows a compact-view graph consisting of 16 DDLogicalParts 
    interconnected by 20 edges represented by pointers to DDPosData.
    \image html compact-view.gif
    \image latex compact-view.eps
    
    The compact-view also serves as base for calculating nodes in the expanded
    view. Paths through the compact-view can be viewed as nodes in the expanded-view
    (expansion of an acyclic directed multigraph into a tree). In the figure there are
    5 different paths from CMS to Module2 (e.g. CMS-Pos1->Ecal-Pos4->EEndcap-Pos21->Module2)
    thus there will be 5 nodes of Module2 in the expanded view.

MEC:
    There has been a re-purposing of the DDCompactView to not only hold the 
    representation described above (in detail this is the DDCompactViewImpl)
    but also own the memory of the stores refered to by the graph.

    DDCompactView now owns the DDMaterial, DDSpecific, DDLogicalPart,
    DDRotation, DDSolid and etc.  Removal of the global one-and-only 
    stores, methods and details such as DDRoot will mean that all of
    these will be accessed via the DDCompactView.
*/
class DDCompactView {
public:
  using Graph = math::Graph<DDLogicalPart, DDPosData*>;
  using GraphWalker = math::GraphWalker<DDLogicalPart, DDPosData*>;
  using Vectors = std::unordered_map<std::string, std::vector<double>>;

  //! Creates a compact-view
  explicit DDCompactView();

  //! Creates a compact-view using a different root of the geometry hierarchy
  explicit DDCompactView(const DDName&);

  ~DDCompactView();

  //! Creates a compact-view using a different root of the geometry hierarchy.
  // NOTE: It cannot be used to modify the stores if they are locked.
  explicit DDCompactView(const DDLogicalPart& rootnodedata);

  //! Provides read-only access to the data structure of the compact-view.
  const Graph& graph() const;
  GraphWalker walker() const;

  //! returns the DDLogicalPart representing the root of the geometrical hierarchy
  const DDLogicalPart& root() const;

  //! The absolute position of the world
  const DDPosData* worldPosition() const;

  //! returns an empty container if not found
  std::vector<double> const& vector(std::string_view iKey) const;

  void position(const DDLogicalPart& self,
                const DDLogicalPart& parent,
                const std::string& copyno,
                const DDTranslation& trans,
                const DDRotation& rot,
                const DDDivision* div = nullptr);

  void position(const DDLogicalPart& self,
                const DDLogicalPart& parent,
                int copyno,
                const DDTranslation& trans,
                const DDRotation& rot,
                const DDDivision* div = nullptr);

  void setRoot(const DDLogicalPart& root);

  void lockdown();

private:
  void swap(DDCompactView&);

  std::unique_ptr<DDCompactViewImpl> rep_;
  std::unique_ptr<DDPosData> worldpos_;

  DDI::Store<DDName, std::unique_ptr<DDI::Material>> matStore_;
  DDI::Store<DDName, std::unique_ptr<DDI::Solid>> solidStore_;
  DDI::Store<DDName, std::unique_ptr<DDI::LogicalPart>> lpStore_;
  DDI::Store<DDName, std::unique_ptr<DDI::Specific>> specStore_;
  DDI::Store<DDName, std::unique_ptr<DDRotationMatrix>> rotStore_;

  Vectors vectors_;
};

#endif