GENIEGenerator
Loading...
Searching...
No Matches
Registry.h
Go to the documentation of this file.
1//____________________________________________________________________________
2/*!
3
4\class genie::Registry
5
6\brief A registry. Provides the container for algorithm configuration
7 parameters.
8
9\author Costas Andreopoulos <c.andreopoulos \at cern.ch>
10 University of Liverpool
11
12\created May 04, 2004
13
14\cpright Copyright (c) 2003-2025, The GENIE Collaboration
15 For the full text of the license visit http://copyright.genie-mc.org
16*/
17//____________________________________________________________________________
18
19#ifndef _REGISTRY_H_
20#define _REGISTRY_H_
21
22#include <map>
23#include <vector>
24#include <string>
25#include <iostream>
26
29
30class TH1F;
31class TH2F;
32class TTree;
33class TFolder;
34
35using std::map;
36using std::vector;
37using std::pair;
38using std::string;
39using std::ostream;
40
41namespace genie {
42
43// Type definitions
44//
45typedef map <RgKey, RegistryItemI *> RgIMap;
46typedef pair<RgKey, RegistryItemI *> RgIMapPair;
47typedef map <RgKey, RegistryItemI *>::size_type RgIMapSizeType;
48typedef map <RgKey, RegistryItemI *>::iterator RgIMapIter;
49typedef map <RgKey, RegistryItemI *>::const_iterator RgIMapConstIter;
50typedef vector<RgKey> RgKeyList;
51
52// Templated utility methods to set/get registry items
53//
54class Registry;
55template<class T>
56 void SetRegistryItem(Registry * r, RgKey key, T item);
57template<class T>
59 Registry * r, RgKey key, T def, bool set_def=true);
60
61//
62//
63ostream & operator << (ostream & stream, const Registry & registry);
64
65class Registry {
66
67public:
68 // Ctor's & dtor
69 //
70 Registry();
71 Registry(string name, bool isReadOnly = true);
72 Registry(const Registry &);
73 virtual ~Registry();
74
75 // Overloaded registry operators (<<, (), = , +=)
76 //
77 friend ostream & operator << (ostream & stream, const Registry & registry);
78
79 Registry & operator = (const Registry & reg);
80 Registry & operator += (const Registry & reg);
81
82 void operator () (RgKey key, int item);
83 void operator () (RgKey key, bool item);
84 void operator () (RgKey key, double item);
85 void operator () (RgKey key, const char * item);
86 void operator () (RgKey key, string item);
87
88 // Registry & registry item locks
89 //
90 void Lock (void); ///< locks the registry
91 void UnLock (void); ///< unlocks the registry (doesn't unlock items)
92 bool IsLocked (void) const; ///< checks registry lock
93 void InhibitItemLocks (void); ///< override individual item locks
94 void RestoreItemLocks (void); ///< restore individual item locks
95 bool ItemLocksAreActive (void) const; ///< check if item locks are active
96 void LockItem (RgKey key); ///< locks the registry item
97 void UnLockItem (RgKey key); ///< unlocks the registry item
98 bool ItemIsLocked (RgKey key) const; ///< check item lock
99 bool ItemIsLocal (RgKey key) const; ///< local or global?
100 void OverrideGlobalDef (RgKey key); ///< let item override global default (i.e. a 'local' item)
101 void LinkToGlobalDef (RgKey key); ///< link its value to a global default (i.e. a 'global' item)
102
103 // Methods to set/retrieve Registry values
104 //
105 void Set (RgIMapPair entry);
106 void Set (RgKey key, RgBool item);
107 void Set (RgKey key, RgInt item);
108 void Set (RgKey key, RgDbl item);
109 void Set (RgKey key, RgStr item);
110 void Set (RgKey key, RgAlg item);
111 void Set (RgKey key, RgCChAr item);
112 void Set (RgKey key, RgH1F item);
113 void Set (RgKey key, RgH2F item);
114 void Set (RgKey key, RgTree item);
115
116 void Get (RgKey key, const RegistryItemI * & item) const;
117 void Get (RgKey key, RgBool & item) const;
118 void Get (RgKey key, RgInt & item) const;
119 void Get (RgKey key, RgDbl & item) const;
120 void Get (RgKey key, RgStr & item) const;
121 void Get (RgKey key, RgAlg & item) const;
122 void Get (RgKey key, RgH1F & item) const;
123 void Get (RgKey key, RgH2F & item) const;
124 void Get (RgKey key, RgTree & item) const;
125
126 RgBool GetBool (RgKey key) const;
127 RgInt GetInt (RgKey key) const;
128 RgDbl GetDouble (RgKey key) const;
129 RgStr GetString (RgKey key) const;
130 RgAlg GetAlg (RgKey key) const;
131 RgH1F GetH1F (RgKey key) const;
132 RgH2F GetH2F (RgKey key) const;
133 RgTree GetTree (RgKey key) const;
134
135 RgBool GetBoolDef (RgKey key, RgBool def_opt, bool set_def=true);
136 RgInt GetIntDef (RgKey key, RgInt def_opt, bool set_def=true);
137 RgDbl GetDoubleDef (RgKey key, RgDbl def_opt, bool set_def=true);
138 RgStr GetStringDef (RgKey key, RgStr def_opt, bool set_def=true);
139 RgAlg GetAlgDef (RgKey key, RgAlg def_opt, bool set_def=true);
140
141 RgIMapConstIter SafeFind (RgKey key) const;
142
143 int NEntries (void) const; ///< get number of items
144 bool Exists (RgKey key) const; ///< item with input key exists?
145 bool CanSetItem (RgKey key) const; ///< can I set the specifed item?
146 bool DeleteEntry (RgKey key); ///< delete the spcified item
147 void SetName (string name); ///< set the registry name
148 string Name (void) const; ///< get the registry name
149 void Print (ostream & stream) const; ///< print the registry to stream
150 void Copy (const Registry &); ///< copy the input registry
151 void Append (const Registry &, RgKey pfx=""); ///< append the input registry. Entries already in the registry are not updated
152 void Merge (const Registry &, RgKey pfx=""); ///< append the input registry. Entries already in the registry are updated
153 void Clear (bool force = false); ///< clear the registry
154 void Init (void); ///< initialize the registry
155
156 RgType_t ItemType (RgKey key) const; ///< return item type
157 RgKeyList FindKeys (RgKey key_part) const; ///< create list with all keys containing 'key_part'
158
159 // Access key->item map
160 //
161 const RgIMap & GetItemMap(void) const { return fRegistry; }
162
163 // Convert to TFolder (this is the primary mechanism for saving the
164 // GENIE configuration in a ROOT file, along with its generated events)
165 //
166 void CopyToFolder (TFolder * folder) const;
167
168 // Assert the existence or registry items
169 //
170 void AssertExistence (RgKey key0) const;
171 void AssertExistence (RgKey key0, RgKey key1) const;
172 void AssertExistence (RgKey key0, RgKey key1, RgKey key2) const;
173
174private:
175
176 RegistryItemI * CloneRegistryItem( const RgKey & key ) const ; ///< Properly clone a registry Item according to its type
177
178 // Registry's private data members
179 //
180 string fName; ///< registry's name
181 bool fIsReadOnly; ///< is read only?
183 RgIMap fRegistry; ///< 'key' -> 'value' map
184};
185
186} // genie namespace
187
188#endif // _REGISTRY_H_
string RgStr
TTree * RgTree
bool RgBool
int RgInt
TH1F * RgH1F
double RgDbl
TH2F * RgH2F
const char * RgCChAr
string RgKey
Registry item pABC.
A registry. Provides the container for algorithm configuration parameters.
Definition Registry.h:65
const RgIMap & GetItemMap(void) const
Definition Registry.h:161
void Append(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are not updated
Definition Registry.cxx:743
void LinkToGlobalDef(RgKey key)
link its value to a global default (i.e. a 'global' item)
Definition Registry.cxx:206
void Merge(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are updated
Definition Registry.cxx:787
Registry & operator=(const Registry &reg)
Definition Registry.cxx:136
RgInt GetIntDef(RgKey key, RgInt def_opt, bool set_def=true)
Definition Registry.cxx:530
RgIMap fRegistry
'key' -> 'value' map
Definition Registry.h:183
RgDbl GetDouble(RgKey key) const
Definition Registry.cxx:474
void Lock(void)
locks the registry
Definition Registry.cxx:148
void Clear(bool force=false)
clear the registry
Definition Registry.cxx:864
RegistryItemI * CloneRegistryItem(const RgKey &key) const
Properly clone a registry Item according to its type.
Definition Registry.cxx:890
void operator()(RgKey key, int item)
Definition Registry.cxx:110
string Name(void) const
get the registry name
Definition Registry.cxx:597
RgIMapConstIter SafeFind(RgKey key) const
Definition Registry.cxx:550
void UnLockItem(RgKey key)
unlocks the registry item
Definition Registry.cxx:245
RgAlg GetAlg(RgKey key) const
Definition Registry.cxx:488
bool ItemLocksAreActive(void) const
check if item locks are active
Definition Registry.cxx:173
RgStr GetString(RgKey key) const
Definition Registry.cxx:481
void LockItem(RgKey key)
locks the registry item
Definition Registry.cxx:234
bool IsLocked(void) const
checks registry lock
Definition Registry.cxx:158
RgType_t ItemType(RgKey key) const
return item type
Definition Registry.cxx:829
bool CanSetItem(RgKey key) const
can I set the specifed item?
Definition Registry.cxx:256
void OverrideGlobalDef(RgKey key)
let item override global default (i.e. a 'local' item)
Definition Registry.cxx:194
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
Definition Registry.cxx:840
void AssertExistence(RgKey key0) const
Definition Registry.cxx:602
friend ostream & operator<<(ostream &stream, const Registry &registry)
Definition Registry.cxx:77
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
Definition Registry.cxx:525
int NEntries(void) const
get number of items
Definition Registry.cxx:582
RgH2F GetH2F(RgKey key) const
Definition Registry.cxx:505
RgStr GetStringDef(RgKey key, RgStr def_opt, bool set_def=true)
Definition Registry.cxx:540
bool DeleteEntry(RgKey key)
delete the spcified item
Definition Registry.cxx:569
Registry & operator+=(const Registry &reg)
Definition Registry.cxx:142
RgAlg GetAlgDef(RgKey key, RgAlg def_opt, bool set_def=true)
Definition Registry.cxx:545
bool fIsReadOnly
is read only?
Definition Registry.h:181
bool Exists(RgKey key) const
item with input key exists?
Definition Registry.cxx:563
void SetName(string name)
set the registry name
Definition Registry.cxx:588
RgInt GetInt(RgKey key) const
Definition Registry.cxx:467
bool ItemIsLocked(RgKey key) const
check item lock
Definition Registry.cxx:218
void Init(void)
initialize the registry
Definition Registry.cxx:855
bool fInhibitItemLocks
Definition Registry.h:182
bool ItemIsLocal(RgKey key) const
local or global?
Definition Registry.cxx:178
void InhibitItemLocks(void)
override individual item locks
Definition Registry.cxx:163
RgBool GetBool(RgKey key) const
Definition Registry.cxx:460
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
Definition Registry.cxx:535
virtual ~Registry()
Definition Registry.cxx:105
void Set(RgIMapPair entry)
Definition Registry.cxx:267
RgH1F GetH1F(RgKey key) const
Definition Registry.cxx:495
void Copy(const Registry &)
copy the input registry
Definition Registry.cxx:722
void Get(RgKey key, const RegistryItemI *&item) const
Definition Registry.cxx:325
RgTree GetTree(RgKey key) const
Definition Registry.cxx:515
void RestoreItemLocks(void)
restore individual item locks
Definition Registry.cxx:168
void UnLock(void)
unlocks the registry (doesn't unlock items)
Definition Registry.cxx:153
void CopyToFolder(TFolder *folder) const
Definition Registry.cxx:626
string fName
registry's name
Definition Registry.h:180
void Print(ostream &stream) const
print the registry to stream
Definition Registry.cxx:679
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
T GetValueOrUseDefault(Registry *r, RgKey key, T def, bool set_def)
Definition Registry.cxx:51
vector< RgKey > RgKeyList
Definition Registry.h:50
void SetRegistryItem(Registry *r, RgKey key, T item)
Definition Registry.cxx:39
enum genie::ERgType RgType_t
map< RgKey, RegistryItemI * > RgIMap
Definition Registry.h:45
pair< RgKey, RegistryItemI * > RgIMapPair
Definition Registry.h:46
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
Definition Registry.h:49
map< RgKey, RegistryItemI * >::size_type RgIMapSizeType
Definition Registry.h:47
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
map< RgKey, RegistryItemI * >::iterator RgIMapIter
Definition Registry.h:48