]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleConfig.cxx
This commit was generated by cvs2svn to compensate for changes in r12269,
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleConfig.cxx
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$
18 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
19 SHUTTLE package
20
21 Revision 1.3  2005/08/30 09:13:02  byordano
22 some docs added
23
24 */
25
26
27 //
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).
34 //
35
36
37 #include "AliShuttleConfig.h"
38
39 #include "AliLog.h"
40
41 #include <TObjString.h>
42 #include <TLDAPResult.h>
43 #include <TLDAPEntry.h>
44 #include <TLDAPAttribute.h>
45
46 AliShuttleConfig::ConfigHolder::ConfigHolder(const TLDAPEntry* entry):
47         fIsValid(kFALSE)
48 {
49         TLDAPAttribute* anAttribute;
50         
51         anAttribute = entry->GetAttribute("dt");
52         if (!anAttribute) {
53                 AliError("Invalid configuration! Can't get detector name.");
54                 return;
55         }
56         fDetector = anAttribute->GetValue();
57         if (!fDetector.Length()) {
58                 AliError("Detector name can't be an empty string!")
59                 return;
60         }
61
62         anAttribute = entry->GetAttribute("ipHost");
63         if (!anAttribute) {
64                 AliError("Invalid configuration! Can't get ipHost.");
65                 return;
66         }
67         fHost = anAttribute->GetValue();
68         if (!fHost.Length()) {
69                 AliError("Host can't be an empty string!")
70                 return;
71         }
72
73         anAttribute = entry->GetAttribute("ipServicePort");
74         if (!anAttribute) {
75                 AliError("Invalid configuration! Can't get ipServicePort.");
76                 return;
77         }
78         TString portStr = anAttribute->GetValue();
79         if (!portStr.Length()) {
80                 AliError("ipServicePort can't be an empty string!")
81                 return;
82         }
83         fPort = portStr.Atoi();
84
85         anAttribute = entry->GetAttribute("alias");
86         if (!anAttribute) {
87                 AliError("Invalid configuration! Can't get alias attribute.");
88                 return;
89         }
90         const char* anAlias;
91         while ((anAlias = anAttribute->GetValue())) {
92                 fAliases.Add(new TObjString(anAlias));
93         }
94                 
95         fIsValid = kTRUE;
96 }
97
98 AliShuttleConfig::ConfigHolder::~ConfigHolder() {
99         fAliases.Delete();
100 }
101
102 ClassImp(AliShuttleConfig)
103
104 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port, 
105         const char* binddn, const char* password, const char* basedn):
106         fIsValid(kFALSE)
107 {
108         //
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.
115         //
116
117         TLDAPServer aServer(host, port, binddn, password);
118         
119         if (!aServer.IsConnected()) {
120                 AliError(Form("Can't connect to ldap server %s:%d", 
121                                 host, port));
122                 return;
123         }
124
125         TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
126                         "(objectClass=shuttleConfig)");
127         if (!aResult) {
128                 AliError(Form("Can't find configuration with base DN: %s",
129                                 basedn));
130                 return;
131         }
132         
133         TLDAPEntry* anEntry;
134         while ((anEntry = aResult->GetNext())) {
135                 ConfigHolder* aHolder = new ConfigHolder(anEntry);
136                 delete anEntry;
137
138                 if (!aHolder->IsValid()) {
139                         AliError("This entry is going to be skipped!");
140                         delete aHolder;
141
142                         continue;
143                 }
144
145                 TObjString* detStr = new TObjString(aHolder->GetDetector());
146                 fDetectorMap.Add(detStr, aHolder);
147                 fDetectorList.Add(detStr);
148         }       
149         
150         delete aResult;
151
152         fIsValid = kTRUE;
153 }
154
155 AliShuttleConfig::~AliShuttleConfig() {
156         fDetectorMap.DeleteAll();
157 }
158
159 const TList* AliShuttleConfig::GetDetectors() const {
160         //
161         // returns collection of TObjString which contains the name
162         // of every detector which is in the configuration.
163         //
164
165         return &fDetectorList;
166 }
167
168 Bool_t AliShuttleConfig::HasDetector(const char* detector) const {
169         //
170         // checks for paricular detector in the configuration.
171         //
172         return fDetectorMap.GetValue(detector) != NULL;
173 }
174
175 const char* AliShuttleConfig::GetHost(const char* detector) const {
176         //
177         // returns DCS server host used by particular detector
178         //
179         
180         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
181         if (!aHolder) {
182                 AliError(Form("There isn't configuration for detector: %s",
183                         detector));
184                 return NULL;
185         }
186
187         return aHolder->GetHost();
188 }
189
190 Int_t AliShuttleConfig::GetPort(const char* detector) const {
191         //
192         // returns DCS server port used by particular detector
193         //
194
195
196         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
197         if (!aHolder) {
198                 AliError(Form("There isn't configuration for detector: %s",
199                         detector));
200                 return 0;
201         }
202
203         return aHolder->GetPort();
204 }
205
206 const TList* AliShuttleConfig::GetAliases(const char* detector) const {
207         //
208         // returns collection of TObjString which represents the set of aliases
209         // which used for data retrieval for particular detector
210         //
211
212         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
213         if (!aHolder) {
214                 AliError(Form("There isn't configuration for detector: %s",
215                         detector));
216                 return NULL;
217         }
218
219         return aHolder->GetAliases();
220 }
221
222 void AliShuttleConfig::Print(Option_t* /*option*/) const {
223         
224         TString result;
225         result += '\n';
226         
227         TIter iter(fDetectorMap.GetTable());
228         TPair* aPair;
229         while ((aPair = (TPair*) iter.Next())) {
230                 ConfigHolder* aHolder = (ConfigHolder*) aPair->Value();
231                 result += '\n';
232                 result += " Detector: ";
233                 result += aHolder->GetDetector();
234                 result += '\n'; 
235                 result += " Host: ";
236                 result += aHolder->GetHost();
237                 result += '\n';
238                 result += " Port: ";
239                 result += aHolder->GetPort();
240                 result += '\n';
241
242                 result += " Aliases: ";
243                 const TList* aliases = aHolder->GetAliases();   
244                 TIter it(aliases);              
245                 TObjString* anAlias;    
246                 while ((anAlias = (TObjString*) it.Next())) {
247                         result += anAlias->String();
248                         result += ' ';
249                 }       
250                 
251                 result += '\n';
252         }
253
254         AliInfo(result);
255 }