27{
28
29
30
31
32
33 RgAlg some_algorithm(
"alg-name",
"alg-config");
34
35 TH1F * h1 = new TH1F("h1","a TH1F to be passed as config param", 100,-5,5);
36 h1->Fill(3,100);
37 h1->Fill(2,50);
38
39
40
41
42
43
44
45 LOG(
"test",
pINFO) <<
"***** Basic Registry tests *****";
46
47 LOG(
"test",
pINFO) <<
"Building, Unlocking, Setting, Locking, Printing...";
48
49 Registry registry(
"example-registry");
50
51 registry.UnLock();
52
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);
60
61 registry.Lock();
62
63 LOG(
"test",
pINFO) <<
"registry:\n" << registry;
64
65
66
68 << "Trying to set variables in a locked registry - should fail";
69
70 registry.Set("var-int-2", 12);
71 registry.Set("var-int-3", 89);
72
73 LOG(
"test",
pINFO) <<
"registry:\n" << registry;
74
75
76
78 << "Unlock the registry first and then set the variables - should succeed";
79
80 registry.UnLock();
81
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"));
86
87 registry.Lock();
88
89 LOG(
"test",
pINFO) <<
"registry\n" << registry;
90
91
92
93
94
96 << "***** Testing copy constructor: Registry registry2(registry) *****";
97
99
100 LOG(
"test",
pINFO) <<
"Registry clone: \n" << registry2;
101 LOG(
"test",
pINFO) <<
"Original registry: \n" << registry;
102
103
104
105
106
107 LOG(
"test",
pINFO) <<
"***** Testing operator () *****";
108
109 registry2.UnLock();
110
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" );
115
116 registry2.Lock();
117
118 LOG(
"test",
pINFO) <<
"registry:\n" << registry2;
119
120
121
122
123
124 LOG(
"test",
pINFO) <<
"***** Testing data retrieval *****";
125
126 bool retrieved_bool = false;
127 int retrieved_int = 0;
128 double retrieved_double = 3.14;
129 string retrieved_string = "random init";
130
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);
135
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;
140
141
142
143
144
145 LOG(
"test",
pINFO) <<
"***** Testing Copy(const Registry & reg) *****";
146
148 registry3.
Copy(registry2);
149
150 LOG(
"test",
pINFO) <<
"Registry clone: \n" << registry3;
151 LOG(
"test",
pINFO) <<
"Original registry: \n" << registry2;
152
153
154
155
156
157 LOG(
"test",
pINFO) <<
"***** Testing individual item locking *****";
158
159 Registry registry4(
"example-registry-with-locked-items");
160
161 registry4.UnLock();
162
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" );
167
169 << "Initial registry: \n" << registry4;
170
171
172
173 registry4.LockItem("an int variable");
174 registry4.LockItem("a double variable");
175
177 << "Registry with locked keys: \n" << registry4;
178
180 << "Attempting to change locked items in unlocked registry";
181
182
183
184
185 registry4.Set("an int variable", 25);
186 registry4.Set("a double variable", 129320.21);
187
189 << "Should have failed to change locked entries: \n" << registry4;
190
191
192
193 LOG(
"test",
pINFO) <<
"Inhibit item locking";
194 registry4.InhibitItemLocks();
195
197 << "registry with item locks inhibited: \n" << registry4;
198
199
201 << "Retrying to change locked items in unlocked registry with inhibited item locking";
202
203 registry4.Set("an int variable", 25);
204 registry4.Set("a double variable", 9.21);
205
206 LOG(
"test",
pINFO) <<
"registry: \n" << registry4;
207
208
209
210
211
212 LOG(
"test",
pINFO) <<
"***** Testing operator = *****";
213
215
216 LOG(
"test",
pINFO) <<
"Printing registry set with the assignment operator = ";
217 LOG(
"test",
pINFO) <<
"registry: \n" << registry5;
218
219
220
221
222
223 LOG(
"test",
pINFO) <<
"***** Testing operator += *****";
224
225 registry5 += registry;
226
227 LOG(
"test",
pINFO) <<
"Printing registry after adding values with the += operator ";
228 LOG(
"test",
pINFO) <<
"registry: \n" << registry5;
229
230
231
232
233
234 LOG(
"test",
pINFO) <<
"***** Testing FindKeys() *****";
235
236 LOG(
"test",
pINFO) <<
"Looking for all entries whose key contain the word `variable'";
238
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;
243 }
244
245
246
247
248
250 LOG(
"test",
pINFO) <<
"***** Testing ItemType() *****";
251
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: "
264
265
267
268 return 0;
269}
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
A registry. Provides the container for algorithm configuration parameters.
RgType_t ItemType(RgKey key) const
return item type
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
void Copy(const Registry &)
copy the input registry
static string AsString(RgType_t rt)
vector< RgKey > RgKeyList