Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DD_DDMap_h
0002 #define DD_DDMap_h
0003 
0004 #include <iostream>
0005 #include <map>
0006 #include <memory>
0007 #include <string>
0008 
0009 #include "DetectorDescription/Core/interface/DDReadMapType.h"
0010 #include "DetectorDescription/Core/interface/DDBase.h"
0011 #include "DetectorDescription/Core/interface/DDName.h"
0012 
0013 class DDMap;
0014 
0015 //! output operator for printing ...
0016 std::ostream& operator<<(std::ostream& o, const DDMap& cons);
0017 
0018 //! simply a std::map<std::string,double> supporting an addional operator[] const
0019 using dd_map_type = ReadMapType<double>;
0020 
0021 //! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
0022 class DDMap : public DDBase<DDName, std::unique_ptr<dd_map_type> > {
0023 public:
0024   //! the type of the managed object
0025   using value_type = dd_map_type;
0026 
0027   //! size type for the size of the stored values
0028   using size_t = dd_map_type::size_type;
0029 
0030   //! an uninitialized constant; one can assign an initialized constant to make it valid
0031   DDMap();
0032 
0033   //! a refenrence to a constant
0034   DDMap(const DDName& name);
0035 
0036   //! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
0037   DDMap(const DDName& name, std::unique_ptr<dd_map_type> value);
0038 
0039   //! the size of the array of values
0040   size_t size() const { return rep().size(); }
0041 
0042   //! the stored values
0043   const dd_map_type& values() const { return rep(); }
0044 
0045   //! returns the value on position pos; does not check boundaries!
0046   const double& operator[](const std::string& name) const {
0047     const dd_map_type& r(rep());
0048     return r[name];
0049   }
0050 
0051   //! read-only iterator pointing to the begin of the stored values
0052   value_type::const_iterator mapBegin() const { return rep().begin(); }
0053 
0054   //! read-only iterator poining one place after the stored values
0055   value_type::const_iterator mapEnd() const { return rep().end(); }
0056 };
0057 #endif  // DD_DDMap_h