DDVector

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#ifndef DDVector_h
#define DDVector_h

#include "DetectorDescription/Core/interface/DDBase.h"
#include "DetectorDescription/Core/interface/DDName.h"
#include <memory>
#include <vector>
#include <iostream>

class DDVector;

//! output operator for printing ...
std::ostream& operator<<(std::ostream& o, const DDVector& cons);

//typedef std::vector<double> dd_constant_type;

//! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
class DDVector : public DDBase<DDName, std::unique_ptr<std::vector<double> > > {
public:
  //! size type for the size of the stored values
  using size_t = std::vector<double>::size_type;

  //! value type of the managed object
  using value_type = std::vector<double>;

  //! an uninitialized constant; one can assign an initialized constant to make it valid
  DDVector();

  //! a refenrence to a constant
  DDVector(const DDName& name);

  //! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
  DDVector(const DDName& name, std::unique_ptr<std::vector<double> > value);

  //! the size of the array of values
  size_t size() const { return rep().size(); }

  //! the stored values
  const value_type& values() const { return rep(); }

  //! returns the value on position pos; does not check boundaries!
  double operator[](size_t pos) const { return rep()[pos]; }

  //! return the first stored value; does not check boundaries!
  double value() const { return rep()[0]; }

  //! read-only iterator pointing to the begin of the stored values
  value_type::const_iterator vectorBegin() const { return rep().begin(); }

  //! read-only iterator poining one place after the stored values
  value_type::const_iterator vectorEnd() const { return rep().end(); }

  //! convert to a double
  operator double() const { return rep()[0]; }

  //! convert to a std::vector<double>
  operator std::vector<double>() const { return rep(); }

  //! convert to a std::vector<int> (expensive!)
  operator std::vector<int>() const;
};
#endif