1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.4 2005/11/19 14:20:31 byordano
19 logbook config added to AliShuttleConfig
21 Revision 1.3 2005/11/17 19:24:25 byordano
22 TList changed to TObjArray in AliShuttleConfig
24 Revision 1.2 2005/11/17 14:43:23 byordano
27 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
28 Initial import as subdirectory in AliRoot
30 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
33 Revision 1.3 2005/08/30 09:13:02 byordano
40 // This class keeps the AliShuttle configuration.
41 // It reads the configuration for LDAP server.
42 // For every child entry in basedn which has schema type 'shuttleConfig'
43 // it creates a detector configuration. This configuration includes:
44 // DCS server host and port and the set of aliases for which data from
45 // will be retrieved (used by AliShuttle).
49 #include "AliShuttleConfig.h"
53 #include <TObjString.h>
54 #include <TLDAPResult.h>
55 #include <TLDAPEntry.h>
56 #include <TLDAPAttribute.h>
58 AliShuttleConfig::ConfigHolder::ConfigHolder(const TLDAPEntry* entry):
61 TLDAPAttribute* anAttribute;
63 anAttribute = entry->GetAttribute("dt");
65 AliError("Invalid configuration! Can't get detector name.");
68 fDetector = anAttribute->GetValue();
69 if (!fDetector.Length()) {
70 AliError("Detector name can't be an empty string!")
74 anAttribute = entry->GetAttribute("ipHost");
76 AliError("Invalid configuration! Can't get ipHost.");
79 fHost = anAttribute->GetValue();
80 if (!fHost.Length()) {
81 AliError("Host can't be an empty string!")
85 anAttribute = entry->GetAttribute("ipServicePort");
87 AliError("Invalid configuration! Can't get ipServicePort.");
90 TString portStr = anAttribute->GetValue();
91 if (!portStr.Length()) {
92 AliError("ipServicePort can't be an empty string!")
95 fPort = portStr.Atoi();
97 anAttribute = entry->GetAttribute("alias");
99 AliError("Invalid configuration! Can't get alias attribute.");
103 while ((anAlias = anAttribute->GetValue())) {
104 fAliases.AddLast(new TObjString(anAlias));
110 AliShuttleConfig::ConfigHolder::~ConfigHolder() {
114 ClassImp(AliShuttleConfig)
116 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
117 const char* binddn, const char* password, const char* basedn):
121 // host: ldap server host
122 // port: ldap server port
123 // binddn: binddn used for ldap binding (simple bind is used!).
124 // password: password for binddn
125 // basedn: this is basedn whose childeren entries which have
126 // (objectClass=shuttleConfig) will be used as detector configurations.
129 TLDAPServer aServer(host, port, binddn, password);
131 if (!aServer.IsConnected()) {
132 AliError(Form("Can't connect to ldap server %s:%d",
137 TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
138 "(objectClass=shuttleConfig)");
140 AliError(Form("Can't find configuration with base DN: %s",
146 while ((anEntry = aResult->GetNext())) {
147 ConfigHolder* aHolder = new ConfigHolder(anEntry);
150 if (!aHolder->IsValid()) {
151 AliError("This entry is going to be skipped!");
157 TObjString* detStr = new TObjString(aHolder->GetDetector());
158 fDetectorMap.Add(detStr, aHolder);
159 fDetectorList.AddLast(detStr);
165 aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
166 "(objectClass=logbookConfig)");
168 AliError(Form("Can't find configuration with base DN: %s",
173 if (aResult->GetCount() == 0) {
174 AliError("Can't find DAQ log book configuration!");
178 if (aResult->GetCount() > 1) {
179 AliError("More than one DAQ log book configuration found!");
183 anEntry = aResult->GetNext();
185 TLDAPAttribute* anAttribute;
186 anAttribute = anEntry->GetAttribute("lbURI");
188 AliError("Can't find lbURI attribute!");
191 fLogBookURI = anAttribute->GetValue();
193 anAttribute = anEntry->GetAttribute("lbUser");
195 AliError("Can't find lbUser attribute!");
198 fLogBookUser = anAttribute->GetValue();
200 anAttribute = anEntry->GetAttribute("lbPassword");
202 AliError("Can't find lbPassword attribute!");
205 fLogBookPassword = anAttribute->GetValue();
213 AliShuttleConfig::~AliShuttleConfig() {
214 fDetectorMap.DeleteAll();
217 const TObjArray* AliShuttleConfig::GetDetectors() const {
219 // returns collection of TObjString which contains the name
220 // of every detector which is in the configuration.
223 return &fDetectorList;
226 Bool_t AliShuttleConfig::HasDetector(const char* detector) const {
228 // checks for paricular detector in the configuration.
230 return fDetectorMap.GetValue(detector) != NULL;
233 const char* AliShuttleConfig::GetHost(const char* detector) const {
235 // returns DCS server host used by particular detector
238 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
240 AliError(Form("There isn't configuration for detector: %s",
245 return aHolder->GetHost();
248 Int_t AliShuttleConfig::GetPort(const char* detector) const {
250 // returns DCS server port used by particular detector
254 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
256 AliError(Form("There isn't configuration for detector: %s",
261 return aHolder->GetPort();
264 const TObjArray* AliShuttleConfig::GetAliases(const char* detector) const {
266 // returns collection of TObjString which represents the set of aliases
267 // which used for data retrieval for particular detector
270 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
272 AliError(Form("There isn't configuration for detector: %s",
277 return aHolder->GetAliases();
280 void AliShuttleConfig::Print(Option_t* /*option*/) const {
285 result += "LogBook URI: ";
286 result += fLogBookURI;
288 result += "LogBook User: ";
289 result += fLogBookUser;
291 result += "LogBook Password: ";
292 result.Append('*', fLogBookPassword.Length());
295 TIter iter(fDetectorMap.GetTable());
297 while ((aPair = (TPair*) iter.Next())) {
298 ConfigHolder* aHolder = (ConfigHolder*) aPair->Value();
300 result += " Detector: ";
301 result += aHolder->GetDetector();
304 result += aHolder->GetHost();
307 result += aHolder->GetPort();
310 result += " Aliases: ";
311 const TObjArray* aliases = aHolder->GetAliases();
314 while ((anAlias = (TObjString*) it.Next())) {
315 result += anAlias->String();