bugfix #29879: multiple subscribers in AliHLTSystem; code cleanup, documentation
[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$
1d172743 18Revision 1.21 2007/04/27 07:06:48 jgrosseo
19GetFileSources returns empty list in case of no files, but successful query
20No mails sent in testmode
21
86aa42c3 22Revision 1.20 2007/04/04 10:33:36 jgrosseo
231) Storing of files to the Grid is now done _after_ your preprocessors succeeded. This is transparent, which means that you can still use the same functions (Store, StoreReferenceData) to store files to the Grid. However, the Shuttle first stores them locally and transfers them after the preprocessor finished. The return code of these two functions has changed from UInt_t to Bool_t which gives you the success of the storing.
24In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
25
262) The meaning of the return code of the preprocessor has changed. 0 is now success and any other value means failure. This value is stored in the log and you can use it to keep details about the error condition.
27
283) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
29
304) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
31
325) New function AliPreprocessor::ProcessDCS(). If you do not need to have DCS data in all cases, you can skip the processing by implemting this function and returning kFALSE under certain conditions. E.g. if there is a certain run type.
33If you always need DCS data (like before), you do not need to implement it.
34
356) The run type has been added to the monitoring page
36
9827400b 37Revision 1.19 2007/02/28 10:41:56 acolla
38Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
39AliPreprocessor::GetRunType() function.
40Added some ldap definition files.
41
441b0e9c 42Revision 1.18 2007/01/23 19:20:03 acolla
43Removed old ldif files, added TOF, MCH ldif files. Added some options in
44AliShuttleConfig::Print. Added in Ali Shuttle: SetShuttleTempDir and
45SetShuttleLogDir
46
36c99a6a 47Revision 1.17 2007/01/18 11:17:47 jgrosseo
48changing spaces to tabs ;-)
49
f59d2f8f 50Revision 1.16 2007/01/18 11:10:35 jgrosseo
51adding the possibility of defining DCS alias and data points with patterns
52first pattern introduced: [N..M] to add all names between the two digits, this works also recursively.
53
40150741 54Revision 1.15 2007/01/15 18:27:11 acolla
55implementation of sending mail to subdetector expert in case the preprocessor fails.
56shuttle.schema updated with expert's email entry
57
fc5a4708 58Revision 1.13 2006/12/07 08:51:26 jgrosseo
59update (alberto):
60table, db names in ldap configuration
61added GRP preprocessor
62DCS data can also be retrieved by data point
63
2c15234c 64Revision 1.12 2006/11/16 16:16:48 jgrosseo
65introducing strict run ordering flag
66removed giving preprocessor name to preprocessor, they have to know their name themselves ;-)
67
be48e3ea 68Revision 1.11 2006/11/06 14:23:04 jgrosseo
69major update (Alberto)
70o) reading of run parameters from the logbook
71o) online offline naming conversion
72o) standalone DCSclient package
73
eba76848 74Revision 1.10 2006/10/20 15:22:59 jgrosseo
75o) Adding time out to the execution of the preprocessors: The Shuttle forks and the parent process monitors the child
76o) Merging Collect, CollectAll, CollectNew function
77o) Removing implementation of empty copy constructors (declaration still there!)
78
cb343cfd 79Revision 1.9 2006/10/02 16:38:39 jgrosseo
80update (alberto):
81fixed memory leaks
82storing of objects that failed to be stored to the grid before
83interfacing of shuttle status table in daq system
84
2bb7b766 85Revision 1.8 2006/08/15 10:50:00 jgrosseo
86effc++ corrections (alberto)
87
4f0ab988 88Revision 1.7 2006/07/20 09:54:40 jgrosseo
89introducing status management: The processing per subdetector is divided into several steps,
90after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
91can keep track of the number of failures and skips further processing after a certain threshold is
92exceeded. These thresholds can be configured in LDAP.
93
5164a766 94Revision 1.6 2006/07/19 10:09:55 jgrosseo
95new configuration, accesst to DAQ FES (Alberto)
96
57f50b3c 97Revision 1.5 2006/07/10 13:01:41 jgrosseo
98enhanced storing of last sucessfully processed run (alberto)
99
a7160fe9 100Revision 1.4 2006/06/12 09:11:16 jgrosseo
101coding conventions (Alberto)
102
58bc3020 103Revision 1.3 2006/06/06 14:26:40 jgrosseo
104o) removed files that were moved to STEER
105o) shuttle updated to follow the new interface (Alberto)
106
b948db8d 107Revision 1.7 2006/05/12 09:07:16 colla
10812/05/06
109New configuration complete
110
111Revision 1.2 2006/03/07 07:52:34 hristov
112New version (B.Yordanov)
113
d477ad88 114Revision 1.4 2005/11/19 14:20:31 byordano
115logbook config added to AliShuttleConfig
116
117Revision 1.3 2005/11/17 19:24:25 byordano
118TList changed to TObjArray in AliShuttleConfig
119
120Revision 1.2 2005/11/17 14:43:23 byordano
121import to local CVS
122
123Revision 1.1.1.1 2005/10/28 07:33:58 hristov
124Initial import as subdirectory in AliRoot
125
73abe331 126Revision 1.1.1.1 2005/09/12 22:11:40 byordano
127SHUTTLE package
128
129Revision 1.3 2005/08/30 09:13:02 byordano
130some docs added
131
132*/
133
134
135//
136// This class keeps the AliShuttle configuration.
137// It reads the configuration for LDAP server.
138// For every child entry in basedn which has schema type 'shuttleConfig'
139// it creates a detector configuration. This configuration includes:
140// DCS server host and port and the set of aliases for which data from
141// will be retrieved (used by AliShuttle).
142//
143
144
145#include "AliShuttleConfig.h"
57f50b3c 146#include "AliShuttleInterface.h"
73abe331 147
148#include "AliLog.h"
149
b948db8d 150#include <TSystem.h>
73abe331 151#include <TObjString.h>
152#include <TLDAPResult.h>
153#include <TLDAPEntry.h>
154#include <TLDAPAttribute.h>
155
57f50b3c 156
1d172743 157AliShuttleConfig::AliShuttleDCSConfigHolder::AliShuttleDCSConfigHolder(const TLDAPEntry* entry):
57f50b3c 158fDCSHost(""),
159fDCSPort(0),
fc5a4708 160fDCSAliases(0),
161fDCSDataPoints(0),
36c99a6a 162fDCSAliasesComp(0),
163fDCSDataPointsComp(0),
1d172743 164fIsValid(kFALSE)
73abe331 165{
1d172743 166// constructor of the shuttle DCS configuration holder
58bc3020 167
73abe331 168 TLDAPAttribute* anAttribute;
2bb7b766 169 fDCSAliases = new TObjArray();
170 fDCSAliases->SetOwner(1);
2c15234c 171 fDCSDataPoints = new TObjArray();
172 fDCSDataPoints->SetOwner(1);
36c99a6a 173 fDCSAliasesComp = new TObjArray();
174 fDCSAliasesComp->SetOwner(1);
175 fDCSDataPointsComp = new TObjArray();
176 fDCSDataPointsComp->SetOwner(1);
57f50b3c 177
86aa42c3 178
1d172743 179 anAttribute = entry->GetAttribute("dcsHost");
2c15234c 180 if (!anAttribute)
181 {
1d172743 182 AliError("Unexpected: no DCS host!");
73abe331 183 return;
184 }
57f50b3c 185
b948db8d 186 fDCSHost = anAttribute->GetValue();
73abe331 187
1d172743 188 anAttribute = entry->GetAttribute("dcsPort");
2c15234c 189 if (!anAttribute)
190 {
1d172743 191 AliError("Unexpected: no DCS port!");
73abe331 192 return;
193 }
194 TString portStr = anAttribute->GetValue();
b948db8d 195 fDCSPort = portStr.Atoi();
73abe331 196
1d172743 197 anAttribute = entry->GetAttribute("dcsAlias"); // MAY
2c15234c 198 if (anAttribute)
199 {
200 const char* anAlias;
201 while ((anAlias = anAttribute->GetValue()))
202 {
36c99a6a 203 fDCSAliasesComp->AddLast(new TObjString(anAlias));
40150741 204 ExpandAndAdd(fDCSAliases, anAlias);
2c15234c 205 }
73abe331 206 }
57f50b3c 207
1d172743 208 anAttribute = entry->GetAttribute("dcsDP"); // MAY
2c15234c 209 if (anAttribute)
210 {
211 const char* aDataPoint;
212 while ((aDataPoint = anAttribute->GetValue()))
213 {
36c99a6a 214 fDCSDataPointsComp->AddLast(new TObjString(aDataPoint));
215 ExpandAndAdd(fDCSDataPoints, aDataPoint);
2c15234c 216 }
b948db8d 217 }
218
73abe331 219 fIsValid = kTRUE;
220}
221
a7160fe9 222//______________________________________________________________________________________________
1d172743 223void AliShuttleConfig::AliShuttleDCSConfigHolder::ExpandAndAdd(TObjArray* target, const char* entry)
40150741 224{
f59d2f8f 225 //
226 // adds <entry> to <target> applying expanding of the name
227 // [N..M] creates M-N+1 names with the corresponding digits
228 //
40150741 229
f59d2f8f 230 TString entryStr(entry);
40150741 231
f59d2f8f 232 Int_t begin = entryStr.Index("[");
233 Int_t end = entryStr.Index("]");
234 if (begin != -1 && end != -1 && end > begin)
235 {
236 TString before(entryStr(0, begin));
237 TString after(entryStr(end+1, entryStr.Length()));
40150741 238
f59d2f8f 239 AliDebug(2, Form("Found [] pattern. Splitted input string %s %s", before.Data(), after.Data()));
40150741 240
f59d2f8f 241 Int_t dotdot = entryStr.Index("..");
40150741 242
f59d2f8f 243 TString nStr(entryStr(begin+1, dotdot-begin-1));
244 TString mStr(entryStr(dotdot+2, end-dotdot-2));
40150741 245
f59d2f8f 246 AliDebug(2, Form("Found [N..M] pattern. %s %s", nStr.Data(), mStr.Data()));
40150741 247
f59d2f8f 248 if (nStr.IsDigit() && mStr.IsDigit())
249 {
250 Int_t n = nStr.Atoi();
251 Int_t m = mStr.Atoi();
40150741 252
f59d2f8f 253 Int_t nDigits = nStr.Length();
254 TString formatStr;
255 formatStr.Form("%%s%%0%dd%%s", nDigits);
40150741 256
f59d2f8f 257 AliDebug(2, Form("Format string is %s", formatStr.Data()));
40150741 258
f59d2f8f 259 for (Int_t current = n; current<=m; ++current)
260 {
261 TString newEntry;
262 newEntry.Form(formatStr.Data(), before.Data(), current, after.Data());
40150741 263
f59d2f8f 264 AliDebug(2, Form("Calling recursive with %s", newEntry.Data()));
40150741 265
f59d2f8f 266 // and go recursive
267 ExpandAndAdd(target, newEntry);
268 }
40150741 269
f59d2f8f 270 // return here because we processed the entries already recursively.
271 return;
272 }
273 }
40150741 274
f59d2f8f 275 AliDebug(2, Form("Adding name %s", entry));
276 target->AddLast(new TObjString(entry));
40150741 277}
278
279//______________________________________________________________________________________________
1d172743 280AliShuttleConfig::AliShuttleDCSConfigHolder::~AliShuttleDCSConfigHolder()
58bc3020 281{
282// destructor of the shuttle configuration holder
283
2bb7b766 284 delete fDCSAliases;
2c15234c 285 delete fDCSDataPoints;
1d172743 286 delete fDCSAliasesComp;
287 delete fDCSDataPointsComp;
73abe331 288}
289
a7160fe9 290//______________________________________________________________________________________________
1d172743 291AliShuttleConfig::AliShuttleDetConfigHolder::AliShuttleDetConfigHolder(const TLDAPEntry* entry):
292fDetector(""),
293fDCSConfig(),
294fResponsibles(0),
295fIsValid(kFALSE),
296fSkipDCSQuery(kFALSE),
297fStrictRunOrder(kFALSE)
73abe331 298{
1d172743 299// constructor of the shuttle configuration holder
2bb7b766 300
1d172743 301 TLDAPAttribute* anAttribute;
302
303 fResponsibles = new TObjArray();
304 fResponsibles->SetOwner(1);
305 fDCSConfig = new TObjArray();
306 fDCSConfig->SetOwner(1);
b948db8d 307
1d172743 308 anAttribute = entry->GetAttribute("det"); // MUST
309 if (!anAttribute)
310 {
311 AliError(Form("No \"det\" attribute!"));
73abe331 312 return;
1d172743 313 }
314 fDetector = anAttribute->GetValue();
b948db8d 315
1d172743 316 anAttribute = entry->GetAttribute("strictRunOrder"); // MAY
317 if (!anAttribute)
318 {
319 AliWarning(Form("%s did not set strictRunOrder flag - the default is FALSE",
320 fDetector.Data()));
321 } else {
322 TString strictRunStr = anAttribute->GetValue();
323 if (!(strictRunStr == "0" || strictRunStr == "1"))
324 {
325 AliError("strictRunOrder flag must be 0 or 1!");
326 return;
327 }
328 fStrictRunOrder = (Bool_t) strictRunStr.Atoi();
b948db8d 329 }
57f50b3c 330
1d172743 331 anAttribute = entry->GetAttribute("responsible"); // MAY
332 if (!anAttribute)
333 {
334 AliDebug(2, "Warning! No \"responsible\" attribute!");
335 }
336 else
337 {
338 const char* aResponsible;
339 while ((aResponsible = anAttribute->GetValue()))
340 {
341 fResponsibles->AddLast(new TObjString(aResponsible));
b948db8d 342 }
343 }
344
1d172743 345 fIsValid = kTRUE;
346}
b948db8d 347
1d172743 348//______________________________________________________________________________________________
349AliShuttleConfig::AliShuttleDetConfigHolder::~AliShuttleDetConfigHolder()
350{
351// destructor of the shuttle configuration holder
57f50b3c 352
1d172743 353 delete fResponsibles;
354 delete fDCSConfig;
355}
73abe331 356
1d172743 357//______________________________________________________________________________________________
358const char* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSHost(Int_t iServ) const
359{
360 //
361 // returns DCS server host
362 //
363
364 if (iServ < 0 || iServ >= GetNServers()) return 0;
365
366 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
367 (fDCSConfig->At(iServ));
368
369 return aHolder->GetDCSHost();
370}
73abe331 371
1d172743 372//______________________________________________________________________________________________
373Int_t AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSPort(Int_t iServ) const
374{
375 //
376 // returns DCS server port
377 //
378
379 if (iServ < 0 || iServ >= GetNServers()) return 0;
380
381 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
382 (fDCSConfig->At(iServ));
383
384 return aHolder->GetDCSPort();
385}
57f50b3c 386
1d172743 387//______________________________________________________________________________________________
388const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSAliases(Int_t iServ) const
389{
390 //
391 // returns collection of TObjString which represents the set of aliases
392 // which used for data retrieval for particular detector
393 //
394
395 if (iServ < 0 || iServ >= GetNServers()) return 0;
396
397 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
398 (fDCSConfig->At(iServ));
399
400 return aHolder->GetDCSAliases();
401}
73abe331 402
1d172743 403//______________________________________________________________________________________________
404const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSDataPoints(Int_t iServ) const
405{
406 //
407 // returns collection of TObjString which represents the set of aliases
408 // which used for data retrieval for particular detector
409 //
d477ad88 410
1d172743 411 if (iServ < 0 || iServ >= GetNServers()) return 0;
d477ad88 412
1d172743 413 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
414 (fDCSConfig->At(iServ));
415
416 return aHolder->GetDCSDataPoints();
417}
d477ad88 418
1d172743 419//______________________________________________________________________________________________
420const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetCompactDCSAliases(Int_t iServ) const
421{
422 //
423 // returns collection of TObjString which represents the set of aliases
424 // which used for data retrieval for particular detector (Compact style)
425 //
d477ad88 426
1d172743 427 if (iServ < 0 || iServ >= GetNServers()) return 0;
57f50b3c 428
1d172743 429 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
430 (fDCSConfig->At(iServ));
431
432 return aHolder->GetCompactDCSAliases();
433}
d477ad88 434
1d172743 435//______________________________________________________________________________________________
436const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetCompactDCSDataPoints(Int_t iServ) const
437{
438 //
439 // returns collection of TObjString which represents the set of aliases
440 // which used for data retrieval for particular detector (Compact style)
441 //
fc5a4708 442
1d172743 443 if (iServ < 0 || iServ >= GetNServers()) return 0;
57f50b3c 444
1d172743 445 AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *>
446 (fDCSConfig->At(iServ));
447
448 return aHolder->GetCompactDCSDataPoints();
449}
d477ad88 450
1d172743 451//______________________________________________________________________________________________
452void AliShuttleConfig::AliShuttleDetConfigHolder::AddDCSConfig(AliShuttleDCSConfigHolder* holder)
453{
454 //
455 // adds a DCS configuration set in the array of DCS configurations
456 //
457
458 if(!holder) return;
459 fDCSConfig->AddLast(holder);
460}
2c15234c 461
1d172743 462ClassImp(AliShuttleConfig)
2c15234c 463
1d172743 464//______________________________________________________________________________________________
465AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
466 const char* binddn, const char* password, const char* basedn):
467 fConfigHost(host),
468 fDAQlbHost(""),
469 fDAQlbPort(),
470 fDAQlbUser(""),
471 fDAQlbPass(""),
472 fDAQlbDB(""),
473 fDAQlbTable(""),
474 fShuttlelbTable(""),
475 fRunTypelbTable(""),
476 fMaxRetries(0),
477 fPPTimeOut(0),
478 fPPMaxMem(0),
479 fDetectorMap(),
480 fDetectorList(),
481 fShuttleInstanceHost(""),
482 fProcessedDetectors(),
483 fProcessAll(kFALSE),
484 fIsValid(kFALSE)
485{
486 //
487 // host: ldap server host
488 // port: ldap server port
489 // binddn: binddn used for ldap binding (simple bind is used!).
490 // password: password for binddn
491 // basedn: this is basedn whose childeren entries which have
492 //
441b0e9c 493
1d172743 494 fDetectorMap.SetOwner(1);
495 fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
496 fProcessedDetectors.SetOwner();
2c15234c 497
1d172743 498 TLDAPServer aServer(host, port, binddn, password, 3);
5164a766 499
1d172743 500 if (!aServer.IsConnected()) {
501 AliError(Form("Can't connect to ldap server %s:%d",
502 host, port));
5164a766 503 return;
504 }
5164a766 505
1d172743 506 // reads configuration for the shuttle running on this machine
507
508 TLDAPResult* aResult = 0;
509 TLDAPEntry* anEntry = 0;
510
511 TList dcsList;
512 dcsList.SetOwner(1);
513 TList detList;
514 detList.SetOwner(1);
515 TList globalList;
516 globalList.SetOwner(1);
517 TList sysList;
518 sysList.SetOwner(1);
519 TList hostList;
520 hostList.SetOwner(1);
521
522 aResult = aServer.Search(basedn, LDAP_SCOPE_SUBTREE, 0, 0);
523
524 if (!aResult)
525 {
526 AliError(Form("Can't find configuration with base DN: %s !", basedn));
9827400b 527 return;
528 }
9827400b 529
1d172743 530 while ((anEntry = aResult->GetNext()))
531 {
532 TString dn = anEntry->GetDn();
533
534 if (dn.BeginsWith("dcsHost="))
fc5a4708 535 {
1d172743 536 dcsList.Add(anEntry);
537 }
538 else if (dn.BeginsWith("det="))
539 {
540 detList.Add(anEntry);
2c15234c 541 }
1d172743 542 else if (dn.BeginsWith("name=globalConfig"))
543 {
544 globalList.Add(anEntry);
2c15234c 545 }
1d172743 546 else if (dn.BeginsWith("system="))
547 {
548 sysList.Add(anEntry);
57f50b3c 549 }
1d172743 550 else if (dn.BeginsWith("shuttleHost="))
fc5a4708 551 {
1d172743 552 hostList.Add(anEntry);
fc5a4708 553 }
1d172743 554 else
555 {
556 delete anEntry;
57f50b3c 557 }
1d172743 558
559 }
560 delete aResult;
561
562 Int_t result=0;
563
564 result += SetGlobalConfig(&globalList);
565 result += SetSysConfig(&sysList);
566 result += SetDetConfig(&detList,&dcsList);
567 result += SetHostConfig(&hostList);
568
569 if(result)
570 {
571 AliError("Configuration is INVALID!");
572 }
573 else
574 {
575 fIsValid = kTRUE;
57f50b3c 576 }
73abe331 577}
578
a7160fe9 579//______________________________________________________________________________________________
580AliShuttleConfig::~AliShuttleConfig()
58bc3020 581{
582// destructor
583
73abe331 584 fDetectorMap.DeleteAll();
2bb7b766 585 fDetectorList.Clear();
586 fProcessedDetectors.Delete();
73abe331 587}
588
a7160fe9 589//______________________________________________________________________________________________
590const TObjArray* AliShuttleConfig::GetDetectors() const
58bc3020 591{
73abe331 592 //
593 // returns collection of TObjString which contains the name
594 // of every detector which is in the configuration.
595 //
596
597 return &fDetectorList;
598}
599
a7160fe9 600//______________________________________________________________________________________________
601Bool_t AliShuttleConfig::HasDetector(const char* detector) const
58bc3020 602{
73abe331 603 //
604 // checks for paricular detector in the configuration.
605 //
606 return fDetectorMap.GetValue(detector) != NULL;
607}
608
a7160fe9 609//______________________________________________________________________________________________
1d172743 610Int_t AliShuttleConfig::GetNServers(const char* detector) const
611{
612 //
613 // returns number of DCS servers for detector
614 //
615
616 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
617 if (!aHolder) {
618 AliError(Form("There isn't configuration for detector: %s",
619 detector));
620 return 0;
621 }
622
623 return aHolder->GetNServers();
624}
625
626
627//______________________________________________________________________________________________
628const char* AliShuttleConfig::GetDCSHost(const char* detector, Int_t iServ) const
58bc3020 629{
73abe331 630 //
1d172743 631 // returns i-th DCS server host used by particular detector
73abe331 632 //
633
1d172743 634 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
73abe331 635 if (!aHolder) {
636 AliError(Form("There isn't configuration for detector: %s",
637 detector));
638 return NULL;
639 }
640
1d172743 641 return aHolder->GetDCSHost(iServ);
73abe331 642}
643
a7160fe9 644//______________________________________________________________________________________________
1d172743 645Int_t AliShuttleConfig::GetDCSPort(const char* detector, Int_t iServ) const
58bc3020 646{
73abe331 647 //
1d172743 648 // returns i-th DCS server port used by particular detector
73abe331 649 //
650
651
1d172743 652 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
73abe331 653 if (!aHolder) {
654 AliError(Form("There isn't configuration for detector: %s",
655 detector));
656 return 0;
657 }
658
1d172743 659 return aHolder->GetDCSPort(iServ);
73abe331 660}
661
a7160fe9 662//______________________________________________________________________________________________
1d172743 663const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector, Int_t iServ) const
58bc3020 664{
73abe331 665 //
1d172743 666 // returns collection of TObjString which represents the i-th set of aliases
73abe331 667 // which used for data retrieval for particular detector
668 //
669
1d172743 670 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
73abe331 671 if (!aHolder) {
672 AliError(Form("There isn't configuration for detector: %s",
673 detector));
674 return NULL;
675 }
676
1d172743 677 return aHolder->GetDCSAliases(iServ);
b948db8d 678}
679
a7160fe9 680//______________________________________________________________________________________________
1d172743 681const TObjArray* AliShuttleConfig::GetDCSDataPoints(const char* detector, Int_t iServ) const
2c15234c 682{
683 //
684 // returns collection of TObjString which represents the set of aliases
685 // which used for data retrieval for particular detector
686 //
687
1d172743 688 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
2c15234c 689 if (!aHolder) {
690 AliError(Form("There isn't configuration for detector: %s",
691 detector));
692 return NULL;
693 }
694
1d172743 695 return aHolder->GetDCSDataPoints(iServ);
696}
697
698//______________________________________________________________________________________________
699const TObjArray* AliShuttleConfig::GetCompactDCSAliases(const char* detector, Int_t iServ) const
700{
701 //
702 // returns collection of TObjString which represents the i-th set of aliases
703 // which used for data retrieval for particular detector (Compact style)
704 //
705
706 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
707 if (!aHolder) {
708 AliError(Form("There isn't configuration for detector: %s",
709 detector));
710 return NULL;
711 }
712
713 return aHolder->GetCompactDCSAliases(iServ);
714}
715
716//______________________________________________________________________________________________
717const TObjArray* AliShuttleConfig::GetCompactDCSDataPoints(const char* detector, Int_t iServ) const
718{
719 //
720 // returns collection of TObjString which represents the set of aliases
721 // which used for data retrieval for particular detector (Compact style)
722 //
723
724 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
725 if (!aHolder) {
726 AliError(Form("There isn't configuration for detector: %s",
727 detector));
728 return NULL;
729 }
730
731 return aHolder->GetCompactDCSDataPoints(iServ);
2c15234c 732}
733
734//______________________________________________________________________________________________
57c1a579 735const TObjArray* AliShuttleConfig::GetResponsibles(const char* detector) const
736{
737 //
738 // returns collection of TObjString which represents the list of mail addresses
739 // of the detector's responsible(s)
740 //
741
1d172743 742 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
57c1a579 743 if (!aHolder) {
744 AliError(Form("There isn't configuration for detector: %s",
745 detector));
746 return NULL;
747 }
748
749 return aHolder->GetResponsibles();
750}
751
752//______________________________________________________________________________________________
a7160fe9 753Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
58bc3020 754{
b948db8d 755 // return TRUE if detector is handled by host or if fProcessAll is TRUE
756
757 if(fProcessAll) return kTRUE;
758 TIter iter(&fProcessedDetectors);
759 TObjString* detName;
760 while((detName = (TObjString*) iter.Next())){
761 if(detName->String() == detector) return kTRUE;
762 }
763 return kFALSE;
73abe331 764}
765
a7160fe9 766//______________________________________________________________________________________________
be48e3ea 767Bool_t AliShuttleConfig::StrictRunOrder(const char* detector) const
768{
769 // return TRUE if detector wants strict run ordering of stored data
770
1d172743 771 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
be48e3ea 772 if (!aHolder)
773 {
774 AliError(Form("There isn't configuration for detector: %s",
775 detector));
776 return kTRUE;
777 }
778
779 return aHolder->StrictRunOrder();
780}
781
782//______________________________________________________________________________________________
1d172743 783UInt_t AliShuttleConfig::SetGlobalConfig(TList* list)
784{
785 // Set the global configuration (DAQ Logbook + preprocessor monitoring settings)
786
787 TLDAPEntry* anEntry = 0;
788 TLDAPAttribute* anAttribute = 0;
789
790 if (list->GetEntries() == 0)
791 {
792 AliError("Global configuration not found!");
793 return 1;
794 }
795 else if (list->GetEntries() > 1)
796 {
797 AliError("More than one global configuration found!");
798 return 2;
799 }
800
801 anEntry = dynamic_cast<TLDAPEntry*> (list->At(0));
802
803 if (!anEntry)
804 {
805 AliError("Unexpected! Global list does not contain a TLDAPEntry");
806 return 3;
807 }
808
809
810 anAttribute = anEntry->GetAttribute("daqLbHost");
811 if (!anAttribute) {
812 AliError("Can't find daqLbHost attribute!");
813 return 4;
814 }
815 fDAQlbHost = anAttribute->GetValue();
816
817 anAttribute = anEntry->GetAttribute("daqLbPort"); // MAY
818 if (anAttribute)
819 {
820 fDAQlbPort = ((TString) anAttribute->GetValue()).Atoi();
821 } else {
822 fDAQlbPort = 3306; // mysql
823 }
824
825 anAttribute = anEntry->GetAttribute("daqLbUser");
826 if (!anAttribute) {
827 AliError("Can't find daqLbUser attribute!");
828 return 4;
829 }
830 fDAQlbUser = anAttribute->GetValue();
831
832 anAttribute = anEntry->GetAttribute("daqLbPasswd");
833 if (!anAttribute) {
834 AliError("Can't find daqLbPasswd attribute!");
835 return 4;
836 }
837 fDAQlbPass = anAttribute->GetValue();
838
839 anAttribute = anEntry->GetAttribute("daqLbDB");
840 if (!anAttribute) {
841 AliError("Can't find daqLbDB attribute!");
842 return 4;
843 }
844 fDAQlbDB = anAttribute->GetValue();
845
846 anAttribute = anEntry->GetAttribute("daqLbTable");
847 if (!anAttribute) {
848 AliError("Can't find daqLbTable attribute!");
849 return 4;
850 }
851 fDAQlbTable = anAttribute->GetValue();
852
853 anAttribute = anEntry->GetAttribute("shuttleLbTable");
854 if (!anAttribute) {
855 AliError("Can't find shuttleLbTable attribute!");
856 return 4;
857 }
858 fShuttlelbTable = anAttribute->GetValue();
859
860 anAttribute = anEntry->GetAttribute("runTypeLbTable");
861 if (!anAttribute) {
862 AliError("Can't find runTypeLbTable attribute!");
863 return 4;
864 }
865 fRunTypelbTable = anAttribute->GetValue();
866
867 anAttribute = anEntry->GetAttribute("ppmaxRetries");
868 if (!anAttribute) {
869 AliError("Can't find ppmaxRetries attribute!");
870 return 4;
871 }
872 TString tmpStr = anAttribute->GetValue();
873 fMaxRetries = tmpStr.Atoi();
874
875 anAttribute = anEntry->GetAttribute("ppTimeOut");
876 if (!anAttribute) {
877 AliError("Can't find ppTimeOut attribute!");
878 return 4;
879 }
880 tmpStr = anAttribute->GetValue();
881 fPPTimeOut = tmpStr.Atoi();
882
883 anAttribute = anEntry->GetAttribute("ppMaxMem");
884 if (!anAttribute) {
885 AliError("Can't find ppMaxMem attribute!");
886 return 4;
887 }
888 tmpStr = anAttribute->GetValue();
889 fPPMaxMem = tmpStr.Atoi();
890
891 return 0;
892
893
894}
895
896//______________________________________________________________________________________________
897UInt_t AliShuttleConfig::SetSysConfig(TList* list)
898{
899 // Set the online FXS configuration (DAQ + DCS + HLT)
900
901 TLDAPEntry* anEntry = 0;
902 TLDAPAttribute* anAttribute = 0;
903
904 if (list->GetEntries() != 3)
905 {
906 AliError(Form("Wrong number of online systems found: %d !", list->GetEntries()));
907 return 1;
908 }
909
910 TIter iter(list);
911 Int_t iSys=0, count = 0;
912 while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
913 {
914 anAttribute = anEntry->GetAttribute("system");
915 TString sysName = anAttribute->GetValue();
916
917 if (sysName == "DAQ")
918 {
919 iSys = 0;
920 count += 1;
921 }
922 else if (sysName == "DCS")
923 {
924 iSys = 1;
925 count += 10;
926 }
927 else if (sysName == "HLT")
928 {
929 iSys = 2;
930 count += 100;
931 }
932
933 anAttribute = anEntry->GetAttribute("dbHost");
934 if (!anAttribute) {
935 AliError(Form ("Can't find dbHost attribute for %s!!",
936 AliShuttleInterface::GetSystemName(iSys)));
937 return 5;
938 }
939 fFXSdbHost[iSys] = anAttribute->GetValue();
940
941 anAttribute = anEntry->GetAttribute("dbPort"); // MAY
942 if (anAttribute)
943 {
944 fFXSdbPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
945 } else {
946 fFXSdbPort[iSys] = 3306; // mysql
947 }
948
949 anAttribute = anEntry->GetAttribute("dbUser");
950 if (!anAttribute) {
951 AliError(Form ("Can't find dbUser attribute for %s!!",
952 AliShuttleInterface::GetSystemName(iSys)));
953 return 5;
954 }
955 fFXSdbUser[iSys] = anAttribute->GetValue();
956
957 anAttribute = anEntry->GetAttribute("dbPasswd");
958 if (!anAttribute) {
959 AliError(Form ("Can't find dbPasswd attribute for %s!!",
960 AliShuttleInterface::GetSystemName(iSys)));
961 return 5;
962 }
963 fFXSdbPass[iSys] = anAttribute->GetValue();
964
965 anAttribute = anEntry->GetAttribute("dbName");
966 if (!anAttribute) {
967 AliError(Form ("Can't find dbName attribute for %s!!",
968 AliShuttleInterface::GetSystemName(iSys)));
969 return 5;
970 }
971
972 fFXSdbName[iSys] = anAttribute->GetValue();
973 anAttribute = anEntry->GetAttribute("dbTable");
974 if (!anAttribute) {
975 AliError(Form ("Can't find dbTable attribute for %s!!",
976 AliShuttleInterface::GetSystemName(iSys)));
977 return 5;
978 }
979 fFXSdbTable[iSys] = anAttribute->GetValue();
980
981 anAttribute = anEntry->GetAttribute("fxsHost");
982 if (!anAttribute) {
983 AliError(Form ("Can't find fxsHost attribute for %s!!",
984 AliShuttleInterface::GetSystemName(iSys)));
985 return 5;
986 }
987 fFXSHost[iSys] = anAttribute->GetValue();
988
989 anAttribute = anEntry->GetAttribute("fxsPort"); // MAY
990 if (anAttribute)
991 {
992 fFXSPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
993 } else {
994 fFXSPort[iSys] = 22; // scp port number
995 }
996
997 anAttribute = anEntry->GetAttribute("fxsUser");
998 if (!anAttribute) {
999 AliError(Form ("Can't find fxsUser attribute for %s!!",
1000 AliShuttleInterface::GetSystemName(iSys)));
1001 return 5;
1002 }
1003 fFXSUser[iSys] = anAttribute->GetValue();
1004
1005 anAttribute = anEntry->GetAttribute("fxsPasswd");
1006 if (anAttribute) fFXSPass[iSys] = anAttribute->GetValue();
1007 }
1008
1009 if(count != 111) {
1010 AliError(Form("Wrong system configuration! (code = %d)", count));
1011 return 6;
1012 }
1013
1014 return 0;
1015}
1016
1017//______________________________________________________________________________________________
1018UInt_t AliShuttleConfig::SetDetConfig(TList* detList, TList* dcsList)
1019{
1020 // Set the detector configuration (general settings + DCS amanda server and alias/DP lists)
1021
1022 TLDAPEntry* anEntry = 0;
1023
1024 TIter iter(detList);
1025 while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
1026 {
1027
1028 AliShuttleDetConfigHolder* detHolder = new AliShuttleDetConfigHolder(anEntry);
1029
1030 if (!detHolder->IsValid()) {
1031 AliError("Detector configuration error!");
1032 delete detHolder;
1033 return 7;
1034 }
1035
1036 TObjString* detStr = new TObjString(detHolder->GetDetector());
1037
1038 // Look for DCS Configuration
1039 TIter dcsIter(dcsList);
1040 TLDAPEntry *dcsEntry = 0;
1041 while ((dcsEntry = dynamic_cast<TLDAPEntry*> (dcsIter.Next())))
1042 {
1043 TString dn = dcsEntry->GetDn();
1044 if(dn.Contains(detStr->GetName())) {
1045 AliDebug(2, Form("Found DCS configuration: dn = %s",dn.Data()));
1046 AliShuttleDCSConfigHolder* dcsHolder = new AliShuttleDCSConfigHolder(dcsEntry);
1047 if (!dcsHolder->IsValid()) {
1048 AliError("DCS configuration error!");
1049 delete detHolder;
1050 delete dcsHolder;
1051 return 7;
1052 }
1053 detHolder->AddDCSConfig(dcsHolder);
1054 }
1055 }
1056
1057
1058 fDetectorMap.Add(detStr, detHolder);
1059 fDetectorList.AddLast(detStr);
1060 }
1061
1062 return 0;
1063}
1064
1065//______________________________________________________________________________________________
1066UInt_t AliShuttleConfig::SetHostConfig(TList* list)
1067{
1068 // Set the Shuttle machines configuration (which detectors processes each machine)
1069
1070 TLDAPEntry* anEntry = 0;
1071 TLDAPAttribute* anAttribute = 0;
1072
1073 fShuttleInstanceHost = gSystem->HostName();
1074
1075 TIter iter(list);
1076 while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
1077 {
1078
1079 TString dn(anEntry->GetDn());
1080 if (!dn.Contains(Form("shuttleHost=%s", fShuttleInstanceHost.Data()))) continue;
1081
1082 if (!fProcessAll)
1083 {
1084 anAttribute = anEntry->GetAttribute("detectors");
1085 const char *detName;
1086 while((detName = anAttribute->GetValue())){
1087 TObjString *objDet= new TObjString(detName);
1088 fProcessedDetectors.Add(objDet);
1089 }
1090 }
1091 }
1092
1093 return 0;
1094}
1095
1096
1097//______________________________________________________________________________________________
36c99a6a 1098void AliShuttleConfig::Print(Option_t* option) const
58bc3020 1099{
1100// print configuration
36c99a6a 1101// options : "": print configuration for all detectors, aliases and DPs in compacted format
1102// "uncompact": print configuration for all detectors, aliases and DPs in uncompacted format
1103// "DET": print configuration for DET, aliases and DPs in compacted format
1104// "DET, uncompact": print configuration for DET, aliases and DPs in uncompacted format
1105
73abe331 1106 TString result;
1107 result += '\n';
d477ad88 1108
57c1a579 1109 result += "####################################################\n";
1110 result += Form(" Shuttle configuration from %s \n", fConfigHost.Data());
1111 result += "####################################################\n";
1112 result += Form("\nShuttle running on %s \n", fShuttleInstanceHost.Data());
57f50b3c 1113
1114 if(fProcessAll) {
57c1a579 1115 result += Form("All detectors will be processed! \n");
57f50b3c 1116 } else {
1117 result += "Detectors processed by this host: ";
1118 TIter it(&fProcessedDetectors);
1119 TObjString* aDet;
1120 while ((aDet = (TObjString*) it.Next())) {
1121 result += Form("%s ", aDet->String().Data());
1122 }
57c1a579 1123 result += "\n";
b948db8d 1124 }
b948db8d 1125
1d172743 1126 result += Form("PP time out = %d - max PP mem size = %d KB - max retries = %d\n\n",
1127 fPPTimeOut, fPPMaxMem, fMaxRetries);
57c1a579 1128 result += "------------------------------------------------------\n";
2bb7b766 1129
57c1a579 1130 result += Form("Logbook Configuration \n\n \tHost: %s:%d; \tUser: %s; ",
fc5a4708 1131 fDAQlbHost.Data(), fDAQlbPort, fDAQlbUser.Data());
b948db8d 1132
2c15234c 1133// result += "Password: ";
1134// result.Append('*', fDAQlbPass.Length());
441b0e9c 1135 result += Form("\tDB: %s; \tTables: %s, %s, %s",
1136 fDAQlbDB.Data(), fDAQlbTable.Data(), fShuttlelbTable.Data(), fRunTypelbTable.Data());
2c15234c 1137
57f50b3c 1138 result += "\n\n";
1139
57c1a579 1140 result += "------------------------------------------------------\n";
1141 result += "FXS configuration\n\n";
1142
57f50b3c 1143 for(int iSys=0;iSys<3;iSys++){
57c1a579 1144 result += Form("*** %s ***\n", AliShuttleInterface::GetSystemName(iSys));
fc5a4708 1145 result += Form("\tDB host: %s:%d; \tUser: %s; \tName: %s; \tTable: %s\n",
1146 fFXSdbHost[iSys].Data(), fFXSdbPort[iSys], fFXSdbUser[iSys].Data(),
2c15234c 1147 fFXSdbName[iSys].Data(), fFXSdbTable[iSys].Data());
1148 // result += Form("DB Password:",fFXSdbPass[iSys].Data());
fc5a4708 1149 result += Form("\tFXS host: %s:%d; \tUser: %s\n\n", fFXSHost[iSys].Data(), fFXSPort[iSys],
1150 fFXSUser[iSys].Data());
2c15234c 1151 // result += Form("FXS Password:",fFXSPass[iSys].Data());
57f50b3c 1152 }
b948db8d 1153
36c99a6a 1154 TString optStr(option);
1155
57c1a579 1156 result += "------------------------------------------------------\n";
1157 result += "Detector-specific configuration\n\n";
1d172743 1158
73abe331 1159 TIter iter(fDetectorMap.GetTable());
1d172743 1160 TPair* aPair = 0;
1161
1162 AliInfo(Form("Option = %s", option));
1163
73abe331 1164 while ((aPair = (TPair*) iter.Next())) {
1d172743 1165 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) aPair->Value();
1166 if (optStr != "" && !optStr.Contains(aHolder->GetDetector()) &&
1167 optStr.CompareTo("uncompact",TString::kIgnoreCase) != 0 )
36c99a6a 1168 continue;
1d172743 1169
57c1a579 1170 result += Form("*** %s *** \n", aHolder->GetDetector());
1171
1172 const TObjArray* responsibles = aHolder->GetResponsibles();
1173 if (responsibles->GetEntries() != 0)
1174 {
1175 result += "\tDetector responsible(s): ";
1176 TIter it(responsibles);
1177 TObjString* aResponsible;
1178 while ((aResponsible = (TObjString*) it.Next()))
1179 {
1180 result += Form("%s ", aResponsible->String().Data());
1181 }
1182 result += "\n";
1183 }
1184
1d172743 1185 result += Form("\tStrict run ordering: %s \n\n", aHolder->StrictRunOrder() ? "YES" : "NO");
1186
1187 const TObjArray* dcsConfig = aHolder->GetDCSConfig();
1188
1189 AliShuttleDCSConfigHolder* dcsHolder = 0;
1190 TIter dcsIter(dcsConfig);
1191 Int_t count=0;
1192 while ((dcsHolder = dynamic_cast<AliShuttleDCSConfigHolder*> (dcsIter.Next())))
be48e3ea 1193 {
1d172743 1194 result += Form("\tAmanda server [%d]: %s:%d \n", count,
1195 dcsHolder->GetDCSHost(), dcsHolder->GetDCSPort());
57f50b3c 1196
1d172743 1197 const TObjArray* aliases = 0;
1198 if (optStr.Contains("uncompact",TString::kIgnoreCase))
1199 {
1200 aliases = dcsHolder->GetDCSAliases();
1201 } else {
1202 aliases = dcsHolder->GetCompactDCSAliases();
1203 }
36c99a6a 1204
1d172743 1205 if (aliases->GetEntries() != 0)
2c15234c 1206 {
1d172743 1207 result += Form("\tDCS Aliases [%d]: ", count);
1208 TIter it(aliases);
1209 TObjString* anAlias;
1210 while ((anAlias = (TObjString*) it.Next()))
1211 {
1212 result += Form("%s ", anAlias->String().Data());
1213 }
1214 result += "\n";
2c15234c 1215 }
57f50b3c 1216
1d172743 1217 const TObjArray* dataPoints = 0;
1218 if (optStr.Contains("uncompact",TString::kIgnoreCase))
1219 {
1220 dataPoints = dcsHolder->GetDCSDataPoints();
1221 } else {
1222 dataPoints = dcsHolder->GetCompactDCSDataPoints();
2c15234c 1223 }
1d172743 1224 if (dataPoints->GetEntries() != 0)
1225 {
1226 result += Form("\tDCS Data Points [%d]: ", count);
1227 TIter it(dataPoints);
1228 TObjString* aDataPoint;
1229 while ((aDataPoint = (TObjString*) it.Next())) {
1230 result += Form("%s ", aDataPoint->String().Data());
1231 }
2c15234c 1232 result += "\n";
1d172743 1233 }
1234 count++;
1235 result += "\n";
2c15234c 1236 }
73abe331 1237 }
57f50b3c 1238 if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
1239
73abe331 1240 AliInfo(result);
1241}