CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Attributes
DDI::Store< N, I, K > Class Template Reference

#include <Store.h>

Public Types

using iterator = typename registry_type::iterator
 
using key_type = K
 
using name_type = N
 
using pimpl_type = I
 
using prep_type = Rep_type *
 
using registry_type = std::map< name_type, prep_type >
 
using Rep_type = rep_type< name_type, pimpl_type >
 

Public Member Functions

auto begin ()
 
void clear ()
 
prep_type create (const name_type &)
 
prep_type create (const name_type &, pimpl_type)
 
auto end ()
 
bool isDefined (const name_type &n) const
 
Storeoperator= (const Store &)=delete
 
bool readOnly () const
 
void setReadOnly (bool b)
 
auto size () const
 
 Store ()
 
 Store (const Store &)=delete
 
void swap (Store &)
 
 ~Store ()
 

Protected Attributes

bool readOnly_
 
std::map< name_type, prep_typereg_
 

Detailed Description

template<class N, class I, class K = I>
class DDI::Store< N, I, K >

A Store provides a place for objects of type I which are uniquely identified by there name of type N. The objects themselves can be accessed indirectly by the prep_type of the Store like

typedef Store<std::string,double> NamedDouble; NamedDouble::prep_type d = NamedDouble("Four", new double(4.)); double val = *(d->second); std::string name = d->first;

K is the key_type which is used as an index in the storage. It must fulfill all requirements for a key in a sorted associative container. N is the user-friendly name_type, which must be mapped uniquely to the key_type and vice versa. N itself must also fulfill all requirements of a key in a sorted associative container. The reason to provide K is that one might save some memory by compacting common parts of information contained in different instances of N, e.g. if N is a pair<string,string>, the first string being a 'namespace' the second a 'name' then K could be a pair<int,string> thus compacting the namespace-string to a simple int. K and N must support following unique conversions:

Definition at line 37 of file Store.h.

Member Typedef Documentation

◆ iterator

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::iterator = typename registry_type::iterator

Definition at line 45 of file Store.h.

◆ key_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::key_type = K

Definition at line 41 of file Store.h.

◆ name_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::name_type = N

Definition at line 39 of file Store.h.

◆ pimpl_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::pimpl_type = I

Definition at line 40 of file Store.h.

◆ prep_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::prep_type = Rep_type*

Definition at line 43 of file Store.h.

◆ registry_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::registry_type = std::map<name_type, prep_type>

Definition at line 44 of file Store.h.

◆ Rep_type

template<class N, class I, class K = I>
using DDI::Store< N, I, K >::Rep_type = rep_type<name_type, pimpl_type>

Definition at line 42 of file Store.h.

Constructor & Destructor Documentation

◆ Store() [1/2]

template<class N, class I, class K = I>
DDI::Store< N, I, K >::Store ( )
inline

Definition at line 67 of file Store.h.

67 : readOnly_(false) {}
bool readOnly_
Definition: Store.h:74

◆ ~Store()

template<class N , class I , class K >
DDI::Store< N, I, K >::~Store ( )

Definition at line 121 of file Store.h.

121  {
122  for (auto it : reg_) {
123  Finalize<I>::cleanup(std::move(it.second->second));
124  delete it.second;
125  it.second = nullptr;
126  }
127  }
std::map< name_type, prep_type > reg_
Definition: Store.h:73
static void cleanup(I &&ptr)
Definition: Store.h:109
def move(src, dest)
Definition: eostools.py:511

◆ Store() [2/2]

template<class N, class I, class K = I>
DDI::Store< N, I, K >::Store ( const Store< N, I, K > &  )
delete

Member Function Documentation

◆ begin()

template<class N, class I, class K = I>
auto DDI::Store< N, I, K >::begin ( void  )
inline

Definition at line 47 of file Store.h.

