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