]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleConfig.cxx
Additional protection
[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.4  2005/11/19 14:20:31  byordano
19 logbook config added to AliShuttleConfig
20
21 Revision 1.3  2005/11/17 19:24:25  byordano
22 TList changed to TObjArray in AliShuttleConfig
23
24 Revision 1.2  2005/11/17 14:43:23  byordano
25 import to local CVS
26
27 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
28 Initial import as subdirectory in AliRoot
29
30 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
31 SHUTTLE package
32
33 Revision 1.3  2005/08/30 09:13:02  byordano
34 some docs added
35
36 */
37
38
39 //
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).
46 //
47
48
49 #include "AliShuttleConfig.h"
50
51 #include "AliLog.h"
52
53 #include <TObjString.h>
54 #include <TLDAPResult.h>
55 #include <TLDAPEntry.h>
56 #include <TLDAPAttribute.h>
57
58 AliShuttleConfig::ConfigHolder::ConfigHolder(const TLDAPEntry* entry):
59         fIsValid(kFALSE)
60 {
61         TLDAPAttribute* anAttribute;
62         
63         anAttribute = entry->GetAttribute("dt");
64         if (!anAttribute) {
65                 AliError("Invalid configuration! Can't get detector name.");
66                 return;
67         }
68         fDetector = anAttribute->GetValue();
69         if (!fDetector.Length()) {
70                 AliError("Detector name can't be an empty string!")
71                 return;
72         }
73
74         anAttribute = entry->GetAttribute("ipHost");
75         if (!anAttribute) {
76                 AliError("Invalid configuration! Can't get ipHost.");
77                 return;
78         }
79         fHost = anAttribute->GetValue();
80         if (!fHost.Length()) {
81                 AliError("Host can't be an empty string!")
82                 return;
83         }
84
85         anAttribute = entry->GetAttribute("ipServicePort");
86         if (!anAttribute) {
87                 AliError("Invalid configuration! Can't get ipServicePort.");
88                 return;
89         }
90         TString portStr = anAttribute->GetValue();
91         if (!portStr.Length()) {
92                 AliError("ipServicePort can't be an empty string!")
93                 return;
94         }
95         fPort = portStr.Atoi();
96
97         anAttribute = entry->GetAttribute("alias");
98         if (!anAttribute) {
99                 AliError("Invalid configuration! Can't get alias attribute.");
100                 return;
101         }
102         const char* anAlias;
103         while ((anAlias = anAttribute->GetValue())) {
104                 fAliases.AddLast(new TObjString(anAlias));
105         }
106                 
107         fIsValid = kTRUE;
108 }
109
110 AliShuttleConfig::ConfigHolder::~ConfigHolder() {
111         fAliases.Delete();
112 }
113
114 ClassImp(AliShuttleConfig)
115
116 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port, 
117         const char* binddn, const char* password, const char* basedn):
118         fIsValid(kFALSE)
119 {
120         //
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.
127         //
128
129         TLDAPServer aServer(host, port, binddn, password);
130         
131         if (!aServer.IsConnected()) {
132                 AliError(Form("Can't connect to ldap server %s:%d", 
133                                 host, port));
134                 return;
135         }
136
137         TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
138                         "(objectClass=shuttleConfig)");
139         if (!aResult) {
140                 AliError(Form("Can't find configuration with base DN: %s",
141                                 basedn));
142                 return;
143         }
144         
145         TLDAPEntry* anEntry;
146         while ((anEntry = aResult->GetNext())) {
147                 ConfigHolder* aHolder = new ConfigHolder(anEntry);
148                 delete anEntry;
149
150                 if (!aHolder->IsValid()) {
151                         AliError("This entry is going to be skipped!");
152                         delete aHolder;
153
154                         continue;
155                 }
156
157                 TObjString* detStr = new TObjString(aHolder->GetDetector());
158                 fDetectorMap.Add(detStr, aHolder);
159                 fDetectorList.AddLast(detStr);
160         }       
161         
162         delete aResult;
163
164
165         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
166                         "(objectClass=logbookConfig)");
167         if (!aResult) {
168                 AliError(Form("Can't find configuration with base DN: %s",
169                                 basedn));
170                 return;
171         }
172
173         if (aResult->GetCount() == 0) {
174                 AliError("Can't find DAQ log book configuration!");
175                 return;
176         }
177
178         if (aResult->GetCount() > 1) {
179                 AliError("More than one DAQ log book configuration found!");
180                 return;
181         }
182
183         anEntry = aResult->GetNext();
184         
185         TLDAPAttribute* anAttribute;
186         anAttribute = anEntry->GetAttribute("lbURI");
187         if (!anAttribute) {
188                 AliError("Can't find lbURI attribute!");
189                 return;
190         }
191         fLogBookURI = anAttribute->GetValue();
192
193         anAttribute = anEntry->GetAttribute("lbUser");
194         if (!anAttribute) {
195                 AliError("Can't find lbUser attribute!");
196                 return;
197         }
198         fLogBookUser = anAttribute->GetValue();
199         
200         anAttribute = anEntry->GetAttribute("lbPassword");
201         if (!anAttribute) {
202                 AliError("Can't find lbPassword attribute!");
203                 return;
204         }
205         fLogBookPassword = anAttribute->GetValue();
206
207         delete anEntry;
208         delete aResult;
209         
210         fIsValid = kTRUE;
211 }
212
213 AliShuttleConfig::~AliShuttleConfig() {
214         fDetectorMap.DeleteAll();
215 }
216
217 const TObjArray* AliShuttleConfig::GetDetectors() const {
218         //
219         // returns collection of TObjString which contains the name
220         // of every detector which is in the configuration.
221         //
222
223         return &fDetectorList;
224 }
225
226 Bool_t AliShuttleConfig::HasDetector(const char* detector) const {
227         //
228         // checks for paricular detector in the configuration.
229         //
230         return fDetectorMap.GetValue(detector) != NULL;
231 }
232
233 const char* AliShuttleConfig::GetHost(const char* detector) const {
234         //
235         // returns DCS server host used by particular detector
236         //
237         
238         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
239         if (!aHolder) {
240                 AliError(Form("There isn't configuration for detector: %s",
241                         detector));
242                 return NULL;
243         }
244
245         return aHolder->GetHost();
246 }
247
248 Int_t AliShuttleConfig::GetPort(const char* detector) const {
249         //
250         // returns DCS server port used by particular detector
251         //
252
253
254         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
255         if (!aHolder) {
256                 AliError(Form("There isn't configuration for detector: %s",
257                         detector));
258                 return 0;
259         }
260
261         return aHolder->GetPort();
262 }
263
264 const TObjArray* AliShuttleConfig::GetAliases(const char* detector) const {
265         //
266         // returns collection of TObjString which represents the set of aliases
267         // which used for data retrieval for particular detector
268         //
269
270         ConfigHolder* aHolder = (ConfigHolder*) fDetectorMap.GetValue(detector);
271         if (!aHolder) {
272                 AliError(Form("There isn't configuration for detector: %s",
273                         detector));
274                 return NULL;
275         }
276
277         return aHolder->GetAliases();
278 }
279
280 void AliShuttleConfig::Print(Option_t* /*option*/) const {
281         
282         TString result;
283         result += '\n';
284
285         result += "LogBook URI: ";
286         result += fLogBookURI;
287         result += '\n';
288         result += "LogBook User: ";
289         result += fLogBookUser;
290         result += '\n';
291         result += "LogBook Password: ";
292         result.Append('*', fLogBookPassword.Length());
293         result += '\n';
294         
295         TIter iter(fDetectorMap.GetTable());
296         TPair* aPair;
297         while ((aPair = (TPair*) iter.Next())) {
298                 ConfigHolder* aHolder = (ConfigHolder*) aPair->Value();
299                 result += '\n';
300                 result += " Detector: ";
301                 result += aHolder->GetDetector();
302                 result += '\n'; 
303                 result += " Host: ";
304                 result += aHolder->GetHost();
305                 result += '\n';
306                 result += " Port: ";
307                 result += aHolder->GetPort();
308                 result += '\n';
309
310                 result += " Aliases: ";
311                 const TObjArray* aliases = aHolder->GetAliases();       
312                 TIter it(aliases);              
313                 TObjString* anAlias;    
314                 while ((anAlias = (TObjString*) it.Next())) {
315                         result += anAlias->String();
316                         result += ' ';
317                 }       
318                 
319                 result += '\n';
320         }
321
322         AliInfo(result);
323 }