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.1.1.1 2005/09/12 22:11:40 byordano
21 Revision 1.3 2005/08/30 09:13:02 byordano
28 // This class keeps the AliShuttle configuration.
29 // It reads the configuration for LDAP server.
30 // For every child entry in basedn which has schema type 'shuttleConfig'
31 // it creates a detector configuration. This configuration includes:
32 // DCS server host and port and the set of aliases for which data from
33 // will be retrieved (used by AliShuttle).
37 #include "AliShuttleConfig.h"
41 #include <TObjString.h>
42 #include <TLDAPResult.h>
43 #include <TLDAPEntry.h>
44 #include <TLDAPAttribute.h>
46 AliShuttleConfig::ConfigHolder::ConfigHolder(const TLDAPEntry* entry):
49 TLDAPAttribute* anAttribute;
51 anAttribute = entry->GetAttribute("dt");
53 AliError("Invalid configuration! Can't get detector name.");
56 fDetector = anAttribute->GetValue();
57 if (!fDetector.Length()) {
58 AliError("Detector name can't be an empty string!")
62 anAttribute = entry->GetAttribute("ipHost");
64 AliError("Invalid configuration! Can't get ipHost.");
67 fHost = anAttribute->GetValue();
68 if (!fHost.Length()) {
69 AliError("Host can't be an empty string!")
73 anAttribute = entry->GetAttribute("ipServicePort");
75 AliError("Invalid configuration! Can't get ipServicePort.");
78 TString portStr = anAttribute->GetValue();
79 if (!portStr.Length()) {
80 AliError("ipServicePort can't be an empty string!")
83 fPort = portStr.Atoi();
85 anAttribute = entry->GetAttribute("alias");
87 AliError("Invalid configuration! Can't get alias attribute.");
91 while ((anAlias = anAttribute->GetValue())) {
92 fAliases.Add(new TObjString(anAlias));
98 AliShuttleConfig::ConfigHolder::~ConfigHolder() {
102 ClassImp(AliShuttleConfig)
104 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
105 const char* binddn, const char* password, const char* basedn):
109 // host: ldap server host
110 // port: ldap server port
111 // binddn: binddn used for ldap binding (simple bind is used!).
112 // password: password for binddn
113 // basedn: this is basedn whose childeren entries which have
114 // (objectClass=shuttleConfig) will be used as detector configurations.
117 TLDAPServer aServer(host, port, binddn, password);
119 if (!aServer.IsConnected()) {
120 AliError(Form("Can't connect to ldap server %s:%d",
125 TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
126 "(objectClass=shuttleConfig)");
128 AliError(Form("Can't find configuration with base DN: %s",
134 while ((anEntry = aResult->GetNext())) {
135 ConfigHolder* aHolder = new ConfigHolder(anEntry);
138 if (!aHolder->IsValid()) {
139 AliError("This entry is going to be skipped!");
145 TObjString* detStr = new TObjString(aHolder->GetDetector());
146 fDetectorMap.Add(detStr, aHolder);
147 fDetectorList.Add(detStr);
155 AliShuttleConfig::~AliShuttleConfig() {
156 fDetectorMap.DeleteAll();
159 const TList* AliShuttleConfig::GetDetectors() const {
161 // returns collection of TObjString which contains the name
162 // of every detector which is in the configuration.
165 return &fDetectorList;
168 Bool_t AliShuttleConfig::HasDetector(const char* detector) const {
170 // checks for paricular detector in the configuration.
172 return fDetectorMap.GetValue(detector) != NULL;
175 const char* AliShuttleConfig::GetHost(const char* detector) const {
177 // returns DCS server host used by particular detector
180 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
182 AliError(Form("There isn't configuration for detector: %s",
187 return aHolder->GetHost();
190 Int_t AliShuttleConfig::GetPort(const char* detector) const {
192 // returns DCS server port used by particular detector
196 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
198 AliError(Form("There isn't configuration for detector: %s",
203 return aHolder->GetPort();
206 const TList* AliShuttleConfig::GetAliases(const char* detector) const {
208 // returns collection of TObjString which represents the set of aliases
209 // which used for data retrieval for particular detector
212 ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
214 AliError(Form("There isn't configuration for detector: %s",
219 return aHolder->GetAliases();
222 void AliShuttleConfig::Print(Option_t* /*option*/) const {
227 TIter iter(fDetectorMap.GetTable());
229 while ((aPair = (TPair*) iter.Next())) {
230 ConfigHolder* aHolder = (ConfigHolder*) aPair->Value();
232 result += " Detector: ";
233 result += aHolder->GetDetector();
236 result += aHolder->GetHost();
239 result += aHolder->GetPort();
242 result += " Aliases: ";
243 const TList* aliases = aHolder->GetAliases();
246 while ((anAlias = (TObjString*) it.Next())) {
247 result += anAlias->String();