Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DDExpandedView_h
0002 #define DDExpandedView_h
0003 
0004 #include <cstddef>
0005 #include <iosfwd>
0006 #include <map>
0007 #include <string>
0008 #include <utility>
0009 #include <vector>
0010 
0011 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0012 #include "DetectorDescription/Core/interface/DDTranslation.h"
0013 #include "DetectorDescription/Core/interface/DDCompactView.h"
0014 #include "DetectorDescription/Core/interface/DDExpandedNode.h"
0015 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0016 #include "DetectorDescription/Core/interface/DDPosData.h"
0017 #include "DetectorDescription/Core/interface/DDTransform.h"
0018 #include "DetectorDescription/Core/interface/DDsvalues.h"
0019 #include "DataFormats/Math/interface/GraphWalker.h"
0020 
0021 class DDFilteredView;
0022 class DDLogicalPart;
0023 struct DDPosData;
0024 
0025 /**
0026   DDExpandedView provides a tree-walker (iterator) for the 
0027   expanded view of the detector description. 
0028   Further it provides a registration mechanism for call-backs
0029   whenever a node in the expanded view becomes current and
0030   fullfills the user-defined predicate.
0031   
0032   FIXME: DDExpandedView: in the Prototype just one class -
0033   FIXME:                 later seperation of interface & implementation!
0034 */
0035 //! Provides an exploded view of the detector (tree-view)
0036 /** Taking a DDCompactView the DDExpandedView expands the compact-view into
0037     a detector tree. One instance of DDExpandedView corresponds to one node
0038     in the tree. It is the 'current' node. By using tree navigation ( next(), nextSibling(),
0039     parent(), firstChild() ) the DDExpandedView represents the new corresponding node.
0040 */
0041 class DDExpandedView {
0042   friend class DDFilteredView;
0043 
0044 public:
0045   using WalkerType = math::GraphWalker<DDLogicalPart, DDPosData *>;
0046 
0047   //! std::vector of sibling numbers
0048   typedef std::vector<int> nav_type;
0049   typedef std::pair<int const *, size_t> NavRange;
0050 
0051   //! Constructs an expanded-view based on the compact-view
0052   DDExpandedView(const DDCompactView &);
0053 
0054   virtual ~DDExpandedView();
0055 
0056   //! The logical-part of the current node in the expanded-view
0057   const DDLogicalPart &logicalPart() const;
0058 
0059   //! The name of the logical-part of the current node in the expanded-view
0060   const std::string &name() const;
0061 
0062   //! The absolute translation of the current node
0063   const DDTranslation &translation() const;
0064 
0065   //! The absolute rotation of the current node
0066   const DDRotationMatrix &rotation() const;
0067 
0068   //! The list of ancestors up to the root-node of the current node
0069   const DDGeoHistory &geoHistory() const;
0070 
0071   //! transversed the DDExpandedView according to the given stack of sibling numbers
0072   bool goTo(const nav_type &);
0073   bool goTo(NavRange);
0074   bool goTo(int const *newpos, size_t sz);
0075 
0076   //! return the stack of sibling numbers which indicates the current position in the DDExpandedView
0077   nav_type navPos() const;
0078 
0079   //! return the stack of copy numbers
0080   nav_type copyNumbers() const;
0081 
0082   //! User specific data attached to the current node
0083   std::vector<const DDsvalues_type *> specifics() const;
0084   void specificsV(std::vector<const DDsvalues_type *> &vc) const;
0085 
0086   DDsvalues_type mergedSpecifics() const;
0087   void mergedSpecificsV(DDsvalues_type &res) const;
0088 
0089   //! The DDVector information
0090   std::vector<double> const &vector(std::string_view iKey) const { return cpv_->vector(iKey); }
0091 
0092   //! Copy number associated with the current node
0093   int copyno() const;
0094 
0095   // navigation
0096 
0097   //! The scope of the expanded-view.
0098   const DDGeoHistory &scope() const;
0099 
0100   //! sets the scope of the expanded view
0101   bool setScope(const DDGeoHistory &hist, int depth = 0);
0102 
0103   //! clears the scope; the full tree is available, depth=0
0104   void clearScope();
0105 
0106   //! depth of the scope. 0 means unrestricted depth.
0107   int depth() const;
0108 
0109   //! set current node to the next node in the expanded tree
0110   bool next();
0111 
0112   //! broad search order of next()
0113   bool nextB();
0114 
0115   //! set the current node to the next sibling ...
0116   bool nextSibling();
0117 
0118   //! set the current node to the first child ...
0119   bool firstChild();
0120 
0121   //! set the current node to the parent node ...
0122   bool parent();
0123 
0124   //! true, if a call to firstChild() would succeed (current node has at least one child)
0125   //bool hasChildren() const;
0126 
0127   //! clears the scope and sets the ExpandedView to its root-node
0128   void reset();
0129 
0130   /* was protected, now public; was named goTo, now goToHistory*/
0131   bool goToHistory(const DDGeoHistory &sc);
0132 
0133 protected:
0134   bool descend(const DDGeoHistory &sc);
0135 
0136 protected:
0137   WalkerType *walker_;  //!< the tricky walker
0138   WalkerType w2_;
0139   const DDTranslation trans_;
0140   const DDRotationMatrix rot_;
0141   DDGeoHistory history_;       //!< std::vector of DDExpandedNode
0142   DDGeoHistory scope_;         //!< scope of the expanded view
0143   unsigned int depth_;         //!< depth of the scope, 0==unrestricted depth
0144   const DDPosData *worldpos_;  //!< ???
0145   std::vector<nav_type> nextBStack_;
0146   const DDCompactView *cpv_;
0147 };
0148 
0149 std::string printNavType(int const *n, size_t sz);
0150 inline std::ostream &operator<<(std::ostream &os, const DDExpandedView::nav_type &n) {
0151   os << printNavType(&n.front(), n.size());
0152   return os;
0153 }
0154 inline std::ostream &operator<<(std::ostream &os, const DDExpandedView::NavRange &n) {
0155   os << printNavType(n.first, n.second);
0156   return os;
0157 }
0158 #endif