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