24 using namespace genie;
33 RgAlg some_algorithm(
"alg-name",
"alg-config");
35 TH1F * h1 =
new TH1F(
"h1",
"a TH1F to be passed as config param", 100,-5,5);
45 LOG(
"test",
pINFO) <<
"***** Basic Registry tests *****";
47 LOG(
"test",
pINFO) <<
"Building, Unlocking, Setting, Locking, Printing...";
49 Registry registry(
"example-registry");
53 registry.
Set(
"var-bool-1",
true);
54 registry.
Set(
"var-double-1", 2.289);
55 registry.
Set(
"var-double-2", 4.190);
56 registry.
Set(
"var-int-1", 0);
57 registry.
Set(
"var-int-2", 11);
58 registry.
Set(
string(
"var-th1f-1"), h1);
59 registry.
Set(
"myalg", some_algorithm);
63 LOG(
"test",
pINFO) <<
"registry:\n" << registry;
68 <<
"Trying to set variables in a locked registry - should fail";
70 registry.
Set(
"var-int-2", 12);
71 registry.
Set(
"var-int-3", 89);
73 LOG(
"test",
pINFO) <<
"registry:\n" << registry;
78 <<
"Unlock the registry first and then set the variables - should succeed";
82 registry.
Set(
"var-int-2", 12);
83 registry.
Set(
"var-int-3", 89);
84 registry.
Set(
"var-string-1",
string(
"this is a string"));
85 registry.
Set(
"var-string-2",
string(
"and this is another string"));
89 LOG(
"test",
pINFO) <<
"registry\n" << registry;
96 <<
"***** Testing copy constructor: Registry registry2(registry) *****";
100 LOG(
"test",
pINFO) <<
"Registry clone: \n" << registry2;
101 LOG(
"test",
pINFO) <<
"Original registry: \n" << registry;
107 LOG(
"test",
pINFO) <<
"***** Testing operator () *****";
111 registry2(
"added an integer with ()", 7 );
112 registry2(
"added a boolean with ()",
true );
113 registry2(
"added a double with ()", 3.14 );
114 registry2(
"added a string with ()",
"ok" );
118 LOG(
"test",
pINFO) <<
"registry:\n" << registry2;
124 LOG(
"test",
pINFO) <<
"***** Testing data retrieval *****";
126 bool retrieved_bool =
false;
127 int retrieved_int = 0;
128 double retrieved_double = 3.14;
129 string retrieved_string =
"random init";
131 registry.
Get(
"var-bool-1", retrieved_bool );
132 registry.
Get(
"var-int-1", retrieved_int );
133 registry.
Get(
"var-double-1", retrieved_double);
134 registry.
Get(
"var-string-1", retrieved_string);
136 LOG(
"test",
pINFO) <<
"retrieved-bool = " << retrieved_bool;
137 LOG(
"test",
pINFO) <<
"retrieved-int = " << retrieved_int;
138 LOG(
"test",
pINFO) <<
"retrieved-double = " << retrieved_double;
139 LOG(
"test",
pINFO) <<
"retrieved-string = " << retrieved_string;
145 LOG(
"test",
pINFO) <<
"***** Testing Copy(const Registry & reg) *****";
148 registry3.
Copy(registry2);
150 LOG(
"test",
pINFO) <<
"Registry clone: \n" << registry3;
151 LOG(
"test",
pINFO) <<
"Original registry: \n" << registry2;
157 LOG(
"test",
pINFO) <<
"***** Testing individual item locking *****";
159 Registry registry4(
"example-registry-with-locked-items");
163 registry4(
"an int variable", 19 );
164 registry4(
"a bool variable",
true );
165 registry4(
"a double variable", 2.71 );
166 registry4(
"a string variable",
"hello" );
169 <<
"Initial registry: \n" << registry4;
173 registry4.
LockItem(
"an int variable");
174 registry4.
LockItem(
"a double variable");
177 <<
"Registry with locked keys: \n" << registry4;
180 <<
"Attempting to change locked items in unlocked registry";
185 registry4.
Set(
"an int variable", 25);
186 registry4.
Set(
"a double variable", 129320.21);
189 <<
"Should have failed to change locked entries: \n" << registry4;
193 LOG(
"test",
pINFO) <<
"Inhibit item locking";
197 <<
"registry with item locks inhibited: \n" << registry4;
201 <<
"Retrying to change locked items in unlocked registry with inhibited item locking";
203 registry4.
Set(
"an int variable", 25);
204 registry4.
Set(
"a double variable", 9.21);
206 LOG(
"test",
pINFO) <<
"registry: \n" << registry4;
212 LOG(
"test",
pINFO) <<
"***** Testing operator = *****";
216 LOG(
"test",
pINFO) <<
"Printing registry set with the assignment operator = ";
217 LOG(
"test",
pINFO) <<
"registry: \n" << registry5;
223 LOG(
"test",
pINFO) <<
"***** Testing operator += *****";
225 registry5 += registry;
227 LOG(
"test",
pINFO) <<
"Printing registry after adding values with the += operator ";
228 LOG(
"test",
pINFO) <<
"registry: \n" << registry5;
234 LOG(
"test",
pINFO) <<
"***** Testing FindKeys() *****";
236 LOG(
"test",
pINFO) <<
"Looking for all entries whose key contain the word `variable'";
239 LOG(
"test",
pINFO) <<
"Found " << klist.size() <<
" entries";
240 RgKeyList::const_iterator kiter = klist.begin();
241 for( ; kiter != klist.end(); ++kiter) {
242 LOG(
"test",
pINFO) <<
"Matching key: " << *kiter;
250 LOG(
"test",
pINFO) <<
"***** Testing ItemType() *****";
253 <<
"Type of var pointed to by key = `var-int-2' is: "
256 <<
"Type of var pointed to by key = `var-string-1' is: "
259 <<
"Type of var pointed to by key = `var-th1f-1' is: "
262 <<
"Type of var pointed to by key = `??&&bla bla ###@ :-)' is: "
static string AsString(RgType_t rt)
void InhibitItemLocks(void)
override individual item locks
void LockItem(RgKey key)
locks the registry item
int main(int argc, char **argv)
void Copy(const Registry &)
copy the input registry
RgType_t ItemType(RgKey key) const
return item type
void Get(RgKey key, const RegistryItemI *&item) const
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
void Lock(void)
locks the registry
vector< RgKey > RgKeyList
void UnLock(void)
unlocks the registry (doesn't unlock items)
A registry. Provides the container for algorithm configuration parameters.
void Set(RgIMapPair entry)