]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleConfig.cxx
Detectors can have more than one AMANDA server. SHUTTLE queries the servers sequentially,
[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.21  2007/04/27 07:06:48  jgrosseo
19 GetFileSources returns empty list in case of no files, but successful query
20 No mails sent in testmode
21
22 Revision 1.20  2007/04/04 10:33:36  jgrosseo
23 1) 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.
24 In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
25
26 2) 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
28 3) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
29
30 4) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
31
32 5) 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.
33 If you always need DCS data (like before), you do not need to implement it.
34
35 6) The run type has been added to the monitoring page
36
37 Revision 1.19  2007/02/28 10:41:56  acolla
38 Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
39 AliPreprocessor::GetRunType() function.
40 Added some ldap definition files.
41
42 Revision 1.18  2007/01/23 19:20:03  acolla
43 Removed old ldif files, added TOF, MCH ldif files. Added some options in
44 AliShuttleConfig::Print. Added in Ali Shuttle: SetShuttleTempDir and
45 SetShuttleLogDir
46
47 Revision 1.17  2007/01/18 11:17:47  jgrosseo
48 changing spaces to tabs ;-)
49
50 Revision 1.16  2007/01/18 11:10:35  jgrosseo
51 adding the possibility of defining DCS alias and data points with patterns
52 first pattern introduced: [N..M] to add all names between the two digits, this works also recursively.
53
54 Revision 1.15  2007/01/15 18:27:11  acolla
55 implementation of sending mail to subdetector expert in case the preprocessor fails.
56 shuttle.schema updated with expert's email entry
57
58 Revision 1.13  2006/12/07 08:51:26  jgrosseo
59 update (alberto):
60 table, db names in ldap configuration
61 added GRP preprocessor
62 DCS data can also be retrieved by data point
63
64 Revision 1.12  2006/11/16 16:16:48  jgrosseo
65 introducing strict run ordering flag
66 removed giving preprocessor name to preprocessor, they have to know their name themselves ;-)
67
68 Revision 1.11  2006/11/06 14:23:04  jgrosseo
69 major update (Alberto)
70 o) reading of run parameters from the logbook
71 o) online offline naming conversion
72 o) standalone DCSclient package
73
74 Revision 1.10  2006/10/20 15:22:59  jgrosseo
75 o) Adding time out to the execution of the preprocessors: The Shuttle forks and the parent process monitors the child
76 o) Merging Collect, CollectAll, CollectNew function
77 o) Removing implementation of empty copy constructors (declaration still there!)
78
79 Revision 1.9  2006/10/02 16:38:39  jgrosseo
80 update (alberto):
81 fixed memory leaks
82 storing of objects that failed to be stored to the grid before
83 interfacing of shuttle status table in daq system
84
85 Revision 1.8  2006/08/15 10:50:00  jgrosseo
86 effc++ corrections (alberto)
87
88 Revision 1.7  2006/07/20 09:54:40  jgrosseo
89 introducing status management: The processing per subdetector is divided into several steps,
90 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
91 can keep track of the number of failures and skips further processing after a certain threshold is
92 exceeded. These thresholds can be configured in LDAP.
93
94 Revision 1.6  2006/07/19 10:09:55  jgrosseo
95 new configuration, accesst to DAQ FES (Alberto)
96
97 Revision 1.5  2006/07/10 13:01:41  jgrosseo
98 enhanced storing of last sucessfully processed run (alberto)
99
100 Revision 1.4  2006/06/12 09:11:16  jgrosseo
101 coding conventions (Alberto)
102
103 Revision 1.3  2006/06/06 14:26:40  jgrosseo
104 o) removed files that were moved to STEER
105 o) shuttle updated to follow the new interface (Alberto)
106
107 Revision 1.7  2006/05/12 09:07:16  colla
108 12/05/06
109 New configuration complete
110
111 Revision 1.2  2006/03/07 07:52:34  hristov
112 New version (B.Yordanov)
113
114 Revision 1.4  2005/11/19 14:20:31  byordano
115 logbook config added to AliShuttleConfig
116
117 Revision 1.3  2005/11/17 19:24:25  byordano
118 TList changed to TObjArray in AliShuttleConfig
119
120 Revision 1.2  2005/11/17 14:43:23  byordano
121 import to local CVS
122
123 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
124 Initial import as subdirectory in AliRoot
125
126 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
127 SHUTTLE package
128
129 Revision 1.3  2005/08/30 09:13:02  byordano
130 some 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"
146 #include "AliShuttleInterface.h"
147
148 #include "AliLog.h"
149
150 #include <TSystem.h>
151 #include <TObjString.h>
152 #include <TLDAPResult.h>
153 #include <TLDAPEntry.h>
154 #include <TLDAPAttribute.h>
155
156
157 AliShuttleConfig::AliShuttleDCSConfigHolder::AliShuttleDCSConfigHolder(const TLDAPEntry* entry):
158 fDCSHost(""),
159 fDCSPort(0),
160 fDCSAliases(0),
161 fDCSDataPoints(0),
162 fDCSAliasesComp(0),
163 fDCSDataPointsComp(0),
164 fIsValid(kFALSE)
165 {
166 // constructor of the shuttle DCS configuration holder
167
168         TLDAPAttribute* anAttribute;
169         fDCSAliases = new TObjArray();
170         fDCSAliases->SetOwner(1);
171         fDCSDataPoints = new TObjArray();
172         fDCSDataPoints->SetOwner(1);
173         fDCSAliasesComp = new TObjArray();
174         fDCSAliasesComp->SetOwner(1);
175         fDCSDataPointsComp = new TObjArray();
176         fDCSDataPointsComp->SetOwner(1);
177
178         
179         anAttribute = entry->GetAttribute("dcsHost"); 
180         if (!anAttribute)
181         {
182                 AliError("Unexpected: no DCS host!");
183                 return;
184         }
185
186         fDCSHost = anAttribute->GetValue();
187
188         anAttribute = entry->GetAttribute("dcsPort");
189         if (!anAttribute)
190         {
191                 AliError("Unexpected: no DCS port!");
192                 return;
193         }
194         TString portStr = anAttribute->GetValue();
195         fDCSPort = portStr.Atoi();
196
197         anAttribute = entry->GetAttribute("dcsAlias"); // MAY
198         if (anAttribute)
199         {
200                 const char* anAlias;
201                 while ((anAlias = anAttribute->GetValue()))
202                 {
203                         fDCSAliasesComp->AddLast(new TObjString(anAlias));
204                         ExpandAndAdd(fDCSAliases, anAlias);
205                 }
206         }
207
208         anAttribute = entry->GetAttribute("dcsDP"); // MAY
209         if (anAttribute)
210         {
211                 const char* aDataPoint;
212                 while ((aDataPoint = anAttribute->GetValue()))
213                 {
214                 fDCSDataPointsComp->AddLast(new TObjString(aDataPoint));
215                 ExpandAndAdd(fDCSDataPoints, aDataPoint);
216                 }
217         }
218
219         fIsValid = kTRUE;
220 }
221
222 //______________________________________________________________________________________________
223 void AliShuttleConfig::AliShuttleDCSConfigHolder::ExpandAndAdd(TObjArray* target, const char* entry)
224 {
225         //
226         // adds <entry> to <target> applying expanding of the name
227         // [N..M] creates M-N+1 names with the corresponding digits
228         //
229
230         TString entryStr(entry);
231
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()));
238
239                 AliDebug(2, Form("Found [] pattern. Splitted input string %s %s", before.Data(), after.Data()));
240
241                 Int_t dotdot = entryStr.Index("..");
242
243                 TString nStr(entryStr(begin+1, dotdot-begin-1));
244                 TString mStr(entryStr(dotdot+2, end-dotdot-2));
245
246                 AliDebug(2, Form("Found [N..M] pattern. %s %s", nStr.Data(), mStr.Data()));
247
248                 if (nStr.IsDigit() && mStr.IsDigit())
249                 {
250                         Int_t n = nStr.Atoi();
251                         Int_t m = mStr.Atoi();
252
253                         Int_t nDigits = nStr.Length();
254                         TString formatStr;
255                         formatStr.Form("%%s%%0%dd%%s", nDigits);
256
257                         AliDebug(2, Form("Format string is %s", formatStr.Data()));
258
259                         for (Int_t current = n; current<=m; ++current)
260                         {
261                                 TString newEntry;
262                                 newEntry.Form(formatStr.Data(), before.Data(), current, after.Data());
263
264                                 AliDebug(2, Form("Calling recursive with %s", newEntry.Data()));
265
266                                 // and go recursive
267                                 ExpandAndAdd(target, newEntry);
268                         }
269
270                         // return here because we processed the entries already recursively.
271                         return;
272                 }
273         }
274
275         AliDebug(2, Form("Adding name %s", entry));
276         target->AddLast(new TObjString(entry));
277 }
278
279 //______________________________________________________________________________________________
280 AliShuttleConfig::AliShuttleDCSConfigHolder::~AliShuttleDCSConfigHolder()
281 {
282 // destructor of the shuttle configuration holder
283
284         delete fDCSAliases;
285         delete fDCSDataPoints;
286         delete fDCSAliasesComp;
287         delete fDCSDataPointsComp;      
288 }
289
290 //______________________________________________________________________________________________
291 AliShuttleConfig::AliShuttleDetConfigHolder::AliShuttleDetConfigHolder(const TLDAPEntry* entry):
292 fDetector(""),
293 fDCSConfig(),
294 fResponsibles(0),
295 fIsValid(kFALSE),
296 fSkipDCSQuery(kFALSE),
297 fStrictRunOrder(kFALSE)
298 {
299 // constructor of the shuttle configuration holder
300
301         TLDAPAttribute* anAttribute;
302         
303         fResponsibles = new TObjArray();
304         fResponsibles->SetOwner(1);
305         fDCSConfig = new TObjArray();
306         fDCSConfig->SetOwner(1);
307
308         anAttribute = entry->GetAttribute("det"); // MUST
309         if (!anAttribute)
310         {
311                 AliError(Form("No \"det\" attribute!"));
312                 return;
313         }
314         fDetector = anAttribute->GetValue();
315
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();
329         }
330
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));
342                 }
343         }
344
345         fIsValid = kTRUE;
346 }
347
348 //______________________________________________________________________________________________
349 AliShuttleConfig::AliShuttleDetConfigHolder::~AliShuttleDetConfigHolder()
350 {
351 // destructor of the shuttle configuration holder
352
353         delete fResponsibles;
354         delete fDCSConfig;
355 }
356
357 //______________________________________________________________________________________________
358 const 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 }
371
372 //______________________________________________________________________________________________
373 Int_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 }
386
387 //______________________________________________________________________________________________
388 const 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 }
402
403 //______________________________________________________________________________________________
404 const 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         //
410
411         if (iServ < 0 || iServ >= GetNServers()) return 0;
412
413         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
414                                                         (fDCSConfig->At(iServ));
415         
416         return aHolder->GetDCSDataPoints();
417 }
418
419 //______________________________________________________________________________________________
420 const 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         //
426
427         if (iServ < 0 || iServ >= GetNServers()) return 0;
428
429         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
430                                                         (fDCSConfig->At(iServ));
431         
432         return aHolder->GetCompactDCSAliases();
433 }
434
435 //______________________________________________________________________________________________
436 const 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         //
442
443         if (iServ < 0 || iServ >= GetNServers()) return 0;
444
445         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
446                                                         (fDCSConfig->At(iServ));
447         
448         return aHolder->GetCompactDCSDataPoints();
449 }
450
451 //______________________________________________________________________________________________
452 void 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 }
461
462 ClassImp(AliShuttleConfig)
463
464 //______________________________________________________________________________________________
465 AliShuttleConfig::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         //
493
494         fDetectorMap.SetOwner(1);
495         fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
496         fProcessedDetectors.SetOwner();
497
498         TLDAPServer aServer(host, port, binddn, password, 3);
499
500         if (!aServer.IsConnected()) {
501                 AliError(Form("Can't connect to ldap server %s:%d",
502                                 host, port));
503                 return;
504         }
505
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));
527                 return;
528         }
529         
530         while ((anEntry = aResult->GetNext())) 
531         {
532                 TString dn = anEntry->GetDn();
533                 
534                 if (dn.BeginsWith("dcsHost=")) 
535                 {
536                         dcsList.Add(anEntry);
537                 } 
538                 else if (dn.BeginsWith("det="))
539                 {
540                         detList.Add(anEntry);
541                 }
542                 else if (dn.BeginsWith("name=globalConfig"))
543                 {
544                         globalList.Add(anEntry);
545                 }
546                 else if (dn.BeginsWith("system="))
547                 {
548                         sysList.Add(anEntry);
549                 }
550                 else if (dn.BeginsWith("shuttleHost="))
551                 {
552                         hostList.Add(anEntry);
553                 }
554                 else 
555                 {
556                         delete anEntry;
557                 }
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;
576         }
577 }
578
579 //______________________________________________________________________________________________
580 AliShuttleConfig::~AliShuttleConfig()
581 {
582 // destructor
583
584         fDetectorMap.DeleteAll();
585         fDetectorList.Clear();
586         fProcessedDetectors.Delete();
587 }
588
589 //______________________________________________________________________________________________
590 const TObjArray* AliShuttleConfig::GetDetectors() const
591 {
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
600 //______________________________________________________________________________________________
601 Bool_t AliShuttleConfig::HasDetector(const char* detector) const
602 {
603         //
604         // checks for paricular detector in the configuration.
605         //
606         return fDetectorMap.GetValue(detector) != NULL;
607 }
608
609 //______________________________________________________________________________________________
610 Int_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 //______________________________________________________________________________________________
628 const char* AliShuttleConfig::GetDCSHost(const char* detector, Int_t iServ) const
629 {
630         //
631         // returns i-th DCS server host used by particular detector
632         //
633         
634         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
635         if (!aHolder) {
636                 AliError(Form("There isn't configuration for detector: %s",
637                         detector));
638                 return NULL;
639         }
640
641         return aHolder->GetDCSHost(iServ);
642 }
643
644 //______________________________________________________________________________________________
645 Int_t AliShuttleConfig::GetDCSPort(const char* detector, Int_t iServ) const
646 {
647         //
648         // returns i-th DCS server port used by particular detector
649         //
650
651
652         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
653         if (!aHolder) {
654                 AliError(Form("There isn't configuration for detector: %s",
655                         detector));
656                 return 0;
657         }
658
659         return aHolder->GetDCSPort(iServ);
660 }
661
662 //______________________________________________________________________________________________
663 const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector, Int_t iServ) const
664 {
665         //
666         // returns collection of TObjString which represents the i-th set of aliases
667         // which used for data retrieval for particular detector
668         //
669
670         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
671         if (!aHolder) {
672                 AliError(Form("There isn't configuration for detector: %s",
673                         detector));
674                 return NULL;
675         }
676
677         return aHolder->GetDCSAliases(iServ);
678 }
679
680 //______________________________________________________________________________________________
681 const TObjArray* AliShuttleConfig::GetDCSDataPoints(const char* detector, Int_t iServ) const
682 {
683         //
684         // returns collection of TObjString which represents the set of aliases
685         // which used for data retrieval for particular detector
686         //
687
688         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
689         if (!aHolder) {
690                 AliError(Form("There isn't configuration for detector: %s",
691                         detector));
692                 return NULL;
693         }
694
695         return aHolder->GetDCSDataPoints(iServ);
696 }
697
698 //______________________________________________________________________________________________
699 const 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 //______________________________________________________________________________________________
717 const 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);
732 }
733
734 //______________________________________________________________________________________________
735 const 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
742         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
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 //______________________________________________________________________________________________
753 Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
754 {
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;
764 }
765
766 //______________________________________________________________________________________________
767 Bool_t AliShuttleConfig::StrictRunOrder(const char* detector) const
768 {
769         // return TRUE if detector wants strict run ordering of stored data
770
771         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
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 //______________________________________________________________________________________________
783 UInt_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 //______________________________________________________________________________________________
897 UInt_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 //______________________________________________________________________________________________
1018 UInt_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 //______________________________________________________________________________________________
1066 UInt_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 //______________________________________________________________________________________________
1098 void AliShuttleConfig::Print(Option_t* option) const
1099 {
1100 // print configuration
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
1106         TString result;
1107         result += '\n';
1108
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());
1113
1114         if(fProcessAll) {
1115                 result += Form("All detectors will be processed! \n");
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                 }
1123                 result += "\n";
1124         }
1125
1126         result += Form("PP time out = %d - max PP mem size = %d KB - max retries = %d\n\n", 
1127                                 fPPTimeOut, fPPMaxMem, fMaxRetries);
1128         result += "------------------------------------------------------\n";
1129
1130         result += Form("Logbook Configuration \n\n \tHost: %s:%d; \tUser: %s; ",
1131                 fDAQlbHost.Data(), fDAQlbPort, fDAQlbUser.Data());
1132
1133 //      result += "Password: ";
1134 //      result.Append('*', fDAQlbPass.Length());
1135         result += Form("\tDB: %s; \tTables: %s, %s, %s",
1136                 fDAQlbDB.Data(), fDAQlbTable.Data(), fShuttlelbTable.Data(), fRunTypelbTable.Data());
1137
1138         result += "\n\n";
1139
1140         result += "------------------------------------------------------\n";
1141         result += "FXS configuration\n\n";
1142
1143         for(int iSys=0;iSys<3;iSys++){
1144                 result += Form("*** %s ***\n", AliShuttleInterface::GetSystemName(iSys));
1145                 result += Form("\tDB  host: %s:%d; \tUser: %s; \tName: %s; \tTable: %s\n",
1146                                                 fFXSdbHost[iSys].Data(), fFXSdbPort[iSys], fFXSdbUser[iSys].Data(),
1147                                                 fFXSdbName[iSys].Data(), fFXSdbTable[iSys].Data());
1148                 // result += Form("DB Password:",fFXSdbPass[iSys].Data());
1149                 result += Form("\tFXS host: %s:%d; \tUser: %s\n\n", fFXSHost[iSys].Data(), fFXSPort[iSys],
1150                                                 fFXSUser[iSys].Data());
1151                 // result += Form("FXS Password:",fFXSPass[iSys].Data());
1152         }
1153
1154         TString optStr(option);
1155
1156         result += "------------------------------------------------------\n";
1157         result += "Detector-specific configuration\n\n";
1158         
1159         TIter iter(fDetectorMap.GetTable());
1160         TPair* aPair = 0;
1161         
1162         AliInfo(Form("Option = %s", option));
1163         
1164         while ((aPair = (TPair*) iter.Next())) {
1165                 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) aPair->Value();
1166                 if (optStr != "" && !optStr.Contains(aHolder->GetDetector()) && 
1167                                 optStr.CompareTo("uncompact",TString::kIgnoreCase) != 0 )
1168                                 continue;
1169                 
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
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())))
1193                 {
1194                         result += Form("\tAmanda server [%d]: %s:%d \n", count,
1195                                 dcsHolder->GetDCSHost(), dcsHolder->GetDCSPort());
1196
1197                         const TObjArray* aliases = 0;
1198                         if (optStr.Contains("uncompact",TString::kIgnoreCase))
1199                         {
1200                                 aliases = dcsHolder->GetDCSAliases();
1201                         } else {
1202                                 aliases = dcsHolder->GetCompactDCSAliases();
1203                         }
1204
1205                         if (aliases->GetEntries() != 0)
1206                         {
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";
1215                         }
1216
1217                         const TObjArray* dataPoints = 0;
1218                         if (optStr.Contains("uncompact",TString::kIgnoreCase))
1219                         {
1220                                 dataPoints = dcsHolder->GetDCSDataPoints();
1221                         } else {
1222                                 dataPoints = dcsHolder->GetCompactDCSDataPoints();
1223                         }
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                                 }
1232                                 result += "\n";
1233                         }
1234                         count++;
1235                         result += "\n";
1236                 }
1237         }
1238         if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
1239
1240         AliInfo(result);
1241 }