Run type field added in SHUTTLE framework. Run type is read from "run type" logbook...
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleConfig.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.18  2007/01/23 19:20:03  acolla
19 Removed old ldif files, added TOF, MCH ldif files. Added some options in
20 AliShuttleConfig::Print. Added in Ali Shuttle: SetShuttleTempDir and
21 SetShuttleLogDir
22
23 Revision 1.17  2007/01/18 11:17:47  jgrosseo
24 changing spaces to tabs ;-)
25
26 Revision 1.16  2007/01/18 11:10:35  jgrosseo
27 adding the possibility of defining DCS alias and data points with patterns
28 first pattern introduced: [N..M] to add all names between the two digits, this works also recursively.
29
30 Revision 1.15  2007/01/15 18:27:11  acolla
31 implementation of sending mail to subdetector expert in case the preprocessor fails.
32 shuttle.schema updated with expert's email entry
33
34 Revision 1.13  2006/12/07 08:51:26  jgrosseo
35 update (alberto):
36 table, db names in ldap configuration
37 added GRP preprocessor
38 DCS data can also be retrieved by data point
39
40 Revision 1.12  2006/11/16 16:16:48  jgrosseo
41 introducing strict run ordering flag
42 removed giving preprocessor name to preprocessor, they have to know their name themselves ;-)
43
44 Revision 1.11  2006/11/06 14:23:04  jgrosseo
45 major update (Alberto)
46 o) reading of run parameters from the logbook
47 o) online offline naming conversion
48 o) standalone DCSclient package
49
50 Revision 1.10  2006/10/20 15:22:59  jgrosseo
51 o) Adding time out to the execution of the preprocessors: The Shuttle forks and the parent process monitors the child
52 o) Merging Collect, CollectAll, CollectNew function
53 o) Removing implementation of empty copy constructors (declaration still there!)
54
55 Revision 1.9  2006/10/02 16:38:39  jgrosseo
56 update (alberto):
57 fixed memory leaks
58 storing of objects that failed to be stored to the grid before
59 interfacing of shuttle status table in daq system
60
61 Revision 1.8  2006/08/15 10:50:00  jgrosseo
62 effc++ corrections (alberto)
63
64 Revision 1.7  2006/07/20 09:54:40  jgrosseo
65 introducing status management: The processing per subdetector is divided into several steps,
66 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
67 can keep track of the number of failures and skips further processing after a certain threshold is
68 exceeded. These thresholds can be configured in LDAP.
69
70 Revision 1.6  2006/07/19 10:09:55  jgrosseo
71 new configuration, accesst to DAQ FES (Alberto)
72
73 Revision 1.5  2006/07/10 13:01:41  jgrosseo
74 enhanced storing of last sucessfully processed run (alberto)
75
76 Revision 1.4  2006/06/12 09:11:16  jgrosseo
77 coding conventions (Alberto)
78
79 Revision 1.3  2006/06/06 14:26:40  jgrosseo
80 o) removed files that were moved to STEER
81 o) shuttle updated to follow the new interface (Alberto)
82
83 Revision 1.7  2006/05/12 09:07:16  colla
84 12/05/06
85 New configuration complete
86
87 Revision 1.2  2006/03/07 07:52:34  hristov
88 New version (B.Yordanov)
89
90 Revision 1.4  2005/11/19 14:20:31  byordano
91 logbook config added to AliShuttleConfig
92
93 Revision 1.3  2005/11/17 19:24:25  byordano
94 TList changed to TObjArray in AliShuttleConfig
95
96 Revision 1.2  2005/11/17 14:43:23  byordano
97 import to local CVS
98
99 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
100 Initial import as subdirectory in AliRoot
101
102 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
103 SHUTTLE package
104
105 Revision 1.3  2005/08/30 09:13:02  byordano
106 some docs added
107
108 */
109
110
111 //
112 // This class keeps the AliShuttle configuration.
113 // It reads the configuration for LDAP server.
114 // For every child entry in basedn which has schema type 'shuttleConfig'
115 // it creates a detector configuration. This configuration includes:
116 // DCS server host and port and the set of aliases for which data from
117 // will be retrieved (used by AliShuttle).
118 //
119
120
121 #include "AliShuttleConfig.h"
122 #include "AliShuttleInterface.h"
123
124 #include "AliLog.h"
125
126 #include <TSystem.h>
127 #include <TObjString.h>
128 #include <TLDAPResult.h>
129 #include <TLDAPEntry.h>
130 #include <TLDAPAttribute.h>
131
132
133 AliShuttleConfig::AliShuttleConfigHolder::AliShuttleConfigHolder(const TLDAPEntry* entry):
134 fDetector(""),
135 fDCSHost(""),
136 fDCSPort(0),
137 fDCSAliases(0),
138 fDCSDataPoints(0),
139 fDCSAliasesComp(0),
140 fDCSDataPointsComp(0),
141 fResponsibles(0),
142 fIsValid(kFALSE),
143 fSkipDCSQuery(kFALSE),
144 fStrictRunOrder(kFALSE)
145 {
146 // constructor of the shuttle configuration holder
147
148         TLDAPAttribute* anAttribute;
149         fDCSAliases = new TObjArray();
150         fDCSAliases->SetOwner(1);
151         fDCSDataPoints = new TObjArray();
152         fDCSDataPoints->SetOwner(1);
153         fDCSAliasesComp = new TObjArray();
154         fDCSAliasesComp->SetOwner(1);
155         fDCSDataPointsComp = new TObjArray();
156         fDCSDataPointsComp->SetOwner(1);
157         fResponsibles = new TObjArray();
158         fResponsibles->SetOwner(1);
159
160         anAttribute = entry->GetAttribute("det"); // MUST
161         if (!anAttribute)
162         {
163                 AliError(Form("Invalid configuration! No \"det\" attribute!"));
164                 return;
165         }
166         fDetector = anAttribute->GetValue();
167
168         anAttribute = entry->GetAttribute("StrictRunOrder"); // MAY
169         if (!anAttribute)
170         {
171                 AliWarning(Form("%s did not set StrictRunOrder flag - the default is FALSE",
172                                 fDetector.Data()));
173         } else {
174                 TString strictRunStr = anAttribute->GetValue();
175                 if (!(strictRunStr == "0" || strictRunStr == "1"))
176                 {
177                         AliError("Invalid configuration! StrictRunOrder flag must be 0 or 1!");
178                         return;
179                 }
180                 fStrictRunOrder = (Bool_t) strictRunStr.Atoi();
181         }
182
183         anAttribute = entry->GetAttribute("responsible"); // MUST
184         if (!anAttribute)
185         {
186                 AliError(Form("Invalid configuration! No \"responsible\" attribute!"));
187                 return;
188         }
189         const char* aResponsible;
190         while ((aResponsible = anAttribute->GetValue()))
191         {
192                 fResponsibles->AddLast(new TObjString(aResponsible));
193         }
194
195         anAttribute = entry->GetAttribute("DCSHost"); // MAY
196         if (!anAttribute)
197         {
198                 AliDebug(2,
199                         Form("%s has not DCS host entry - Shuttle will skip DCS data query!",
200                                 fDetector.Data()));
201                 fIsValid = kTRUE;
202                 fSkipDCSQuery = kTRUE;
203                 return;
204         }
205
206         fDCSHost = anAttribute->GetValue();
207
208         anAttribute = entry->GetAttribute("DCSPort"); // MAY
209         if (!anAttribute)
210         {
211                 AliError(Form("Invalid configuration! %s has DCS Host but no port number!",
212                                 fDetector.Data()));
213                 return;
214         }
215         TString portStr = anAttribute->GetValue();
216         fDCSPort = portStr.Atoi();
217
218         anAttribute = entry->GetAttribute("DCSalias"); // MAY
219         if (anAttribute)
220         {
221                 const char* anAlias;
222                 while ((anAlias = anAttribute->GetValue()))
223                 {
224                         fDCSAliasesComp->AddLast(new TObjString(anAlias));
225                         ExpandAndAdd(fDCSAliases, anAlias);
226                 }
227         }
228
229         anAttribute = entry->GetAttribute("DCSdatapoint"); // MAY
230         if (anAttribute)
231         {
232                 const char* aDataPoint;
233                 while ((aDataPoint = anAttribute->GetValue()))
234                 {
235                 fDCSDataPointsComp->AddLast(new TObjString(aDataPoint));
236                 ExpandAndAdd(fDCSDataPoints, aDataPoint);
237                 }
238         }
239
240         fIsValid = kTRUE;
241 }
242
243 //______________________________________________________________________________________________
244 void AliShuttleConfig::AliShuttleConfigHolder::ExpandAndAdd(TObjArray* target, const char* entry)
245 {
246         //
247         // adds <entry> to <target> applying expanding of the name
248         // [N..M] creates M-N+1 names with the corresponding digits
249         //
250
251         TString entryStr(entry);
252
253         Int_t begin = entryStr.Index("[");
254         Int_t end = entryStr.Index("]");
255         if (begin != -1 && end != -1 && end > begin)
256         {
257                 TString before(entryStr(0, begin));
258                 TString after(entryStr(end+1, entryStr.Length()));
259
260                 AliDebug(2, Form("Found [] pattern. Splitted input string %s %s", before.Data(), after.Data()));
261
262                 Int_t dotdot = entryStr.Index("..");
263
264                 TString nStr(entryStr(begin+1, dotdot-begin-1));
265                 TString mStr(entryStr(dotdot+2, end-dotdot-2));
266
267                 AliDebug(2, Form("Found [N..M] pattern. %s %s", nStr.Data(), mStr.Data()));
268
269                 if (nStr.IsDigit() && mStr.IsDigit())
270                 {
271                         Int_t n = nStr.Atoi();
272                         Int_t m = mStr.Atoi();
273
274                         Int_t nDigits = nStr.Length();
275                         TString formatStr;
276                         formatStr.Form("%%s%%0%dd%%s", nDigits);
277
278                         AliDebug(2, Form("Format string is %s", formatStr.Data()));
279
280                         for (Int_t current = n; current<=m; ++current)
281                         {
282                                 TString newEntry;
283                                 newEntry.Form(formatStr.Data(), before.Data(), current, after.Data());
284
285                                 AliDebug(2, Form("Calling recursive with %s", newEntry.Data()));
286
287                                 // and go recursive
288                                 ExpandAndAdd(target, newEntry);
289                         }
290
291                         // return here because we processed the entries already recursively.
292                         return;
293                 }
294         }
295
296         AliDebug(2, Form("Adding name %s", entry));
297         target->AddLast(new TObjString(entry));
298 }
299
300 //______________________________________________________________________________________________
301 AliShuttleConfig::AliShuttleConfigHolder::~AliShuttleConfigHolder()
302 {
303 // destructor of the shuttle configuration holder
304
305         delete fDCSAliases;
306         delete fDCSDataPoints;
307         delete fResponsibles;
308 }
309
310 ClassImp(AliShuttleConfig)
311
312 //______________________________________________________________________________________________
313 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
314         const char* binddn, const char* password, const char* basedn):
315         fIsValid(kFALSE), fConfigHost(host),
316         fDAQlbHost(""), fDAQlbPort(), fDAQlbUser(""), fDAQlbPass(""),
317         fDAQlbDB(""), fDAQlbTable(""), fShuttlelbTable(""), fRunTypelbTable(""),
318         fMaxRetries(0), fPPTimeOut(0), fDetectorMap(), fDetectorList(),
319         fShuttleInstanceHost(""), fProcessedDetectors(), fProcessAll(kFALSE)
320 {
321         //
322         // host: ldap server host
323         // port: ldap server port
324         // binddn: binddn used for ldap binding (simple bind is used!).
325         // password: password for binddn
326         // basedn: this is basedn whose childeren entries which have
327         // (objectClass=shuttleConfig) will be used as detector configurations.
328         //
329
330         fDetectorMap.SetOwner();
331         fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
332         fProcessedDetectors.SetOwner();
333
334         TLDAPServer aServer(host, port, binddn, password, 3);
335
336         if (!aServer.IsConnected()) {
337                 AliError(Form("Can't connect to ldap server %s:%d",
338                                 host, port));
339                 return;
340         }
341
342         // reads configuration for the shuttle running on this machine
343
344         fShuttleInstanceHost = gSystem->HostName();
345         TString queryFilter = Form("(ShuttleHost=%s)", fShuttleInstanceHost.Data());
346
347         TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
348
349         if (!aResult) {
350                 AliError(Form("Can't find configuration with base DN: %s",
351                                 basedn));
352                 return;
353         }
354
355         if (aResult->GetCount() == 0) {
356                 AliError(Form("No Shuttle instance for host = %s!",
357                                         fShuttleInstanceHost.Data()));
358                 AliError(Form("All detectors will be processed."));
359                 fProcessAll=kTRUE;
360         }
361
362         if (aResult->GetCount() > 1) {
363                 AliError(Form("More than one Shuttle instance for host %s!",
364                                         fShuttleInstanceHost.Data()));
365                 delete aResult;
366                 return;
367         }
368
369         TLDAPEntry* anEntry = 0;
370         TLDAPAttribute* anAttribute = 0;
371
372         if(!fProcessAll){
373                 anEntry = aResult->GetNext();
374                 anAttribute = anEntry->GetAttribute("detectors");
375                 const char *detName;
376                 while((detName = anAttribute->GetValue())){
377                         TObjString *objDet= new TObjString(detName);
378                         fProcessedDetectors.Add(objDet);
379                 }
380         }
381
382         delete anEntry; delete aResult;
383
384         // Detector configuration (DCS Archive DB settings)
385
386         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, "(objectClass=AliShuttleDetector)");
387         if (!aResult) {
388                 AliError(Form("Can't find configuration with base DN: %s", basedn));
389                 return;
390         }
391
392
393         while ((anEntry = aResult->GetNext())) {
394                 AliShuttleConfigHolder* aHolder = new AliShuttleConfigHolder(anEntry);
395                 delete anEntry;
396
397                 if (!aHolder->IsValid()) {
398                         AliError("Detector configuration error!");
399                         delete aHolder;
400                         delete aResult;
401                         return;
402                 }
403
404                 TObjString* detStr = new TObjString(aHolder->GetDetector());
405                 fDetectorMap.Add(detStr, aHolder);
406                 fDetectorList.AddLast(detStr);
407         }
408
409         delete aResult;
410
411         // Global configuration (DAQ logbook)
412
413         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
414                         "(objectClass=AliShuttleGlobalConfig)");
415         if (!aResult) {
416                 AliError(Form("Can't find configuration with base DN: %s",
417                                 basedn));
418                 return;
419         }
420
421         if (aResult->GetCount() == 0) {
422                 AliError("Can't find DAQ logbook configuration!");
423                 delete aResult;
424                 return;
425         }
426
427         if (aResult->GetCount() > 1) {
428                 AliError("More than one DAQ logbook configuration found!");
429                 delete aResult;
430                 return;
431         }
432
433         anEntry = aResult->GetNext();
434
435         anAttribute = anEntry->GetAttribute("DAQLogbookHost");
436         if (!anAttribute) {
437                 AliError("Can't find DAQLogbookHost attribute!");
438                 delete anEntry; delete aResult;
439                 return;
440         }
441         fDAQlbHost = anAttribute->GetValue();
442
443         anAttribute = anEntry->GetAttribute("DAQLogbookPort"); // MAY
444         if (anAttribute)
445         {
446                 fDAQlbPort = ((TString) anAttribute->GetValue()).Atoi();
447         } else {
448                 fDAQlbPort = 3306; // mysql
449         }
450
451         anAttribute = anEntry->GetAttribute("DAQLogbookUser");
452         if (!anAttribute) {
453                 AliError("Can't find DAQLogbookUser attribute!");
454                 delete aResult; delete anEntry;
455                 return;
456         }
457         fDAQlbUser = anAttribute->GetValue();
458
459         anAttribute = anEntry->GetAttribute("DAQLogbookPassword");
460         if (!anAttribute) {
461                 AliError("Can't find DAQLogbookPassword attribute!");
462                 delete aResult; delete anEntry;
463                 return;
464         }
465         fDAQlbPass = anAttribute->GetValue();
466
467         anAttribute = anEntry->GetAttribute("DAQLogbookDB");
468         if (!anAttribute) {
469                 AliError("Can't find DAQLogbookDB attribute!");
470                 delete aResult; delete anEntry;
471                 return;
472         }
473         fDAQlbDB = anAttribute->GetValue();
474
475         anAttribute = anEntry->GetAttribute("DAQLogbookTable");
476         if (!anAttribute) {
477                 AliError("Can't find DAQLogbookTable attribute!");
478                 delete aResult; delete anEntry;
479                 return;
480         }
481         fDAQlbTable = anAttribute->GetValue();
482
483         anAttribute = anEntry->GetAttribute("ShuttleLogbookTable");
484         if (!anAttribute) {
485                 AliError("Can't find ShuttleLogbookTable attribute!");
486                 delete aResult; delete anEntry;
487                 return;
488         }
489         fShuttlelbTable = anAttribute->GetValue();
490
491         anAttribute = anEntry->GetAttribute("RunTypeLogbookTable");
492         if (!anAttribute) {
493                 AliError("Can't find RunTypeLogbookTable attribute!");
494                 delete aResult; delete anEntry;
495                 return;
496         }
497         fRunTypelbTable = anAttribute->GetValue();
498
499         anAttribute = anEntry->GetAttribute("MaxRetries");
500         if (!anAttribute) {
501                 AliError("Can't find MaxRetries attribute!");
502                 delete aResult; delete anEntry;
503                 return;
504         }
505         TString tmpStr = anAttribute->GetValue();
506         fMaxRetries = tmpStr.Atoi();
507
508         anAttribute = anEntry->GetAttribute("PPTimeOut");
509         if (!anAttribute) {
510                 AliError("Can't find PPTimeOut attribute!");
511                 delete aResult; delete anEntry;
512                 return;
513         }
514         tmpStr = anAttribute->GetValue();
515         fPPTimeOut = tmpStr.Atoi();
516
517         delete aResult; delete anEntry;
518
519         // FXS configuration (FXS logbook and hosts)
520
521         for(int iSys=0;iSys<3;iSys++){
522                 queryFilter = Form("(system=%s)", AliShuttleInterface::GetSystemName(iSys));
523                 aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
524                 if (!aResult) {
525                         AliError(Form("Can't find configuration for system: %s",
526                                         AliShuttleInterface::GetSystemName(iSys)));
527                         return;
528                 }
529
530                 if (aResult->GetCount() != 1 ) {
531                         AliError("Error in FXS configuration!");
532                         delete aResult;
533                         return;
534                 }
535
536                 anEntry = aResult->GetNext();
537
538                 anAttribute = anEntry->GetAttribute("DBHost");
539                 if (!anAttribute) {
540                         AliError(Form ("Can't find DBHost attribute for %s!!",
541                                                 AliShuttleInterface::GetSystemName(iSys)));
542                         delete aResult; delete anEntry;
543                         return;
544                 }
545                 fFXSdbHost[iSys] = anAttribute->GetValue();
546
547                 anAttribute = anEntry->GetAttribute("DBPort"); // MAY
548                 if (anAttribute)
549                 {
550                         fFXSdbPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
551                 } else {
552                         fFXSdbPort[iSys] = 3306; // mysql
553                 }
554
555                 anAttribute = anEntry->GetAttribute("DBUser");
556                 if (!anAttribute) {
557                         AliError(Form ("Can't find DBUser attribute for %s!!",
558                                                 AliShuttleInterface::GetSystemName(iSys)));
559                         delete aResult; delete anEntry;
560                         return;
561                 }
562                 fFXSdbUser[iSys] = anAttribute->GetValue();
563
564                 anAttribute = anEntry->GetAttribute("DBPassword");
565                 if (!anAttribute) {
566                         AliError(Form ("Can't find DBPassword attribute for %s!!",
567                                                 AliShuttleInterface::GetSystemName(iSys)));
568                         delete aResult; delete anEntry;
569                         return;
570                 }
571                 fFXSdbPass[iSys] = anAttribute->GetValue();
572
573                 anAttribute = anEntry->GetAttribute("DBName");
574                 if (!anAttribute) {
575                         AliError(Form ("Can't find DBName attribute for %s!!",
576                                                 AliShuttleInterface::GetSystemName(iSys)));
577                         delete aResult; delete anEntry;
578                         return;
579                 }
580
581                 fFXSdbName[iSys] = anAttribute->GetValue();
582                 anAttribute = anEntry->GetAttribute("DBTable");
583                 if (!anAttribute) {
584                         AliError(Form ("Can't find DBTable attribute for %s!!",
585                                                 AliShuttleInterface::GetSystemName(iSys)));
586                         delete aResult; delete anEntry;
587                         return;
588                 }
589                 fFXSdbTable[iSys] = anAttribute->GetValue();
590
591                 anAttribute = anEntry->GetAttribute("FSHost");
592                 if (!anAttribute) {
593                         AliError(Form ("Can't find FSHost attribute for %s!!",
594                                                 AliShuttleInterface::GetSystemName(iSys)));
595                         delete aResult; delete anEntry;
596                         return;
597                 }
598                 fFXSHost[iSys] = anAttribute->GetValue();
599
600                 anAttribute = anEntry->GetAttribute("FSPort"); // MAY
601                 if (anAttribute)
602                 {
603                         fFXSPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
604                 } else {
605                         fFXSPort[iSys] = 22; // scp port number
606                 }
607
608                 anAttribute = anEntry->GetAttribute("FSUser");
609                 if (!anAttribute) {
610                         AliError(Form ("Can't find FSUser attribute for %s!!",
611                                                 AliShuttleInterface::GetSystemName(iSys)));
612                         delete aResult; delete anEntry;
613                         return;
614                 }
615                 fFXSUser[iSys] = anAttribute->GetValue();
616
617                 anAttribute = anEntry->GetAttribute("FSPassword");
618                 if (anAttribute) fFXSPass[iSys] = anAttribute->GetValue();
619
620                 delete aResult; delete anEntry;
621         }
622
623         fIsValid = kTRUE;
624 }
625
626 //______________________________________________________________________________________________
627 AliShuttleConfig::~AliShuttleConfig()
628 {
629 // destructor
630
631         fDetectorMap.DeleteAll();
632         fDetectorList.Clear();
633         fProcessedDetectors.Delete();
634 }
635
636 //______________________________________________________________________________________________
637 const TObjArray* AliShuttleConfig::GetDetectors() const
638 {
639         //
640         // returns collection of TObjString which contains the name
641         // of every detector which is in the configuration.
642         //
643
644         return &fDetectorList;
645 }
646
647 //______________________________________________________________________________________________
648 Bool_t AliShuttleConfig::HasDetector(const char* detector) const
649 {
650         //
651         // checks for paricular detector in the configuration.
652         //
653         return fDetectorMap.GetValue(detector) != NULL;
654 }
655
656 //______________________________________________________________________________________________
657 const char* AliShuttleConfig::GetDCSHost(const char* detector) const
658 {
659         //
660         // returns DCS server host used by particular detector
661         //
662         
663         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
664         if (!aHolder) {
665                 AliError(Form("There isn't configuration for detector: %s",
666                         detector));
667                 return NULL;
668         }
669
670         return aHolder->GetDCSHost();
671 }
672
673 //______________________________________________________________________________________________
674 Int_t AliShuttleConfig::GetDCSPort(const char* detector) const
675 {
676         //
677         // returns DCS server port used by particular detector
678         //
679
680
681         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
682         if (!aHolder) {
683                 AliError(Form("There isn't configuration for detector: %s",
684                         detector));
685                 return 0;
686         }
687
688         return aHolder->GetDCSPort();
689 }
690
691 //______________________________________________________________________________________________
692 const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector) const
693 {
694         //
695         // returns collection of TObjString which represents the set of aliases
696         // which used for data retrieval for particular detector
697         //
698
699         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
700         if (!aHolder) {
701                 AliError(Form("There isn't configuration for detector: %s",
702                         detector));
703                 return NULL;
704         }
705
706         return aHolder->GetDCSAliases();
707 }
708
709 //______________________________________________________________________________________________
710 const TObjArray* AliShuttleConfig::GetDCSDataPoints(const char* detector) const
711 {
712         //
713         // returns collection of TObjString which represents the set of aliases
714         // which used for data retrieval for particular detector
715         //
716
717         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
718         if (!aHolder) {
719                 AliError(Form("There isn't configuration for detector: %s",
720                         detector));
721                 return NULL;
722         }
723
724         return aHolder->GetDCSDataPoints();
725 }
726
727 //______________________________________________________________________________________________
728 const TObjArray* AliShuttleConfig::GetResponsibles(const char* detector) const
729 {
730         //
731         // returns collection of TObjString which represents the list of mail addresses
732         // of the detector's responsible(s)
733         //
734
735         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
736         if (!aHolder) {
737                 AliError(Form("There isn't configuration for detector: %s",
738                         detector));
739                 return NULL;
740         }
741
742         return aHolder->GetResponsibles();
743 }
744
745 //______________________________________________________________________________________________
746 Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
747 {
748         // return TRUE if detector is handled by host or if fProcessAll is TRUE
749
750         if(fProcessAll) return kTRUE;
751         TIter iter(&fProcessedDetectors);
752         TObjString* detName;
753         while((detName = (TObjString*) iter.Next())){
754                 if(detName->String() == detector) return kTRUE;
755         }
756         return kFALSE;
757 }
758
759 //______________________________________________________________________________________________
760 Bool_t AliShuttleConfig::StrictRunOrder(const char* detector) const
761 {
762         // return TRUE if detector wants strict run ordering of stored data
763
764         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
765         if (!aHolder)
766         {
767                 AliError(Form("There isn't configuration for detector: %s",
768                         detector));
769                 return kTRUE;
770         }
771
772         return aHolder->StrictRunOrder();
773 }
774
775 //______________________________________________________________________________________________
776 void AliShuttleConfig::Print(Option_t* option) const
777 {
778 // print configuration
779 // options : "": print configuration for all detectors, aliases and DPs in compacted format
780 //           "uncompact": print configuration for all detectors, aliases and DPs in uncompacted format
781 //           "DET": print configuration for DET, aliases and DPs in compacted format
782 //           "DET, uncompact": print configuration for DET, aliases and DPs in uncompacted format
783
784         TString result;
785         result += '\n';
786
787         result += "####################################################\n";
788         result += Form(" Shuttle configuration from %s \n", fConfigHost.Data());
789         result += "####################################################\n";
790         result += Form("\nShuttle running on %s \n", fShuttleInstanceHost.Data());
791
792         if(fProcessAll) {
793                 result += Form("All detectors will be processed! \n");
794         } else {
795                 result += "Detectors processed by this host: ";
796                 TIter it(&fProcessedDetectors);
797                 TObjString* aDet;
798                 while ((aDet = (TObjString*) it.Next())) {
799                         result += Form("%s ", aDet->String().Data());
800                 }
801                 result += "\n";
802         }
803
804         result += Form("PP time out = %d - Max total retries = %d\n\n", fPPTimeOut, fMaxRetries);
805         result += "------------------------------------------------------\n";
806
807         result += Form("Logbook Configuration \n\n \tHost: %s:%d; \tUser: %s; ",
808                 fDAQlbHost.Data(), fDAQlbPort, fDAQlbUser.Data());
809
810 //      result += "Password: ";
811 //      result.Append('*', fDAQlbPass.Length());
812         result += Form("\tDB: %s; \tTables: %s, %s, %s",
813                 fDAQlbDB.Data(), fDAQlbTable.Data(), fShuttlelbTable.Data(), fRunTypelbTable.Data());
814
815         result += "\n\n";
816
817         result += "------------------------------------------------------\n";
818         result += "FXS configuration\n\n";
819
820         for(int iSys=0;iSys<3;iSys++){
821                 result += Form("*** %s ***\n", AliShuttleInterface::GetSystemName(iSys));
822                 result += Form("\tDB  host: %s:%d; \tUser: %s; \tName: %s; \tTable: %s\n",
823                                                 fFXSdbHost[iSys].Data(), fFXSdbPort[iSys], fFXSdbUser[iSys].Data(),
824                                                 fFXSdbName[iSys].Data(), fFXSdbTable[iSys].Data());
825                 // result += Form("DB Password:",fFXSdbPass[iSys].Data());
826                 result += Form("\tFXS host: %s:%d; \tUser: %s\n\n", fFXSHost[iSys].Data(), fFXSPort[iSys],
827                                                 fFXSUser[iSys].Data());
828                 // result += Form("FXS Password:",fFXSPass[iSys].Data());
829         }
830
831         TString optStr(option);
832
833         result += "------------------------------------------------------\n";
834         result += "Detector-specific configuration\n\n";
835         TIter iter(fDetectorMap.GetTable());
836         TPair* aPair;
837         while ((aPair = (TPair*) iter.Next())) {
838                 AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) aPair->Value();
839                 if (option != 0 && !optStr.Contains(aHolder->GetDetector()) && optStr.CompareTo("uncompact",TString::kIgnoreCase) != 0 )
840                                 continue;
841                 result += Form("*** %s *** \n", aHolder->GetDetector());
842
843                 const TObjArray* responsibles = aHolder->GetResponsibles();
844                 if (responsibles->GetEntries() != 0)
845                 {
846                         result += "\tDetector responsible(s): ";
847                         TIter it(responsibles);
848                         TObjString* aResponsible;
849                         while ((aResponsible = (TObjString*) it.Next()))
850                         {
851                                 result += Form("%s ", aResponsible->String().Data());
852                         }
853                         result += "\n";
854                 }
855
856                 result += Form("\tStrict run ordering: %s \n", aHolder->StrictRunOrder() ? "YES" : "NO");
857                 if(aHolder->SkipDCSQuery())
858                 {
859                         result += "\n";
860                         continue;
861                 }
862                 result += Form("\tAmanda server: %s:%d \n", aHolder->GetDCSHost(), aHolder->GetDCSPort());
863
864                 const TObjArray* aliases = 0;
865                 if (optStr.Contains("uncompact",TString::kIgnoreCase))
866                 {
867                         aliases = aHolder->GetDCSAliases();
868                 } else {
869                         aliases = aHolder->GetCompactDCSAliases();
870                 }
871
872                 if (aliases->GetEntries() != 0)
873                 {
874                         result += "\tDCS Aliases: ";
875                         TIter it(aliases);
876                         TObjString* anAlias;
877                         while ((anAlias = (TObjString*) it.Next()))
878                         {
879                                 result += Form("%s ", anAlias->String().Data());
880                         }
881                         result += "\n";
882                 }
883
884                 const TObjArray* dataPoints = 0;
885                 if (optStr.Contains("uncompact",TString::kIgnoreCase))
886                 {
887                         dataPoints = aHolder->GetDCSDataPoints();
888                 } else {
889                         dataPoints = aHolder->GetCompactDCSDataPoints();
890                 }
891                 if (dataPoints->GetEntries() != 0)
892                 {
893                         result += "\tDCS Data Points: ";
894                         TIter it(dataPoints);
895                         TObjString* aDataPoint;
896                         while ((aDataPoint = (TObjString*) it.Next())) {
897                                 result += Form("%s ", aDataPoint->String().Data());
898                         }
899                                 result += "\n";
900                 }
901                 result += "\n";
902         }
903
904         if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
905
906         AliInfo(result);
907 }