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