47 { return reg_.begin(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:73

◆ clear()

template<class N, class I, class K = I>
void DDI::Store< N, I, K >::clear ( )

◆ create() [1/2]

template<class N , class I , class K >
Store< N, I, K >::prep_type DDI::Store< N, I, K >::create ( const name_type n)

Definition at line 78 of file Store.h.

78  {
79  prep_type tmp = nullptr;
80  auto result = reg_.emplace(n, tmp);
81  if (result.second) {
82  if (readOnly_)
83  throw cms::Exception("DetectorDescriptionStore")
84  << " Store has been locked. Illegal attempt to add " << n << " to a global store.";
85  // ELSE
86  result.first->second = new Rep_type(n, nullptr);
87  }
88  return result.first->second;
89  }
std::map< name_type, prep_type > reg_
Definition: Store.h:73
bool readOnly_
Definition: Store.h:74
rep_type< name_type, pimpl_type > Rep_type
Definition: Store.h:42
Rep_type * prep_type
Definition: Store.h:43
tmp
align.sh
Definition: createJobs.py:716

◆ create() [2/2]

template<class N , class I , class K >
Store< N, I, K >::prep_type DDI::Store< N, I, K >::create ( const name_type n,
pimpl_type  p 
)

Definition at line 92 of file Store.h.

92  {
93  if (readOnly_)
94  throw cms::Exception("DetectorDescriptionStore")
95  << " Store has been locked. Illegal attempt to add " << n << " to a global store.";
96  // ELSE
97  prep_type tmp = nullptr;
98  auto result = reg_.emplace(n, tmp);
99  if (!result.second) {
100  result.first->second->second.swap(p);
101  } else {
102  result.first->second = new Rep_type(n, std::move(p));
103  }
104  return result.first->second;
105  }
std::map< name_type, prep_type > reg_
Definition: Store.h:73
bool readOnly_
Definition: Store.h:74
rep_type< name_type, pimpl_type > Rep_type
Definition: Store.h:42
Rep_type * prep_type
Definition: Store.h:43
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511

◆ end()

template<class N, class I, class K = I>
auto DDI::Store< N, I, K >::end ( void  )
inline

Definition at line 48 of file Store.h.

Referenced by Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

48 { return reg_.end(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:73

◆ isDefined()

template<class N , class I , class K >
bool DDI::Store< N, I, K >::isDefined ( const name_type n) const

Definition at line 130 of file Store.h.

130  {
131  if (readOnly_)
132  edm::LogWarning("DetectorDescriptionStore")
133  << " Store is locked and most likely empty. isDefined will be false.";
134  auto it = reg_.find(n);
135  bool result(false);
136  if (it != reg_.end()) {
137  if (it.second->second) {
138  result = true;
139  }
140  }
141  return result;
142  }
std::map< name_type, prep_type > reg_
Definition: Store.h:73
bool readOnly_
Definition: Store.h:74
Log< level::Warning, false > LogWarning

◆ operator=()

template<class N, class I, class K = I>
Store& DDI::Store< N, I, K >::operator= ( const Store< N, I, K > &  )
delete

◆ readOnly()

template<class N, class I, class K = I>
bool DDI::Store< N, I, K >::readOnly ( ) const
inline

Definition at line 65 of file Store.h.

65 { return readOnly_; }
bool readOnly_
Definition: Store.h:74

◆ setReadOnly()

template<class N, class I, class K = I>
void DDI::Store< N, I, K >::setReadOnly ( bool  b)
inline

Definition at line 64 of file Store.h.

64 { readOnly_ = b; }
bool readOnly_
Definition: Store.h:74
double b
Definition: hdecay.h:118

◆ size()

template<class N, class I, class K = I>
auto DDI::Store< N, I, K >::size ( void  ) const
inline

Definition at line 49 of file Store.h.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

49 { return reg_.size(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:73

◆ swap()

template<class N , class I , class K >
void DDI::Store< N, I, K >::swap ( Store< N, I, K > &  storeToSwap)

Definition at line 145 of file Store.h.

145  {
146  reg_.swap(storeToSwap.reg_);
147  storeToSwap.readOnly_ = readOnly_;
148  }
std::map< name_type, prep_type > reg_
Definition: Store.h:73
bool readOnly_
Definition: Store.h:74

Member Data Documentation

◆ readOnly_

template<class N, class I, class K = I>
bool DDI::Store< N, I, K >::readOnly_
protected

◆ reg_

template<class N, class I, class K = I>
std::map<name_type, prep_type> DDI::Store< N, I, K >::reg_
protected