Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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