Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:54

0001 #ifndef DDLogicalPart_h
0002 #define DDLogicalPart_h
0003 
0004 #include <iosfwd>
0005 #include <map>
0006 #include <memory>
0007 #include <string>
0008 #include <utility>
0009 #include <vector>
0010 
0011 #include "DetectorDescription/Core/interface/Singleton.h"
0012 #include "DetectorDescription/Core/interface/DDBase.h"
0013 #include "DetectorDescription/Core/interface/DDEnums.h"
0014 #include "DetectorDescription/Core/interface/DDName.h"
0015 #include "DetectorDescription/Core/interface/DDsvalues.h"
0016 
0017 class DDLogicalPart;
0018 class DDMaterial;
0019 class DDPartSelection;
0020 class DDSolid;
0021 class DDSpecifics;
0022 class DDValue;
0023 namespace DDI {
0024   class LogicalPart;
0025 }  // namespace DDI
0026 
0027 std::ostream &operator<<(std::ostream &, const DDLogicalPart &);
0028 
0029 //! A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
0030 /** ... of a unpositioned volume. DDLogicalPart provides thus an interface to its XML
0031     representation <LogicalPart ... </LogicalPart>. 
0032 
0033     An object of this class is a reference-object and thus lightweighted. 
0034     It can be copied by value without having a large overhead.
0035     Assigning to the reference-object invalidates the object which was referred to
0036     before. Assigning also effects all other instances of this class which 
0037     were created using the same value of DDName. In fact, the value of DDName
0038     identifies a LogicalPart uniquely.
0039     
0040     \b Current \b Restriction: Only the \a name part of DDName identifies the LogicalPart.
0041     
0042     
0043     <h3> General properties of reference objects:</h3>
0044     
0045     Three kind of reference objects can
0046     be distinguished:
0047     \arg \b Uninitialized reference objects (related to default constructor)
0048     \arg \b Initialized reference objects (related to the constructor taken DDName as argument)
0049     \arg \b Defined reference objects
0050     
0051     An \b unititialized reference object is somehow comparable to an anonymous
0052     structure. The default constructor (no arguments) is used to create it. No
0053     DDName was specified. It's not very useful unless you assign an \b initialized
0054     or \b defined reference object.
0055     
0056     An \b initialized reference object is a reference object which was created
0057     first using only the constructor taking a single DDName as an argument. It's
0058     comparable to a variable declaration with default initialization (like 
0059     \c std::vector \c < \c int \c > \c v). The default object is registered using
0060     the DDName as index in some from the user hidden registry.
0061     After an \b initialized reference object
0062     has been created it can be used (copied, assigned to, beeing assigned to, ..)
0063     like a built in type like \c int. As soon as an \b defined reference
0064     object with the same DDName is create, all already existing \b initialized
0065     reference object become \b defined reference object immidiately (some kind
0066     of one-definition-rule).
0067     
0068     A \b defined reference object is a reference object which was created using
0069     a constructor taking DDName and additional arguments or using appropriate
0070     factory functions (e.g. DDbox) returning a \b defined reference object.
0071     As soon as one \b defined reference object \c A1 is created with 
0072     a unique DDName \c N1,
0073     every reference object \c A2 
0074     created by the constructor which only take DDName \c N2
0075     as an argument and \c N2 == \c N1, is also a \b defined
0076     reference object referring to the same object than \c A1. 
0077     Hence \c A1 == \c A2 is true. Further any previously created
0078     initialized reference objects having the same DDName also become references
0079     to the newly created defined reference object \c A1.
0080     
0081     To find out whether an instance of a reference object is defined or not,
0082     \c operator \c bool can be used, i.e.
0083     \code
0084     DDLogicalPart(DDName("CMS","cms.xml")) cms;
0085     if (cms) {
0086       // cms is a defined reference object
0087     }
0088     else {
0089       // cms is a (default) initialized reference object
0090     }
0091     \endcode
0092 */
0093 class DDLogicalPart : public DDBase<DDName, std::unique_ptr<DDI::LogicalPart> > {
0094 public:
0095   //! The default constructor provides an uninitialzed reference object.
0096   DDLogicalPart(void) : DDBase<DDName, std::unique_ptr<DDI::LogicalPart> >() {}
0097 
0098   //! Creates a reference object referring to the appropriate XML specification.
0099   DDLogicalPart(const DDName &name);
0100 
0101   //! Registers (creates) a reference object representing a LogicalPart.
0102   DDLogicalPart(const DDName &name,
0103                 const DDMaterial &material,
0104                 const DDSolid &solid,
0105                 DDEnums::Category cat = DDEnums::unspecified);
0106 
0107   //! Returns the categorization of the DDLogicalPart (sensitive detector element, cable, ...)
0108   DDEnums::Category category(void) const;
0109 
0110   //! Returns a reference object of the material this LogicalPart is made of
0111   const DDMaterial &material(void) const;
0112 
0113   //! Returns a reference object of the solid being the shape of this LogicalPart
0114   const DDSolid &solid(void) const;
0115 
0116   //! returns the specific-data attached to the LogicalPart only (not to a DDExpandedNode)
0117   std::vector<const DDsvalues_type *> specifics(void) const;
0118 
0119   //! returns the merged-specifics, i.e. the last specified specifics of this logical-part
0120   DDsvalues_type mergedSpecifics(void) const;
0121 
0122   //! \b don't \b use, internal only /todo make it private
0123   void addSpecifics(const std::pair<const DDPartSelection *, const DDsvalues_type *> &);
0124   void removeSpecifics(const std::pair<DDPartSelection *, DDsvalues_type *> &);
0125   const std::vector<std::pair<const DDPartSelection *, const DDsvalues_type *> > &attachedSpecifics(void) const;
0126   bool hasDDValue(const DDValue &) const;
0127 };
0128 
0129 // some helpers .... (not very clean, redesign!!)
0130 std::pair<bool, std::string> DDIsValid(const std::string &ns,
0131                                        const std::string &name,
0132                                        std::vector<DDLogicalPart> &result,
0133                                        bool doRegex = true);
0134 // std::maps name to std::vector of namespaces
0135 // 2009-2010 re-write...FIX: Understand how this is used by DDSpecifics and FIX
0136 typedef DDI::Singleton<std::map<std::string, std::vector<DDName> > > LPNAMES;
0137 void DD_NC(const DDName &);
0138 
0139 #endif