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