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