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