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