Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
4 \class genie::Registry
6 \brief A registry. Provides the container for algorithm configuration
7  parameters.
9 \author Costas Andreopoulos <costas.andreopoulos \at>
10  University of Liverpool & STFC Rutherford Appleton Lab
12 \created May 04, 2004
14 \cpright Copyright (c) 2003-2019, The GENIE Collaboration
15  For the full text of the license visit
16  or see $GENIE/LICENSE
17 */
18 //____________________________________________________________________________
20 #ifndef _REGISTRY_H_
21 #define _REGISTRY_H_
23 #include <map>
24 #include <vector>
25 #include <string>
26 #include <iostream>
31 class TH1F;
32 class TH2F;
33 class TTree;
34 class TFolder;
36 using std::map;
37 using std::vector;
38 using std::pair;
39 using std::string;
40 using std::ostream;
42 namespace genie {
44 // Type definitions
45 //
46 typedef map <RgKey, RegistryItemI *> RgIMap;
47 typedef pair<RgKey, RegistryItemI *> RgIMapPair;
49 typedef map <RgKey, RegistryItemI *>::iterator RgIMapIter;
50 typedef map <RgKey, RegistryItemI *>::const_iterator RgIMapConstIter;
51 typedef vector<RgKey> RgKeyList;
53 // Templated utility methods to set/get registry items
54 //
55 class Registry;
56 template<class T>
57  void SetRegistryItem(Registry * r, RgKey key, T item);
58 template<class T>
60  Registry * r, RgKey key, T def, bool set_def=true);
62 //
63 //
64 ostream & operator << (ostream & stream, const Registry & registry);
66 class Registry {
68 public:
69  // Ctor's & dtor
70  //
71  Registry();
72  Registry(string name, bool isReadOnly = true);
73  Registry(const Registry &);
74  virtual ~Registry();
76  // Overloaded registry operators (<<, (), = , +=)
77  //
78  friend ostream & operator << (ostream & stream, const Registry & registry);
80  Registry & operator = (const Registry & reg);
81  Registry & operator += (const Registry & reg);
83  void operator () (RgKey key, int item);
84  void operator () (RgKey key, bool item);
85  void operator () (RgKey key, double item);
86  void operator () (RgKey key, const char * item);
87  void operator () (RgKey key, string item);
89  // Registry & registry item locks
90  //
91  void Lock (void); ///< locks the registry
92  void UnLock (void); ///< unlocks the registry (doesn't unlock items)
93  bool IsLocked (void) const; ///< checks registry lock
94  void InhibitItemLocks (void); ///< override individual item locks
95  void RestoreItemLocks (void); ///< restore individual item locks
96  bool ItemLocksAreActive (void) const; ///< check if item locks are active
97  void LockItem (RgKey key); ///< locks the registry item
98  void UnLockItem (RgKey key); ///< unlocks the registry item
99  bool ItemIsLocked (RgKey key) const; ///< check item lock
100  bool ItemIsLocal (RgKey key) const; ///< local or global?
101  void OverrideGlobalDef (RgKey key); ///< let item override global default (i.e. a 'local' item)
102  void LinkToGlobalDef (RgKey key); ///< link its value to a global default (i.e. a 'global' item)
104  // Methods to set/retrieve Registry values
105  //
106  void Set (RgIMapPair entry);
107  void Set (RgKey key, RgBool item);
108  void Set (RgKey key, RgInt item);
109  void Set (RgKey key, RgDbl item);
110  void Set (RgKey key, RgStr item);
111  void Set (RgKey key, RgAlg item);
112  void Set (RgKey key, RgCChAr item);
113  void Set (RgKey key, RgH1F item);
114  void Set (RgKey key, RgH2F item);
115  void Set (RgKey key, RgTree item);
117  void Get (RgKey key, const RegistryItemI * & item) const;
118  void Get (RgKey key, RgBool & item) const;
119  void Get (RgKey key, RgInt & item) const;
120  void Get (RgKey key, RgDbl & item) const;
121  void Get (RgKey key, RgStr & item) const;
122  void Get (RgKey key, RgAlg & item) const;
123  void Get (RgKey key, RgH1F & item) const;
124  void Get (RgKey key, RgH2F & item) const;
125  void Get (RgKey key, RgTree & item) const;
127  RgBool GetBool (RgKey key) const;
128  RgInt GetInt (RgKey key) const;
129  RgDbl GetDouble (RgKey key) const;
130  RgStr GetString (RgKey key) const;
131  RgAlg GetAlg (RgKey key) const;
132  RgH1F GetH1F (RgKey key) const;
133  RgH2F GetH2F (RgKey key) const;
134  RgTree GetTree (RgKey key) const;
136  RgBool GetBoolDef (RgKey key, RgBool def_opt, bool set_def=true);
137  RgInt GetIntDef (RgKey key, RgInt def_opt, bool set_def=true);
138  RgDbl GetDoubleDef (RgKey key, RgDbl def_opt, bool set_def=true);
139  RgStr GetStringDef (RgKey key, RgStr def_opt, bool set_def=true);
140  RgAlg GetAlgDef (RgKey key, RgAlg def_opt, bool set_def=true);
142  RgIMapConstIter SafeFind (RgKey key) const;
144  int NEntries (void) const; ///< get number of items
145  bool Exists (RgKey key) const; ///< item with input key exists?
146  bool CanSetItem (RgKey key) const; ///< can I set the specifed item?
147  bool DeleteEntry (RgKey key); ///< delete the spcified item
148  void SetName (string name); ///< set the registry name
149  string Name (void) const; ///< get the registry name
150  void Print (ostream & stream) const; ///< print the registry to stream
151  void Copy (const Registry &); ///< copy the input registry
152  void Append (const Registry &, RgKey pfx=""); ///< append the input registry. Entries already in the registry are not updated
153  void Merge (const Registry &, RgKey pfx=""); ///< append the input registry. Entries already in the registry are updated
154  void Clear (bool force = false); ///< clear the registry
155  void Init (void); ///< initialize the registry
157  RgType_t ItemType (RgKey key) const; ///< return item type
158  RgKeyList FindKeys (RgKey key_part) const; ///< create list with all keys containing 'key_part'
160  // Access key->item map
161  //
162  const RgIMap & GetItemMap(void) const { return fRegistry; }
164  // Convert to TFolder (this is the primary mechanism for saving the
165  // GENIE configuration in a ROOT file, along with its generated events)
166  //
167  void CopyToFolder (TFolder * folder) const;
169  // Assert the existence or registry items
170  //
171  void AssertExistence (RgKey key0) const;
172  void AssertExistence (RgKey key0, RgKey key1) const;
173  void AssertExistence (RgKey key0, RgKey key1, RgKey key2) const;
175 private:
177  RegistryItemI * CloneRegistryItem( const RgKey & key ) const ; ///< Properly clone a registry Item according to its type
179  // Registry's private data members
180  //
181  string fName; ///< registry's name
182  bool fIsReadOnly; ///< is read only?
183  bool fInhibitItemLocks; ///<
184  RgIMap fRegistry; ///< 'key' -> 'value' map
185 };
187 } // genie namespace
189 #endif // _REGISTRY_H_
const XML_Char * name
Definition: expat.h:151
bool fIsReadOnly
is read only?
Definition: Registry.h:182
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
Definition: Registry.cxx:550
const char * RgCChAr
bool IsLocked(void) const
checks registry lock
Definition: Registry.cxx:173
Definition: GeneratorBase.h:8
friend ostream & operator<<(ostream &stream, const Registry &registry)
Definition: Registry.cxx:92
bool RgBool
int RgInt
Registry & operator=(const Registry &reg)
Definition: Registry.cxx:151
T GetValueOrUseDefault(Registry *r, RgKey key, T def, bool set_def)
Definition: Registry.cxx:66
bool DeleteEntry(RgKey key)
delete the spcified item
Definition: Registry.cxx:584
void Append(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are not updated
Definition: Registry.cxx:758
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:489
bool ItemLocksAreActive(void) const
check if item locks are active
Definition: Registry.cxx:188
void InhibitItemLocks(void)
override individual item locks
Definition: Registry.cxx:178
void Print(ostream &stream) const
print the registry to stream
Definition: Registry.cxx:694
RgInt GetInt(RgKey key) const
Definition: Registry.cxx:482
void LockItem(RgKey key)
locks the registry item
Definition: Registry.cxx:249
void SetRegistryItem(Registry *r, RgKey key, T item)
Definition: Registry.cxx:54
Registry item pABC.
Definition: RegistryItemI.h:30
TH2F * RgH2F
string Name(void) const
get the registry name
Definition: Registry.cxx:612
void Copy(const Registry &)
copy the input registry
Definition: Registry.cxx:737
RgH1F GetH1F(RgKey key) const
Definition: Registry.cxx:510
enum genie::ERgType RgType_t
RgType_t ItemType(RgKey key) const
return item type
Definition: Registry.cxx:844
void Get(RgKey key, const RegistryItemI *&item) const
Definition: Registry.cxx:340
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing &#39;key_part&#39;
Definition: Registry.cxx:855
void Init(void)
initialize the registry
Definition: Registry.cxx:870
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
Definition: Registry.h:50
const RgIMap & GetItemMap(void) const
Definition: Registry.h:162
bool ItemIsLocal(RgKey key) const
local or global?
Definition: Registry.cxx:193
RgIMap fRegistry
&#39;key&#39; -> &#39;value&#39; map
Definition: Registry.h:184
string RgStr
RgInt GetIntDef(RgKey key, RgInt def_opt, bool set_def=true)
Definition: Registry.cxx:545
void Lock(void)
locks the registry
Definition: Registry.cxx:163
void SetName(string name)
set the registry name
Definition: Registry.cxx:603
void AssertExistence(RgKey key0) const
Definition: Registry.cxx:617
RgIMapConstIter SafeFind(RgKey key) const
Definition: Registry.cxx:565
pair< RgKey, RegistryItemI * > RgIMapPair
Definition: Registry.h:47
bool fInhibitItemLocks
Definition: Registry.h:183
vector< RgKey > RgKeyList
Definition: Registry.h:51
map< RgKey, RegistryItemI * >::size_type RgIMapSizeType
Definition: Registry.h:48
void UnLock(void)
unlocks the registry (doesn&#39;t unlock items)
Definition: Registry.cxx:168
RgStr GetString(RgKey key) const
Definition: Registry.cxx:496
void RestoreItemLocks(void)
restore individual item locks
Definition: Registry.cxx:183
RgStr GetStringDef(RgKey key, RgStr def_opt, bool set_def=true)
Definition: Registry.cxx:555
void LinkToGlobalDef(RgKey key)
link its value to a global default (i.e. a &#39;global&#39; item)
Definition: Registry.cxx:221
string RgKey
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
TH1F * RgH1F
RgBool GetBool(RgKey key) const
Definition: Registry.cxx:475
map< RgKey, RegistryItemI * >::iterator RgIMapIter
Definition: Registry.h:49
TRandom3 r(0)
RgTree GetTree(RgKey key) const
Definition: Registry.cxx:530
void OverrideGlobalDef(RgKey key)
let item override global default (i.e. a &#39;local&#39; item)
Definition: Registry.cxx:209
void UnLockItem(RgKey key)
unlocks the registry item
Definition: Registry.cxx:260
RgH2F GetH2F(RgKey key) const
Definition: Registry.cxx:520
virtual ~Registry()
Definition: Registry.cxx:120
bool Exists(RgKey key) const
item with input key exists?
Definition: Registry.cxx:578
double T
Definition: Xdiff_gwt.C:5
string fName
registry&#39;s name
Definition: Registry.h:181
RgAlg GetAlgDef(RgKey key, RgAlg def_opt, bool set_def=true)
Definition: Registry.cxx:560
bool CanSetItem(RgKey key) const
can I set the specifed item?
Definition: Registry.cxx:271
void Clear(bool force=false)
clear the registry
Definition: Registry.cxx:879
void CopyToFolder(TFolder *folder) const
Definition: Registry.cxx:641
double RgDbl
def entry(str)
void Set(RgIMapPair entry)
Definition: Registry.cxx:282
Registry & operator+=(const Registry &reg)
Definition: Registry.cxx:157
void Merge(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are updated
Definition: Registry.cxx:802
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
Definition: Registry.cxx:540
bool ItemIsLocked(RgKey key) const
check item lock
Definition: Registry.cxx:233
RegistryItemI * CloneRegistryItem(const RgKey &key) const
Properly clone a registry Item according to its type.
Definition: Registry.cxx:905
RgAlg GetAlg(RgKey key) const
Definition: Registry.cxx:503
void operator()(RgKey key, int item)
Definition: Registry.cxx:125
map< RgKey, RegistryItemI * > RgIMap
Definition: Registry.h:46
TTree * RgTree
int NEntries(void) const
get number of items
Definition: Registry.cxx:597
enum BeamMode string