CMS 3D CMS Logo

DDBase.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_CORE_DDBASE_H
2 #define DETECTOR_DESCRIPTION_CORE_DDBASE_H
3 
4 #include <utility>
8 
9 template <class N, class C>
10 class DDBase {
11 public:
12  template <class D>
13  class iterator {
14  public:
16  using value_type = D;
17 
18  explicit iterator(const typename DDI::Store<N, C>::iterator it) : it_(it) {}
19 
21 
22  value_type& operator*() const {
23  d_.prep_ = it_->second;
24  return d_;
25  }
26 
28  d_.prep_ = it_->second;
29  return &d_;
30  }
31 
32  bool operator==(const iterator& i) const { return i.it_ == it_; }
33 
34  bool operator!=(const iterator& i) const { return i.it_ != it_; }
35 
36  bool operator<(const iterator& i) const { return it_ < i.it_; }
37 
38  bool operator>(const iterator& i) const { return it_ > i.it_; }
39 
40  void operator++() { ++it_; }
41 
42  void end() const { it_ = StoreT::instance().end(); }
43 
44  private:
45  mutable typename DDI::Store<N, C>::iterator it_;
46  mutable D d_;
47  };
48 
49 public:
51  using def_type = std::pair<const N*, bool>;
52  static auto end() { return StoreT::instance().end(); }
53  static auto begin() { return StoreT::instance().begin(); }
54 
55  DDBase() : prep_(nullptr) {}
56  virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/
57  }
58 
59  const N& name() const { return prep_->name(); }
60 
61  const N& ddname() const { return prep_->name(); }
62 
63  std::string toString() const { return prep_->name().fullname(); }
64 
65  const typename DDI::rep_traits<N, C>::reference rep() const { return *(prep_->second); }
66 
67  typename DDI::rep_traits<N, C>::reference rep() { return *(prep_->second); }
68 
69  const typename DDI::rep_traits<N, C>::reference val() const {
70  if (!isValid())
71  throw cms::Exception("DDException") << "undefined: " << name();
72  return rep();
73  }
74 
76  if (!isValid())
77  throw cms::Exception("DDException") << "undefined: " << name();
78  return rep();
79  }
80 
81  bool operator==(const DDBase& b) const { return prep_ == b.prep_; }
82  // true, if registered or defined
83  operator bool() const { return isValid(); }
84  bool operator<(const DDBase& b) const { return prep_ < b.prep_; }
85  bool operator>(const DDBase& b) const { return prep_ > b.prep_; }
86 
87  // ( name*, true ) if defined
88  // ( name*, false ) if registered but not defined
89  // ( 0, false ) if not there at all
90  def_type isDefined() const {
91  return prep_ ? std::make_pair(&(prep_->name()), bool(prep_->second)) : std::make_pair((const N*)nullptr, false);
92  }
93 
95  bool isValid() const { return prep_ ? bool(prep_->second) : false; }
96  void create(const N& name, C vals) { prep_ = StoreT::instance().create(name, std::move(vals)); }
97  void create(const N& name) { prep_ = StoreT::instance().create(name); }
98 
99 private:
101 };
102 
103 #endif
DDBase::operator==
bool operator==(const DDBase &b) const
Definition: DDBase.h:81
DDBase::iterator::operator->
value_type * operator->() const
Definition: DDBase.h:27
DDBase< DDName, std::unique_ptr< DDI::Material > >::def_type
std::pair< const DDName *, bool > def_type
Definition: DDBase.h:51
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
DDI::rep_type::second
I second
Definition: rep_type.h:37
DDBase::iterator::d_
D d_
Definition: DDBase.h:46
DDBase::isDefined
def_type isDefined() const
Definition: DDBase.h:90
DDI::Singleton
Definition: Singleton.h:6
DDBase::rep
DDI::rep_traits< N, C >::reference rep()
Definition: DDBase.h:67
DDI::rep_traits::reference
typename I::reference reference
Definition: rep_type.h:12
DDBase::iterator::iterator
iterator()
Definition: DDBase.h:20
DDBase::iterator::operator++
void operator++()
Definition: DDBase.h:40
DDBase::iterator::operator!=
bool operator!=(const iterator &i) const
Definition: DDBase.h:34
DDBase::iterator::value_type
D value_type
C is, for example, a DDLogicalPart or a DDMaterial or a DDSolid ...
Definition: DDBase.h:16
DDBase::operator<
bool operator<(const DDBase &b) const
Definition: DDBase.h:84
DDBase::iterator::operator<
bool operator<(const iterator &i) const
Definition: DDBase.h:36
DDBase::prep_
DDI::rep_type< N, C > * prep_
Definition: DDBase.h:100
DDI::rep_type::name
const rep_traits< N, I >::name_type & name() const
Definition: rep_type.h:39
DDBase::~DDBase
virtual ~DDBase()
Definition: DDBase.h:56
DDBase::toString
std::string toString() const
Definition: DDBase.h:63
DDBase::operator>
bool operator>(const DDBase &b) const
Definition: DDBase.h:85
Store.h
DDBase::name
const N & name() const
Definition: DDBase.h:59
DDBase::iterator::operator==
bool operator==(const iterator &i) const
Definition: DDBase.h:32
N
#define N
Definition: blowfish.cc:9
DDBase::end
static auto end()
Definition: DDBase.h:52
DDBase::rep
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:65
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDI::rep_type< N, C >
DDBase::isValid
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:95
DDBase::ddname
const N & ddname() const
Definition: DDBase.h:61
DDI::Singleton::instance
static value_type & instance()
DDBase::iterator::it_
DDI::Store< N, C >::iterator it_
Definition: DDBase.h:45
DDBase::iterator::iterator
iterator(const typename DDI::Store< N, C >::iterator it)
Definition: DDBase.h:18
DDBase::iterator
Definition: DDBase.h:13
DDBase::val
const DDI::rep_traits< N, C >::reference val() const
Definition: DDBase.h:69
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
DDBase::begin
static auto begin()
Definition: DDBase.h:53
DDBase::DDBase
DDBase()
Definition: DDBase.h:55
DDI::Store::iterator
typename registry_type::iterator iterator
Definition: Store.h:45
DDBase::create
void create(const N &name)
Definition: DDBase.h:97
Singleton.h
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
DDBase::iterator::operator*
value_type & operator*() const
Definition: DDBase.h:22
eostools.move
def move(src, dest)
Definition: eostools.py:511
gen::C
C
Definition: PomwigHadronizer.cc:78
DDBase::create
void create(const N &name, C vals)
Definition: DDBase.h:96
Exception
Definition: hltDiff.cc:245
DDBase
Definition: DDBase.h:10
rep_type.h
DDBase::iterator::end
void end() const
Definition: DDBase.h:42
DDBase::val
const DDI::rep_traits< N, C >::reference val()
Definition: DDBase.h:75
DDBase::iterator::operator>
bool operator>(const iterator &i) const
Definition: DDBase.h:38