]>
Commit | Line | Data |
---|---|---|
73abe331 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | $Log$ | |
58bc3020 | 18 | Revision 1.3 2006/06/06 14:26:40 jgrosseo |
19 | o) removed files that were moved to STEER | |
20 | o) shuttle updated to follow the new interface (Alberto) | |
21 | ||
b948db8d | 22 | Revision 1.7 2006/05/12 09:07:16 colla |
23 | 12/05/06 | |
24 | New configuration complete | |
25 | ||
26 | Revision 1.2 2006/03/07 07:52:34 hristov | |
27 | New version (B.Yordanov) | |
28 | ||
d477ad88 | 29 | Revision 1.4 2005/11/19 14:20:31 byordano |
30 | logbook config added to AliShuttleConfig | |
31 | ||
32 | Revision 1.3 2005/11/17 19:24:25 byordano | |
33 | TList changed to TObjArray in AliShuttleConfig | |
34 | ||
35 | Revision 1.2 2005/11/17 14:43:23 byordano | |
36 | import to local CVS | |
37 | ||
38 | Revision 1.1.1.1 2005/10/28 07:33:58 hristov | |
39 | Initial import as subdirectory in AliRoot | |
40 | ||
73abe331 | 41 | Revision 1.1.1.1 2005/09/12 22:11:40 byordano |
42 | SHUTTLE package | |
43 | ||
44 | Revision 1.3 2005/08/30 09:13:02 byordano | |
45 | some docs added | |
46 | ||
47 | */ | |
48 | ||
49 | ||
50 | // | |
51 | // This class keeps the AliShuttle configuration. | |
52 | // It reads the configuration for LDAP server. | |
53 | // For every child entry in basedn which has schema type 'shuttleConfig' | |
54 | // it creates a detector configuration. This configuration includes: | |
55 | // DCS server host and port and the set of aliases for which data from | |
56 | // will be retrieved (used by AliShuttle). | |
57 | // | |
58 | ||
59 | ||
60 | #include "AliShuttleConfig.h" | |
61 | ||
62 | #include "AliLog.h" | |
63 | ||
b948db8d | 64 | #include <TSystem.h> |
73abe331 | 65 | #include <TObjString.h> |
66 | #include <TLDAPResult.h> | |
67 | #include <TLDAPEntry.h> | |
68 | #include <TLDAPAttribute.h> | |
69 | ||
58bc3020 | 70 | AliShuttleConfig::AliShuttleConfigHolder::AliShuttleConfigHolder(const TLDAPEntry* entry): |
73abe331 | 71 | fIsValid(kFALSE) |
72 | { | |
58bc3020 | 73 | // constructor of the shuttle configuration holder |
74 | ||
73abe331 | 75 | TLDAPAttribute* anAttribute; |
76 | ||
b948db8d | 77 | anAttribute = entry->GetAttribute("det"); |
73abe331 | 78 | if (!anAttribute) { |
79 | AliError("Invalid configuration! Can't get detector name."); | |
80 | return; | |
81 | } | |
82 | fDetector = anAttribute->GetValue(); | |
83 | if (!fDetector.Length()) { | |
84 | AliError("Detector name can't be an empty string!") | |
85 | return; | |
86 | } | |
87 | ||
b948db8d | 88 | anAttribute = entry->GetAttribute("DCSHost"); |
73abe331 | 89 | if (!anAttribute) { |
b948db8d | 90 | AliError("Invalid configuration! Can't get DCSHost."); |
73abe331 | 91 | return; |
92 | } | |
b948db8d | 93 | fDCSHost = anAttribute->GetValue(); |
94 | if (!fDCSHost.Length()) { | |
73abe331 | 95 | AliError("Host can't be an empty string!") |
96 | return; | |
97 | } | |
98 | ||
b948db8d | 99 | anAttribute = entry->GetAttribute("DCSPort"); |
73abe331 | 100 | if (!anAttribute) { |
b948db8d | 101 | AliError("Invalid configuration! Can't get DCSPort."); |
73abe331 | 102 | return; |
103 | } | |
104 | TString portStr = anAttribute->GetValue(); | |
105 | if (!portStr.Length()) { | |
b948db8d | 106 | AliError("port can't be an empty string!") |
73abe331 | 107 | return; |
108 | } | |
b948db8d | 109 | fDCSPort = portStr.Atoi(); |
73abe331 | 110 | |
b948db8d | 111 | anAttribute = entry->GetAttribute("DCSAlias"); |
73abe331 | 112 | if (!anAttribute) { |
113 | AliError("Invalid configuration! Can't get alias attribute."); | |
114 | return; | |
115 | } | |
116 | const char* anAlias; | |
117 | while ((anAlias = anAttribute->GetValue())) { | |
b948db8d | 118 | fDCSAliases.AddLast(new TObjString(anAlias)); |
119 | } | |
120 | ||
121 | anAttribute = entry->GetAttribute("DAQFileIDs"); | |
122 | if (!anAttribute) { | |
123 | AliError("Invalid configuration! Can't get DAQFileIDs attribute."); | |
124 | return; | |
125 | } | |
126 | const char* aFileID; | |
127 | while ((aFileID = anAttribute->GetValue())) { | |
128 | fDAQFileIDs.AddLast(new TObjString(aFileID)); | |
73abe331 | 129 | } |
130 | ||
131 | fIsValid = kTRUE; | |
132 | } | |
133 | ||
58bc3020 | 134 | AliShuttleConfig::AliShuttleConfigHolder::~AliShuttleConfigHolder() |
135 | { | |
136 | // destructor of the shuttle configuration holder | |
137 | ||
b948db8d | 138 | fDCSAliases.Delete(); |
73abe331 | 139 | } |
140 | ||
141 | ClassImp(AliShuttleConfig) | |
142 | ||
143 | AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port, | |
144 | const char* binddn, const char* password, const char* basedn): | |
b948db8d | 145 | fIsValid(kFALSE), |
146 | fProcessAll(kFALSE) | |
73abe331 | 147 | { |
148 | // | |
149 | // host: ldap server host | |
150 | // port: ldap server port | |
151 | // binddn: binddn used for ldap binding (simple bind is used!). | |
152 | // password: password for binddn | |
b948db8d | 153 | // basedn: this is basedn whose childeren entries which have |
73abe331 | 154 | // (objectClass=shuttleConfig) will be used as detector configurations. |
155 | // | |
156 | ||
b948db8d | 157 | TLDAPServer aServer(host, port, binddn, password, 3); |
73abe331 | 158 | |
159 | if (!aServer.IsConnected()) { | |
160 | AliError(Form("Can't connect to ldap server %s:%d", | |
161 | host, port)); | |
162 | return; | |
163 | } | |
164 | ||
b948db8d | 165 | // reads configuration for the shuttle running on this machine |
166 | ||
167 | fShuttleInstanceHost = gSystem->HostName(); | |
168 | TString queryFilter = "(ShuttleHost="; | |
169 | queryFilter += fShuttleInstanceHost; | |
170 | queryFilter += ")"; | |
171 | ||
73abe331 | 172 | TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, |
b948db8d | 173 | queryFilter.Data()); |
174 | ||
73abe331 | 175 | if (!aResult) { |
176 | AliError(Form("Can't find configuration with base DN: %s", | |
177 | basedn)); | |
178 | return; | |
179 | } | |
b948db8d | 180 | |
181 | if (aResult->GetCount() == 0) { | |
182 | AliError(Form("No Shuttle instance for host = %s!",fShuttleInstanceHost.Data())); | |
183 | AliError(Form("All detectors will be processed.")); | |
184 | fProcessAll=kTRUE; | |
185 | } | |
186 | ||
187 | if (aResult->GetCount() > 1) { | |
188 | AliError(Form("More than one Shuttle instance for host %s!",fShuttleInstanceHost.Data())); | |
189 | return; | |
190 | } | |
73abe331 | 191 | |
192 | TLDAPEntry* anEntry; | |
b948db8d | 193 | TLDAPAttribute* anAttribute; |
194 | ||
195 | if(!fProcessAll){ | |
196 | anEntry = aResult->GetNext(); | |
197 | anAttribute = anEntry->GetAttribute("detectors"); | |
198 | const char *detName; | |
199 | while((detName = anAttribute->GetValue())){ | |
200 | TObjString *objDet= new TObjString(detName); | |
201 | fProcessedDetectors.Add(objDet); | |
202 | } | |
203 | } | |
204 | ||
205 | aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, | |
206 | "(objectClass=AliShuttleDetector)"); | |
207 | if (!aResult) { | |
208 | AliError(Form("Can't find configuration with base DN: %s", | |
209 | basedn)); | |
210 | return; | |
211 | } | |
212 | ||
73abe331 | 213 | while ((anEntry = aResult->GetNext())) { |
58bc3020 | 214 | AliShuttleConfigHolder* aHolder = new AliShuttleConfigHolder(anEntry); |
73abe331 | 215 | delete anEntry; |
216 | ||
217 | if (!aHolder->IsValid()) { | |
218 | AliError("This entry is going to be skipped!"); | |
219 | delete aHolder; | |
220 | ||
221 | continue; | |
222 | } | |
223 | ||
224 | TObjString* detStr = new TObjString(aHolder->GetDetector()); | |
225 | fDetectorMap.Add(detStr, aHolder); | |
d477ad88 | 226 | fDetectorList.AddLast(detStr); |
73abe331 | 227 | } |
228 | ||
229 | delete aResult; | |
230 | ||
d477ad88 | 231 | |
232 | aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, | |
b948db8d | 233 | "(objectClass=AliShuttleGlobalConfig)"); |
d477ad88 | 234 | if (!aResult) { |
235 | AliError(Form("Can't find configuration with base DN: %s", | |
236 | basedn)); | |
237 | return; | |
238 | } | |
239 | ||
240 | if (aResult->GetCount() == 0) { | |
b948db8d | 241 | AliError("Can't find DAQ logbook configuration!"); |
d477ad88 | 242 | return; |
243 | } | |
244 | ||
245 | if (aResult->GetCount() > 1) { | |
b948db8d | 246 | AliError("More than one DAQ logbook configuration found!"); |
d477ad88 | 247 | return; |
248 | } | |
249 | ||
250 | anEntry = aResult->GetNext(); | |
251 | ||
b948db8d | 252 | anAttribute = anEntry->GetAttribute("DAQLogbookHost"); |
d477ad88 | 253 | if (!anAttribute) { |
b948db8d | 254 | AliError("Can't find DAQLogbookHost attribute!"); |
d477ad88 | 255 | return; |
256 | } | |
b948db8d | 257 | fDAQLogBookHost = anAttribute->GetValue(); |
d477ad88 | 258 | |
b948db8d | 259 | anAttribute = anEntry->GetAttribute("DAQLogbookUser"); |
d477ad88 | 260 | if (!anAttribute) { |
b948db8d | 261 | AliError("Can't find DAQLogbookUser attribute!"); |
d477ad88 | 262 | return; |
263 | } | |
b948db8d | 264 | fDAQLogBookUser = anAttribute->GetValue(); |
d477ad88 | 265 | |
b948db8d | 266 | anAttribute = anEntry->GetAttribute("DAQLogbookPassword"); |
d477ad88 | 267 | if (!anAttribute) { |
b948db8d | 268 | AliError("Can't find DAQLogbookPassword attribute!"); |
d477ad88 | 269 | return; |
270 | } | |
b948db8d | 271 | fDAQLogBookPassword = anAttribute->GetValue(); |
272 | ||
273 | anAttribute = anEntry->GetAttribute("DAQFileSystemHost"); | |
274 | if (!anAttribute) { | |
275 | AliError("Can't find DAQFileSystemHost attribute!"); | |
276 | return; | |
277 | } | |
278 | fDAQFSHost = anAttribute->GetValue(); | |
d477ad88 | 279 | |
280 | delete anEntry; | |
281 | delete aResult; | |
282 | ||
73abe331 | 283 | fIsValid = kTRUE; |
284 | } | |
285 | ||
58bc3020 | 286 | AliShuttleConfig::~AliShuttleConfig() |
287 | { | |
288 | // destructor | |
289 | ||
73abe331 | 290 | fDetectorMap.DeleteAll(); |
291 | } | |
292 | ||
58bc3020 | 293 | const TObjArray* AliShuttleConfig::GetDetectors() const |
294 | { | |
73abe331 | 295 | // |
296 | // returns collection of TObjString which contains the name | |
297 | // of every detector which is in the configuration. | |
298 | // | |
299 | ||
300 | return &fDetectorList; | |
301 | } | |
302 | ||
58bc3020 | 303 | Bool_t AliShuttleConfig::HasDetector(const char* detector) const |
304 | { | |
73abe331 | 305 | // |
306 | // checks for paricular detector in the configuration. | |
307 | // | |
308 | return fDetectorMap.GetValue(detector) != NULL; | |
309 | } | |
310 | ||
58bc3020 | 311 | const char* AliShuttleConfig::GetDCSHost(const char* detector) const |
312 | { | |
73abe331 | 313 | // |
314 | // returns DCS server host used by particular detector | |
315 | // | |
316 | ||
58bc3020 | 317 | AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector); |
73abe331 | 318 | if (!aHolder) { |
319 | AliError(Form("There isn't configuration for detector: %s", | |
320 | detector)); | |
321 | return NULL; | |
322 | } | |
323 | ||
b948db8d | 324 | return aHolder->GetDCSHost(); |
73abe331 | 325 | } |
326 | ||
58bc3020 | 327 | Int_t AliShuttleConfig::GetDCSPort(const char* detector) const |
328 | { | |
73abe331 | 329 | // |
330 | // returns DCS server port used by particular detector | |
331 | // | |
332 | ||
333 | ||
58bc3020 | 334 | AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector); |
73abe331 | 335 | if (!aHolder) { |
336 | AliError(Form("There isn't configuration for detector: %s", | |
337 | detector)); | |
338 | return 0; | |
339 | } | |
340 | ||
b948db8d | 341 | return aHolder->GetDCSPort(); |
73abe331 | 342 | } |
343 | ||
58bc3020 | 344 | const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector) const |
345 | { | |
73abe331 | 346 | // |
347 | // returns collection of TObjString which represents the set of aliases | |
348 | // which used for data retrieval for particular detector | |
349 | // | |
350 | ||
58bc3020 | 351 | AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector); |
73abe331 | 352 | if (!aHolder) { |
353 | AliError(Form("There isn't configuration for detector: %s", | |
354 | detector)); | |
355 | return NULL; | |
356 | } | |
357 | ||
b948db8d | 358 | return aHolder->GetDCSAliases(); |
359 | } | |
360 | ||
58bc3020 | 361 | const TObjArray* AliShuttleConfig::GetDAQFileIDs(const char* detector) const |
362 | { | |
b948db8d | 363 | // |
364 | // returns collection of TObjString which represents the set of DAQ file IDs | |
365 | // which used for data retrieval for particular detector | |
366 | // | |
367 | ||
58bc3020 | 368 | AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector); |
b948db8d | 369 | if (!aHolder) { |
370 | AliError(Form("There isn't configuration for detector: %s", | |
371 | detector)); | |
372 | return NULL; | |
373 | } | |
374 | ||
375 | return aHolder->GetDAQFileIDs(); | |
376 | } | |
377 | ||
58bc3020 | 378 | Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const |
379 | { | |
b948db8d | 380 | // return TRUE if detector is handled by host or if fProcessAll is TRUE |
381 | ||
382 | if(fProcessAll) return kTRUE; | |
383 | TIter iter(&fProcessedDetectors); | |
384 | TObjString* detName; | |
385 | while((detName = (TObjString*) iter.Next())){ | |
386 | if(detName->String() == detector) return kTRUE; | |
387 | } | |
388 | return kFALSE; | |
73abe331 | 389 | } |
390 | ||
58bc3020 | 391 | void AliShuttleConfig::Print(Option_t* /*option*/) const |
392 | { | |
393 | // print configuration | |
73abe331 | 394 | |
395 | TString result; | |
396 | result += '\n'; | |
d477ad88 | 397 | |
b948db8d | 398 | result += "Shuttle running on host: "; |
399 | result += fShuttleInstanceHost; | |
d477ad88 | 400 | result += '\n'; |
b948db8d | 401 | result += "Detectors handled by this host: "; |
402 | TIter it(&fProcessedDetectors); | |
403 | TObjString* aDet; | |
404 | while ((aDet = (TObjString*) it.Next())) { | |
405 | result += aDet->String(); | |
406 | result += ' '; | |
407 | } | |
d477ad88 | 408 | result += '\n'; |
b948db8d | 409 | if(fProcessAll) result += "ProcessAll is ON"; |
410 | ||
d477ad88 | 411 | result += '\n'; |
b948db8d | 412 | result += '\n'; |
413 | ||
414 | result += "DAQ LogBook Host: "; | |
415 | result += fDAQLogBookHost; | |
416 | result += '\n'; | |
417 | result += "DAQ LogBook User: "; | |
418 | result += fDAQLogBookUser; | |
419 | result += '\n'; | |
420 | result += "DAQ LogBook Password: "; | |
421 | result.Append('*', fDAQLogBookPassword.Length()); | |
422 | result += '\n'; | |
423 | result += '\n'; | |
424 | result += "DAQ File System Host: "; | |
425 | result += fDAQFSHost; | |
426 | result += '\n'; | |
427 | ||
73abe331 | 428 | TIter iter(fDetectorMap.GetTable()); |
429 | TPair* aPair; | |
430 | while ((aPair = (TPair*) iter.Next())) { | |
58bc3020 | 431 | AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) aPair->Value(); |
73abe331 | 432 | result += '\n'; |
433 | result += " Detector: "; | |
434 | result += aHolder->GetDetector(); | |
435 | result += '\n'; | |
b948db8d | 436 | result += " DCS Host: "; |
437 | result += aHolder->GetDCSHost(); | |
73abe331 | 438 | result += '\n'; |
b948db8d | 439 | result += " DCS Port: "; |
440 | result += aHolder->GetDCSPort(); | |
73abe331 | 441 | result += '\n'; |
442 | ||
b948db8d | 443 | result += " DCS Aliases: "; |
444 | const TObjArray* aliases = aHolder->GetDCSAliases(); | |
445 | TIter it(aliases); | |
73abe331 | 446 | TObjString* anAlias; |
447 | while ((anAlias = (TObjString*) it.Next())) { | |
448 | result += anAlias->String(); | |
449 | result += ' '; | |
450 | } | |
451 | ||
452 | result += '\n'; | |
b948db8d | 453 | |
454 | result += " DAQ File IDs: "; | |
455 | const TObjArray* fileIDs = aHolder->GetDAQFileIDs(); | |
456 | TIter it2(fileIDs); | |
457 | TObjString* aFileID; | |
458 | while ((aFileID = (TObjString*) it2.Next())) { | |
459 | result += aFileID->String(); | |
460 | result += ' '; | |
461 | } | |
462 | result += '\n'; | |
73abe331 | 463 | } |
464 | ||
465 | AliInfo(result); | |
466 | } |