Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-15 04:27:14

0001 #ifndef DETECTOR_DESCRIPTION_CORE_DDNAME_H
0002 #define DETECTOR_DESCRIPTION_CORE_DDNAME_H
0003 
0004 #include <iosfwd>
0005 #include <string>
0006 #include <utility>
0007 
0008 #include "FWCore/Utilities/interface/StdPairHasher.h"
0009 #include <oneapi/tbb/concurrent_vector.h>
0010 #include <oneapi/tbb/concurrent_unordered_map.h>
0011 
0012 class DDCurrentNamespace;
0013 
0014 //! DDName is used to identify DDD entities uniquely.
0015 /** A DDName consists of a \a name and a \a namespace. Both are represented as std::string.
0016 */
0017 class DDName {
0018 public:
0019   using id_type = int;
0020   using key_type = std::pair<const std::string, std::string>;
0021   using Registry = tbb::concurrent_unordered_map<key_type, id_type, edm::StdPairHasher>;
0022   using IdToName = tbb::concurrent_vector<Registry::const_iterator>;
0023 
0024   //! Constructs a DDName with name \a name and assigns \a name to the namespace \a ns.
0025   DDName(const std::string& name, const std::string& ns);
0026 
0027   //! Creates a DDName with \a name in the current namespace defined in the singleton DDCurrentNamespace
0028   DDName(const std::string& name);
0029   DDName(const char* name);
0030   DDName(const char* name, const char* ns);
0031 
0032   explicit DDName();
0033 
0034   //! Returns the \a name
0035   const std::string& name() const;
0036 
0037   //! Returns the \a namespace
0038   const std::string& ns() const;
0039 
0040   /** Returns a string complete of the \a namespace and \a name separated by ":". 
0041       Most likely you want to use ns() and / or name() methods instead.
0042    */
0043   const std::string fullname() const { return ns() + ":" + name(); }
0044 
0045   id_type id() const { return id_; }
0046 
0047   bool operator<(const DDName& rhs) const { return id_ < rhs.id_; }
0048   bool operator==(const DDName& rhs) const { return id_ == rhs.id_; }
0049 
0050 private:
0051   id_type id_;
0052 
0053   static Registry::const_iterator registerName(const std::pair<std::string, std::string>& s);
0054 };
0055 
0056 std::ostream& operator<<(std::ostream& os, const DDName& n);
0057 
0058 #endif