CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected 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
 
bool readOnly () const
 
void setReadOnly (bool b)
 
auto size () const
 
 Store ()
 
void swap (Store &)
 
 ~Store ()
 

Protected Member Functions

Storeoperator= (const Store &)=delete
 
 Store (const Store &)=delete
 

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

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

Definition at line 46 of file Store.h.

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

Definition at line 42 of file Store.h.

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

Definition at line 40 of file Store.h.

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

Definition at line 41 of file Store.h.

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

Definition at line 44 of file Store.h.

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 45 of file Store.h.

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 43 of file Store.h.

Constructor & Destructor Documentation

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

Definition at line 68 of file Store.h.

68 : readOnly_(false) { }
bool readOnly_
Definition: Store.h:75
template<class N , class I , class K >
DDI::Store< N, I, K >::~Store ( )

Definition at line 133 of file Store.h.

References DDI::Finalize< I >::cleanup(), eostools::move(), and DDI::Store< N, I, K >::reg_.

Referenced by DDI::Store< DDName, DDRotationMatrix * >::Store().

134  {
135  for( auto it : reg_ ) {
136  Finalize<I>::cleanup( std::move( it.second->second ));
137  delete it.second;
138  it.second = nullptr;
139  }
140  }
static void cleanup(I &&ptr)
Definition: Store.h:119
std::map< name_type, prep_type > reg_
Definition: Store.h:72
def move(src, dest)
Definition: eostools.py:511
template<class N, class I, class K = I>
DDI::Store< N, I, K >::Store ( const Store< N, I, K > &  )
protecteddelete

Member Function Documentation

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

Definition at line 48 of file Store.h.

48 { return reg_.begin(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:72
template<class N, class I, class K = I>
void DDI::Store< N, I, K >::clear ( )
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 80 of file Store.h.

References Exception, DDI::Store< N, I, K >::readOnly_, DDI::Store< N, I, K >::reg_, mps_fire::result, and tmp.

Referenced by DDI::Store< DDName, DDRotationMatrix * >::size().

81  {
82  prep_type tmp = nullptr;
83  auto result = reg_.emplace( n, tmp );
84  if( result.second ) {
85  if( readOnly_ )
86  throw cms::Exception( "DetectorDescriptionStore" )
87  << " Store has been locked. Illegal attempt to add "
88  << n << " to a global store.";
89  // ELSE
90  result.first->second = new Rep_type( n, nullptr );
91  }
92  return result.first->second;
93  }
bool readOnly_
Definition: Store.h:75
std::map< name_type, prep_type > reg_
Definition: Store.h:72
Rep_type * prep_type
Definition: Store.h:44
rep_type< name_type, pimpl_type > Rep_type
Definition: Store.h:43
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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 97 of file Store.h.

References Exception, eostools::move(), DDI::Store< N, I, K >::readOnly_, DDI::Store< N, I, K >::reg_, mps_fire::result, and tmp.

99  {
100  if( readOnly_ )
101  throw cms::Exception( "DetectorDescriptionStore" )
102  << " Store has been locked. Illegal attempt to add "
103  << n << " to a global store.";
104  // ELSE
105  prep_type tmp = nullptr;
106  auto result = reg_.emplace( n, tmp );
107  if( !result.second ) {
108  result.first->second->second.swap( p );
109  }
110  else {
111  result.first->second = new Rep_type( n, std::move( p ));
112  }
113  return result.first->second;
114  }
bool readOnly_
Definition: Store.h:75
std::map< name_type, prep_type > reg_
Definition: Store.h:72
Rep_type * prep_type
Definition: Store.h:44
rep_type< name_type, pimpl_type > Rep_type
Definition: Store.h:43
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
def move(src, dest)
Definition: eostools.py:511
template<class N, class I, class K = I>
auto DDI::Store< N, I, K >::end ( void  )
inline

Definition at line 49 of file Store.h.

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

49 { return reg_.end(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:72
template<class N , class I , class K >
bool DDI::Store< N, I, K >::isDefined ( const name_type n) const

Definition at line 143 of file Store.h.

References DDI::Store< N, I, K >::readOnly_, DDI::Store< N, I, K >::reg_, and mps_fire::result.

Referenced by DDI::Store< DDName, DDRotationMatrix * >::size().

144  {
145  if (readOnly_) edm::LogWarning("DetectorDescriptionStore") << " Store is locked and most likely empty. isDefined will be false.";
146  auto it = reg_.find(n);
147  bool result(false);
148  if (it != reg_.end()) {
149  if (it.second->second) {
150  result=true;
151  }
152  }
153  return result;
154  }
bool readOnly_
Definition: Store.h:75
std::map< name_type, prep_type > reg_
Definition: Store.h:72
template<class N, class I, class K = I>
Store& DDI::Store< N, I, K >::operator= ( const Store< N, I, K > &  )
protecteddelete
template<class N, class I, class K = I>
bool DDI::Store< N, I, K >::readOnly ( ) const
inline

Definition at line 66 of file Store.h.

66 { return readOnly_; }
bool readOnly_
Definition: Store.h:75
template<class N, class I, class K = I>
void DDI::Store< N, I, K >::setReadOnly ( bool  b)
inline

Definition at line 65 of file Store.h.

65 { readOnly_ = b; }
bool readOnly_
Definition: Store.h:75
double b
Definition: hdecay.h:120
template<class N, class I, class K = I>
auto DDI::Store< N, I, K >::size ( void  ) const
inline

Definition at line 50 of file Store.h.

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

50 { return reg_.size(); }
std::map< name_type, prep_type > reg_
Definition: Store.h:72
template<class N , class I , class K >
void DDI::Store< N, I, K >::swap ( Store< N, I, K > &  storeToSwap)

Definition at line 157 of file Store.h.

References DDI::Store< N, I, K >::readOnly_, and DDI::Store< N, I, K >::reg_.

Referenced by DDI::Store< DDName, DDRotationMatrix * >::size().

157  {
158  reg_.swap(storeToSwap.reg_);
159  storeToSwap.readOnly_ = readOnly_;
160  }
bool readOnly_
Definition: Store.h:75
std::map< name_type, prep_type > reg_
Definition: Store.h:72

Member Data Documentation

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