Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:23

0001 #ifndef DETECTOR_DESCRIPTION_CORE_DD_COMPACT_VIEW_H
0002 #define DETECTOR_DESCRIPTION_CORE_DD_COMPACT_VIEW_H
0003 
0004 #include <cstddef>
0005 #include <memory>
0006 #include <string>
0007 #include <utility>
0008 #include <vector>
0009 #include <unordered_map>
0010 
0011 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0012 #include "DetectorDescription/Core/interface/DDTranslation.h"
0013 #include "DetectorDescription/Core/interface/Store.h"
0014 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0015 #include "DetectorDescription/Core/interface/DDPosData.h"
0016 #include "DetectorDescription/Core/interface/DDTransform.h"
0017 #include "DataFormats/Math/interface/Graph.h"
0018 #include "DataFormats/Math/interface/GraphWalker.h"
0019 
0020 class DDCompactViewImpl;
0021 class DDDivision;
0022 class DDName;
0023 struct DDPosData;
0024 
0025 namespace DDI {
0026   class LogicalPart;
0027   class Material;
0028   class Solid;
0029   class Specific;
0030 }  // namespace DDI
0031 
0032 /**
0033   Navigation through the compact view of the detector ...
0034 */
0035 //MEC: these comments are kept from original... Will we ever do this? don't think so.
0036 //FIXME: DDCompactView: check for proper acyclic directed graph structure!!
0037 //FIXME:
0038 //FIXME:         X          [A-X] ... LogicalPart
0039 //FIXME:        / \             | ... PosPart (directed parten to child)
0040 //FIXME:       A   A
0041 //FIXME:       |   |
0042 //FIXME:       B   C
0043 //FIXME:
0044 //FIXME:    THIS IS NOT ALLOWED, but currently can be specified using DDL ....
0045 //FIXME:
0046 
0047 //! Compact representation of the geometrical detector hierarchy
0048 /** A DDCompactView represents the detector as an acyclic directed multigraph.
0049     The nodes are instances of DDLogicalPart while the edges are pointers to
0050     DDPosData. Edges are directed from parent-node to child-node. 
0051     Edges represented by DDPosData are the relative translation and rotation
0052     accompanied by a copy-number of the child-node towards the parent-node.
0053     
0054     One node is explicitly marked as the root node. It is the DDLogicalPart which
0055     defines the base coordinate system for the detector. All subdetectors are
0056     directly or inderectly positioned inside the root-node. 
0057     
0058     Example:
0059     
0060     The figureshows a compact-view graph consisting of 16 DDLogicalParts 
0061     interconnected by 20 edges represented by pointers to DDPosData.
0062     \image html compact-view.gif
0063     \image latex compact-view.eps
0064     
0065     The compact-view also serves as base for calculating nodes in the expanded
0066     view. Paths through the compact-view can be viewed as nodes in the expanded-view
0067     (expansion of an acyclic directed multigraph into a tree). In the figure there are
0068     5 different paths from CMS to Module2 (e.g. CMS-Pos1->Ecal-Pos4->EEndcap-Pos21->Module2)
0069     thus there will be 5 nodes of Module2 in the expanded view.
0070 
0071 MEC:
0072     There has been a re-purposing of the DDCompactView to not only hold the 
0073     representation described above (in detail this is the DDCompactViewImpl)
0074     but also own the memory of the stores refered to by the graph.
0075 
0076     DDCompactView now owns the DDMaterial, DDSpecific, DDLogicalPart,
0077     DDRotation, DDSolid and etc.  Removal of the global one-and-only 
0078     stores, methods and details such as DDRoot will mean that all of
0079     these will be accessed via the DDCompactView.
0080 */
0081 class DDCompactView {
0082 public:
0083   using Graph = math::Graph<DDLogicalPart, DDPosData*>;
0084   using GraphWalker = math::GraphWalker<DDLogicalPart, DDPosData*>;
0085   using Vectors = std::unordered_map<std::string, std::vector<double>>;
0086 
0087   //! Creates a compact-view
0088   explicit DDCompactView();
0089 
0090   //! Creates a compact-view using a different root of the geometry hierarchy
0091   explicit DDCompactView(const DDName&);
0092 
0093   ~DDCompactView();
0094 
0095   //! Creates a compact-view using a different root of the geometry hierarchy.
0096   // NOTE: It cannot be used to modify the stores if they are locked.
0097   explicit DDCompactView(const DDLogicalPart& rootnodedata);
0098 
0099   //! Provides read-only access to the data structure of the compact-view.
0100   const Graph& graph() const;
0101   GraphWalker walker() const;
0102 
0103   //! returns the DDLogicalPart representing the root of the geometrical hierarchy
0104   const DDLogicalPart& root() const;
0105 
0106   //! The absolute position of the world
0107   const DDPosData* worldPosition() const;
0108 
0109   //! returns an empty container if not found
0110   std::vector<double> const& vector(std::string_view iKey) const;
0111 
0112   void position(const DDLogicalPart& self,
0113                 const DDLogicalPart& parent,
0114                 const std::string& copyno,
0115                 const DDTranslation& trans,
0116                 const DDRotation& rot,
0117                 const DDDivision* div = nullptr);
0118 
0119   void position(const DDLogicalPart& self,
0120                 const DDLogicalPart& parent,
0121                 int copyno,
0122                 const DDTranslation& trans,
0123                 const DDRotation& rot,
0124                 const DDDivision* div = nullptr);
0125 
0126   void setRoot(const DDLogicalPart& root);
0127 
0128   void lockdown();
0129 
0130 private:
0131   void swap(DDCompactView&);
0132 
0133   std::unique_ptr<DDCompactViewImpl> rep_;
0134   std::unique_ptr<DDPosData> worldpos_;
0135 
0136   DDI::Store<DDName, std::unique_ptr<DDI::Material>> matStore_;
0137   DDI::Store<DDName, std::unique_ptr<DDI::Solid>> solidStore_;
0138   DDI::Store<DDName, std::unique_ptr<DDI::LogicalPart>> lpStore_;
0139   DDI::Store<DDName, std::unique_ptr<DDI::Specific>> specStore_;
0140   DDI::Store<DDName, std::unique_ptr<DDRotationMatrix>> rotStore_;
0141 
0142   Vectors vectors_;
0143 };
0144 
0145 #endif