da8998be15136c7c5ed2665c90c01d4b5e5fa14a
[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 #include <Riostream.h>
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         fAlienPath(other.fAlienPath),
275         fDAQlbHost(other.fDAQlbHost),
276         fDAQlbPort(other.fDAQlbPort),
277         fDAQlbUser(other.fDAQlbUser),
278         fDAQlbPass(other.fDAQlbPass),
279         fDAQlbDB(other.fDAQlbDB),
280         fDAQlbTable(other.fDAQlbTable),
281         fShuttlelbTable(other.fShuttlelbTable),
282         fRunTypelbTable(other.fRunTypelbTable),
283         fPasswdFilePath(other.fPasswdFilePath),
284         fMaxRetries(other.fMaxRetries),
285         fPPTimeOut(other.fPPTimeOut),
286         fDCSTimeOut(other.fDCSTimeOut),
287         fDCSRetries(other.fDCSRetries),
288         fPPMaxMem(other.fPPMaxMem),
289         fMonitorHost(other.fMonitorHost),
290         fMonitorTable(other.fMonitorTable),
291         fTriggerWait(other.fTriggerWait),
292         fRunMode(other.fRunMode),
293         fDetectorMap(),
294         fDetectorList(other.fDetectorList),
295         fShuttleInstanceHost(other.fShuttleInstanceHost),
296         fProcessedDetectors(other.fProcessedDetectors),
297         fKeepDCSMap(other.fKeepDCSMap),
298         fKeepTempFolder(other.fKeepTempFolder),
299         fSendMail(other.fSendMail),
300         fProcessAll(other.fProcessAll),
301         fIsValid(other.fIsValid)
302 {
303         //
304         // copy ctor
305         //
306         for (Int_t i = 0; i<3; i++){
307                 fFXSHost[i]=other.fFXSHost[i];
308                 fFXSPort[i]=other.fFXSPort[i];
309                 fFXSUser[i]=other.fFXSUser[i];
310                 fFXSPass[i]=other.fFXSPass[i];
311                 fFXSBaseFolder[i]=other.fFXSBaseFolder[i];
312                 fFXSdbHost[i]=other.fFXSdbHost[i];
313                 fFXSdbPort[i]=other.fFXSdbPort[i];
314                 fFXSdbUser[i]=other.fFXSdbUser[i];
315                 fFXSdbPass[i]=other.fFXSdbPass[i];
316                 fFXSdbName[i]=other.fFXSdbName[i];
317                 fFXSdbTable[i]=other.fFXSdbTable[i];
318         }
319         for (Int_t i = 0; i<5; i++){
320                 fAdmin[i] = new TObjArray();
321                 fAdmin[i]->AddAt(other.fAdmin[i]->At(i),i);
322         }
323
324         TIter iter((other.fDetectorMap).GetTable());
325         TPair* aPair = 0;
326         
327         while ((aPair = (TPair*) iter.Next())) {
328                 AliShuttleDetConfigHolder *holder =(AliShuttleDetConfigHolder *)aPair->Value();
329                 TKey *key = (TKey*)aPair->Key();
330                 fDetectorMap.Add(key,holder);
331         }
332
333
334
335 //_____________________________________________________________________________________________         
336 AliShuttleConfig& AliShuttleConfig::operator=(const AliShuttleConfig &other) 
337 {
338         //
339         //assignment operator
340         //
341         this->fConfigHost=other.fConfigHost;
342         this->fDAQlbHost=other.fDAQlbHost;
343         this->fDAQlbPort=other.fDAQlbPort;
344         this->fDAQlbUser=other.fDAQlbUser;
345         this->fDAQlbPass=other.fDAQlbPass;
346         this->fDAQlbDB=other.fDAQlbDB;
347         this->fDAQlbTable=other.fDAQlbTable;
348         this->fShuttlelbTable=other.fShuttlelbTable;
349         this->fRunTypelbTable=other.fRunTypelbTable;
350         this->fPasswdFilePath=other.fPasswdFilePath;
351         this->fMaxRetries=other.fMaxRetries;
352         this->fPPTimeOut=other.fPPTimeOut;
353         this->fDCSTimeOut=other.fDCSTimeOut;
354         this->fDCSRetries=other.fDCSRetries;
355         this->fPPMaxMem=other.fPPMaxMem;
356         this->fMonitorHost=other.fMonitorHost;
357         this->fMonitorTable=other.fMonitorTable;
358         this->fTriggerWait=other.fTriggerWait;
359         this->fRunMode=other.fRunMode;
360         this->fDetectorList=other.fDetectorList;
361         this->fShuttleInstanceHost=other.fShuttleInstanceHost;
362         this->fProcessedDetectors=other.fProcessedDetectors;
363         this->fKeepDCSMap=other.fKeepDCSMap;
364         this->fKeepTempFolder=other.fKeepTempFolder;
365         this->fSendMail=other.fSendMail;
366         this->fProcessAll=other.fProcessAll;
367         this->fIsValid=other.fIsValid;
368         for (Int_t i = 0; i<3; i++){
369                 this->fFXSHost[i]=other.fFXSHost[i];
370                 this->fFXSPort[i]=other.fFXSPort[i];
371                 this->fFXSUser[i]=other.fFXSUser[i];
372                 this->fFXSPass[i]=other.fFXSPass[i];
373                 this->fFXSBaseFolder[i]=other.fFXSBaseFolder[i];
374                 this->fFXSdbHost[i]=other.fFXSdbHost[i];
375                 this->fFXSdbPort[i]=other.fFXSdbPort[i];
376                 this->fFXSdbUser[i]=other.fFXSdbUser[i];
377                 this->fFXSdbPass[i]=other.fFXSdbPass[i];
378                 this->fFXSdbName[i]=other.fFXSdbName[i];
379                 this->fFXSdbTable[i]=other.fFXSdbTable[i];
380         }
381         for (Int_t i = 0; i<5; i++){
382                 this->fAdmin[i] = new TObjArray();
383                 this->fAdmin[i]->AddAt(other.fAdmin[i]->At(i),i);
384         }
385
386         TIter iter((other.fDetectorMap).GetTable());
387         TPair* aPair = 0;
388         
389         while ((aPair = (TPair*) iter.Next())) {
390                 AliShuttleDetConfigHolder *holder =(AliShuttleDetConfigHolder *)aPair->Value();
391                 TKey *key = (TKey*)aPair->Key();
392                 this->fDetectorMap.Add(key,holder);
393         }
394         return *this;
395
396 //______________________________________________________________________________________________
397 void AliShuttleConfig::AliShuttleDCSConfigHolder::ExpandAndAdd(TObjArray* target, const char* entry)
398 {
399         //
400         // adds <entry> to <target> applying expanding of the name
401         // [N..M] creates M-N+1 names with the corresponding digits
402         //
403
404         TString entryStr(entry);
405
406         Int_t begin = entryStr.Index("[");
407         Int_t end = entryStr.Index("]");
408         if (begin != -1 && end != -1 && end > begin)
409         {
410                 TString before(entryStr(0, begin));
411                 TString after(entryStr(end+1, entryStr.Length()));
412
413                 AliDebug(2, Form("Found [] pattern. Splitted input string %s %s", before.Data(), after.Data()));
414
415                 Int_t dotdot = entryStr.Index("..");
416
417                 TString nStr(entryStr(begin+1, dotdot-begin-1));
418                 TString mStr(entryStr(dotdot+2, end-dotdot-2));
419
420                 AliDebug(2, Form("Found [N..M] pattern. %s %s", nStr.Data(), mStr.Data()));
421
422                 if (nStr.IsDigit() && mStr.IsDigit())
423                 {
424                         Int_t n = nStr.Atoi();
425                         Int_t m = mStr.Atoi();
426
427                         Int_t nDigits = nStr.Length();
428                         TString formatStr;
429                         formatStr.Form("%%s%%0%dd%%s", nDigits);
430
431                         AliDebug(2, Form("Format string is %s", formatStr.Data()));
432
433                         for (Int_t current = n; current<=m; ++current)
434                         {
435                                 TString newEntry;
436                                 newEntry.Form(formatStr.Data(), before.Data(), current, after.Data());
437
438                                 AliDebug(2, Form("Calling recursive with %s", newEntry.Data()));
439
440                                 // and go recursive
441                                 ExpandAndAdd(target, newEntry);
442                         }
443
444                         // return here because we processed the entries already recursively.
445                         return;
446                 }
447         }
448
449         AliDebug(2, Form("Adding name %s", entry));
450         target->AddLast(new TObjString(entry));
451 }
452
453 //______________________________________________________________________________________________
454 AliShuttleConfig::AliShuttleDCSConfigHolder::~AliShuttleDCSConfigHolder()
455 {
456 // destructor of the shuttle configuration holder
457
458         delete fDCSAliases;
459         delete fDCSDataPoints;
460         delete fDCSAliasesComp;
461         delete fDCSDataPointsComp;      
462 }
463
464 //______________________________________________________________________________________________
465 AliShuttleConfig::AliShuttleDetConfigHolder::AliShuttleDetConfigHolder(const TLDAPEntry* entry):
466 fDetector(""),
467 fDCSConfig(),
468 fResponsibles(0),
469 fIsValid(kFALSE),
470 fSkipDCSQuery(kFALSE),
471 fStrictRunOrder(kFALSE)
472 {
473 // constructor of the shuttle configuration holder
474
475         TLDAPAttribute* anAttribute;
476         
477         fResponsibles = new TObjArray();
478         fResponsibles->SetOwner(1);
479         fDCSConfig = new TObjArray();
480         fDCSConfig->SetOwner(1);
481
482         anAttribute = entry->GetAttribute("det"); // MUST
483         if (!anAttribute)
484         {
485                 AliError(Form("No \"det\" attribute!"));
486                 return;
487         }
488         fDetector = anAttribute->GetValue();
489
490         anAttribute = entry->GetAttribute("strictRunOrder"); // MAY
491         if (!anAttribute)
492         {
493                 AliWarning(Form("%s did not set strictRunOrder flag - the default is FALSE",
494                                 fDetector.Data()));
495         } else {
496                 TString strictRunStr = anAttribute->GetValue();
497                 if (!(strictRunStr == "0" || strictRunStr == "1"))
498                 {
499                         AliError("strictRunOrder flag must be 0 or 1!");
500                         return;
501                 }
502                 fStrictRunOrder = (Bool_t) strictRunStr.Atoi();
503         }
504
505         anAttribute = entry->GetAttribute("responsible"); // MAY
506         if (!anAttribute)
507         {
508                 AliDebug(2, "Warning! No \"responsible\" attribute!");
509         }
510         else
511         {
512                 const char* aResponsible;
513                 while ((aResponsible = anAttribute->GetValue()))
514                 {
515                         fResponsibles->AddLast(new TObjString(aResponsible));
516                 }
517         }
518
519         fIsValid = kTRUE;
520 }
521
522 //______________________________________________________________________________________________
523 AliShuttleConfig::AliShuttleDetConfigHolder::~AliShuttleDetConfigHolder()
524 {
525 // destructor of the shuttle configuration holder
526
527         delete fResponsibles;
528         delete fDCSConfig;
529 }
530
531 //______________________________________________________________________________________________
532 const char* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSHost(Int_t iServ) const
533 {
534         //
535         // returns DCS server host 
536         //
537         
538         if (iServ < 0 || iServ >= GetNServers()) return 0;
539         
540         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
541                                                         (fDCSConfig->At(iServ));
542         
543         return aHolder->GetDCSHost();
544 }
545
546 //______________________________________________________________________________________________
547 Int_t AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSPort(Int_t iServ) const
548 {
549         //
550         // returns DCS server port 
551         //
552         
553         if (iServ < 0 || iServ >= GetNServers()) return 0;
554         
555         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
556                                                         (fDCSConfig->At(iServ));
557         
558         return aHolder->GetDCSPort();
559 }
560
561 //______________________________________________________________________________________________
562 Int_t AliShuttleConfig::AliShuttleDetConfigHolder::GetMultiSplit(Int_t iServ) const
563 {
564         //
565         // returns DCS "multi split" value
566         //
567         
568         if (iServ < 0 || iServ >= GetNServers()) return 0;
569         
570         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
571                                                         (fDCSConfig->At(iServ));
572         
573         return aHolder->GetMultiSplit();
574 }
575
576 //______________________________________________________________________________________________
577 const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSAliases(Int_t iServ) const
578 {
579         //
580         // returns collection of TObjString which represents the set of aliases
581         // which used for data retrieval for particular detector
582         //
583         
584         if (iServ < 0 || iServ >= GetNServers()) return 0;
585         
586         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
587                                                         (fDCSConfig->At(iServ));
588         
589         return aHolder->GetDCSAliases();
590 }
591
592 //______________________________________________________________________________________________
593 const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetDCSDataPoints(Int_t iServ) const
594 {
595         //
596         // returns collection of TObjString which represents the set of aliases
597         // which used for data retrieval for particular detector
598         //
599
600         if (iServ < 0 || iServ >= GetNServers()) return 0;
601
602         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
603                                                         (fDCSConfig->At(iServ));
604         
605         return aHolder->GetDCSDataPoints();
606 }
607
608 //______________________________________________________________________________________________
609 const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetCompactDCSAliases(Int_t iServ) const
610 {
611         //
612         // returns collection of TObjString which represents the set of aliases
613         // which used for data retrieval for particular detector (Compact style)
614         //
615
616         if (iServ < 0 || iServ >= GetNServers()) return 0;
617
618         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
619                                                         (fDCSConfig->At(iServ));
620         
621         return aHolder->GetCompactDCSAliases();
622 }
623
624 //______________________________________________________________________________________________
625 const TObjArray* AliShuttleConfig::AliShuttleDetConfigHolder::GetCompactDCSDataPoints(Int_t iServ) const
626 {
627         //
628         // returns collection of TObjString which represents the set of aliases
629         // which used for data retrieval for particular detector (Compact style)
630         //
631
632         if (iServ < 0 || iServ >= GetNServers()) return 0;
633
634         AliShuttleDCSConfigHolder *aHolder = dynamic_cast<AliShuttleDCSConfigHolder *> 
635                                                         (fDCSConfig->At(iServ));
636         
637         return aHolder->GetCompactDCSDataPoints();
638 }
639
640 //______________________________________________________________________________________________
641 void AliShuttleConfig::AliShuttleDetConfigHolder::AddDCSConfig(AliShuttleDCSConfigHolder* holder)
642 {
643         //
644         // adds a DCS configuration set in the array of DCS configurations
645         // 
646         
647         if(!holder) return;
648         fDCSConfig->AddLast(holder);
649 }
650
651 ClassImp(AliShuttleConfig)
652
653 //______________________________________________________________________________________________
654 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
655         const char* binddn, const char* password, const char* basedn):
656         fConfigHost(host), 
657         fAlienPath(""), 
658         fDAQlbHost(""), 
659         fDAQlbPort(), 
660         fDAQlbUser(""), 
661         fDAQlbPass(""),
662         fDAQlbDB(""), 
663         fDAQlbTable(""), 
664         fShuttlelbTable(""), 
665         fRunTypelbTable(""),
666         fPasswdFilePath(""),
667         fMaxRetries(0), 
668         fPPTimeOut(0), 
669         fDCSTimeOut(0), 
670         fDCSRetries(0), 
671         fDCSQueryOffset(0),
672         fDCSDelay(0),
673         fPPMaxMem(0), 
674         fMonitorHost(""), 
675         fMonitorTable(""), 
676         fTriggerWait(3600),
677         fRunMode(kTest),
678         fDetectorMap(), 
679         fDetectorList(),
680         fAdmin(),
681         fShuttleInstanceHost(""), 
682         fProcessedDetectors(), 
683         fKeepDCSMap(kFALSE),
684         fKeepTempFolder(kFALSE),
685         fSendMail(kFALSE),
686         fProcessAll(kFALSE), 
687         fIsValid(kFALSE)
688
689 {
690         //
691         // host: ldap server host
692         // port: ldap server port
693         // binddn: binddn used for ldap binding (simple bind is used!).
694         // password: password for binddn
695         // basedn: this is basedn whose childeren entries which have
696         //
697
698         fDetectorMap.SetOwner(1);
699         fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
700         fProcessedDetectors.SetOwner();
701         
702         for (int i=0; i<5; i++)
703         {
704                 fAdmin[i] = new TObjArray(); 
705                 fAdmin[i]->SetOwner();
706         }
707
708         TLDAPServer aServer(host, port, binddn, password, 3);
709
710         if (!aServer.IsConnected()) {
711                 AliError(Form("Can't connect to ldap server %s:%d",
712                                 host, port));
713                 return;
714         }
715
716         // reads configuration for the shuttle running on this machine
717         
718         TLDAPResult* aResult = 0;
719         TLDAPEntry* anEntry = 0;
720         
721         TList dcsList;
722         dcsList.SetOwner(1);
723         TList detList;
724         detList.SetOwner(1);
725         TList globalList;
726         globalList.SetOwner(1);
727         TList sysList;
728         sysList.SetOwner(1);
729         TList hostList;
730         hostList.SetOwner(1);
731         
732         aResult = aServer.Search(basedn, LDAP_SCOPE_SUBTREE, 0, 0);
733         
734         if (!aResult) 
735         {
736                 AliError(Form("Can't find configuration with base DN: %s !", basedn));
737                 return;
738         }
739         
740         while ((anEntry = aResult->GetNext())) 
741         {
742                 TString dn = anEntry->GetDn();
743                 
744                 if (dn.BeginsWith("dcsHost=")) 
745                 {
746                         dcsList.Add(anEntry);
747                 } 
748                 else if (dn.BeginsWith("det="))
749                 {
750                         detList.Add(anEntry);
751                 }
752                 else if (dn.BeginsWith("name=globalConfig"))
753                 {
754                         globalList.Add(anEntry);
755                 }
756                 else if (dn.BeginsWith("system="))
757                 {
758                         sysList.Add(anEntry);
759                 }
760                 else if (dn.BeginsWith("shuttleHost="))
761                 {
762                         hostList.Add(anEntry);
763                 }
764                 else 
765                 {
766                         delete anEntry;
767                 }
768         
769         }
770         delete aResult;
771         
772         Int_t result=0;
773         
774         result += SetGlobalConfig(&globalList);
775         result += SetSysConfig(&sysList);
776         result += SetPasswords();
777         result += SetDetConfig(&detList,&dcsList);
778         result += SetHostConfig(&hostList);
779         
780         if(result) 
781         {
782                 AliError("Configuration is INVALID!");
783         }
784         else 
785         {
786                 fIsValid = kTRUE;
787         }
788 }
789
790 //______________________________________________________________________________________________
791 AliShuttleConfig::~AliShuttleConfig()
792 {
793 // destructor
794
795         fDetectorMap.DeleteAll();
796         fDetectorList.Clear();
797         fProcessedDetectors.Delete();
798 }
799
800 //______________________________________________________________________________________________
801 const TObjArray* AliShuttleConfig::GetDetectors() const
802 {
803         //
804         // returns collection of TObjString which contains the name
805         // of every detector which is in the configuration.
806         //
807
808         return &fDetectorList;
809 }
810
811 //______________________________________________________________________________________________
812 Bool_t AliShuttleConfig::HasDetector(const char* detector) const
813 {
814         //
815         // checks for paricular detector in the configuration.
816         //
817         return fDetectorMap.GetValue(detector) != NULL;
818 }
819
820 //______________________________________________________________________________________________
821 Int_t AliShuttleConfig::GetNServers(const char* detector) const
822 {
823         //
824         // returns number of DCS servers for detector
825         //
826         
827         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
828         if (!aHolder) {
829                 AliError(Form("There isn't configuration for detector: %s",
830                         detector));
831                 return 0;
832         }
833
834         return aHolder->GetNServers();
835 }
836
837
838 //______________________________________________________________________________________________
839 const char* AliShuttleConfig::GetDCSHost(const char* detector, Int_t iServ) const
840 {
841         //
842         // returns i-th DCS server host used by particular detector
843         //
844         
845         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
846         if (!aHolder) {
847                 AliError(Form("There isn't configuration for detector: %s",
848                         detector));
849                 return NULL;
850         }
851
852         return aHolder->GetDCSHost(iServ);
853 }
854
855 //______________________________________________________________________________________________
856 Int_t AliShuttleConfig::GetDCSPort(const char* detector, Int_t iServ) const
857 {
858         //
859         // returns i-th DCS server port used by particular detector
860         //
861
862
863         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
864         if (!aHolder) {
865                 AliError(Form("There isn't configuration for detector: %s",
866                         detector));
867                 return 0;
868         }
869
870         return aHolder->GetDCSPort(iServ);
871 }
872
873 //______________________________________________________________________________________________
874 Int_t AliShuttleConfig::GetMultiSplit(const char* detector, Int_t iServ) const
875 {
876         //
877         // returns i-th DCS "multi split" value
878         //
879
880
881         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
882         if (!aHolder) {
883                 AliError(Form("There isn't configuration for detector: %s",
884                         detector));
885                 return 0;
886         }
887
888         return aHolder->GetMultiSplit(iServ);
889 }
890
891 //______________________________________________________________________________________________
892 const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector, Int_t iServ) const
893 {
894         //
895         // returns collection of TObjString which represents the i-th set of aliases
896         // which used for data retrieval for particular detector
897         //
898
899         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
900         if (!aHolder) {
901                 AliError(Form("There isn't configuration for detector: %s",
902                         detector));
903                 return NULL;
904         }
905
906         return aHolder->GetDCSAliases(iServ);
907 }
908
909 //______________________________________________________________________________________________
910 const TObjArray* AliShuttleConfig::GetDCSDataPoints(const char* detector, Int_t iServ) const
911 {
912         //
913         // returns collection of TObjString which represents the set of aliases
914         // which used for data retrieval for particular detector
915         //
916
917         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
918         if (!aHolder) {
919                 AliError(Form("There isn't configuration for detector: %s",
920                         detector));
921                 return NULL;
922         }
923
924         return aHolder->GetDCSDataPoints(iServ);
925 }
926
927 //______________________________________________________________________________________________
928 const TObjArray* AliShuttleConfig::GetCompactDCSAliases(const char* detector, Int_t iServ) const
929 {
930         //
931         // returns collection of TObjString which represents the i-th set of aliases
932         // which used for data retrieval for particular detector (Compact style)
933         //
934
935         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
936         if (!aHolder) {
937                 AliError(Form("There isn't configuration for detector: %s",
938                         detector));
939                 return NULL;
940         }
941
942         return aHolder->GetCompactDCSAliases(iServ);
943 }
944
945 //______________________________________________________________________________________________
946 const TObjArray* AliShuttleConfig::GetCompactDCSDataPoints(const char* detector, Int_t iServ) const
947 {
948         //
949         // returns collection of TObjString which represents the set of aliases
950         // which used for data retrieval for particular detector (Compact style)
951         //
952
953         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
954         if (!aHolder) {
955                 AliError(Form("There isn't configuration for detector: %s",
956                         detector));
957                 return NULL;
958         }
959
960         return aHolder->GetCompactDCSDataPoints(iServ);
961 }
962
963 //______________________________________________________________________________________________
964 const TObjArray* AliShuttleConfig::GetResponsibles(const char* detector) const
965 {
966         //
967         // returns collection of TObjString which represents the list of mail addresses
968         // of the detector's responsible(s)
969         //
970
971         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
972         if (!aHolder) {
973                 AliError(Form("There isn't configuration for detector: %s",
974                         detector));
975                 return NULL;
976         }
977
978         return aHolder->GetResponsibles();
979 }
980
981 //______________________________________________________________________________________________
982 const TObjArray* AliShuttleConfig::GetAdmins(Int_t sys) const
983 {
984         //
985         // returns collection of TObjString which represents the list of mail addresses
986         // of the system's administrator(s) (DAQ, DCS, HLT, Global, Amanda)
987         //
988
989         if (sys < 0 || sys > 4) return 0;
990         return fAdmin[sys];
991 }
992
993 //______________________________________________________________________________________________
994 Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
995 {
996         // return TRUE if detector is handled by host or if fProcessAll is TRUE
997
998         if(fProcessAll) return kTRUE;
999         TIter iter(&fProcessedDetectors);
1000         TObjString* detName;
1001         while((detName = (TObjString*) iter.Next())){
1002                 if(detName->String() == detector) return kTRUE;
1003         }
1004         return kFALSE;
1005 }
1006
1007 //______________________________________________________________________________________________
1008 Bool_t AliShuttleConfig::StrictRunOrder(const char* detector) const
1009 {
1010         // return TRUE if detector wants strict run ordering of stored data
1011
1012         AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) fDetectorMap.GetValue(detector);
1013         if (!aHolder)
1014         {
1015                 AliError(Form("There isn't configuration for detector: %s",
1016                         detector));
1017                 return kTRUE;
1018         }
1019
1020         return aHolder->StrictRunOrder();
1021 }
1022
1023 //______________________________________________________________________________________________
1024 UInt_t AliShuttleConfig::SetGlobalConfig(TList* list)
1025 {
1026         // Set the global configuration (DAQ Logbook + preprocessor monitoring settings)
1027
1028
1029         TLDAPEntry* anEntry = 0;
1030         TLDAPAttribute* anAttribute = 0;
1031         
1032         if (list->GetEntries() == 0) 
1033         {
1034                 AliError("Global configuration not found!");
1035                 return 1;
1036         } 
1037         else if (list->GetEntries() > 1)
1038         {
1039                 AliError("More than one global configuration found!");
1040                 return 2;
1041         }
1042         
1043         anEntry = dynamic_cast<TLDAPEntry*> (list->At(0));
1044         
1045         if (!anEntry)
1046         {
1047                 AliError("Unexpected! Global list does not contain a TLDAPEntry");
1048                 return 3;
1049         } 
1050         
1051         
1052         anAttribute = anEntry->GetAttribute("AlienPath");
1053         if (!anAttribute) {
1054                 AliError("Can't find AlienPath attribute!");
1055                 return 4;
1056         }
1057         fAlienPath = anAttribute->GetValue();
1058
1059         anAttribute = anEntry->GetAttribute("daqLbHost");
1060         if (!anAttribute) {
1061                 AliError("Can't find daqLbHost attribute!");
1062                 return 4;
1063         }
1064         fDAQlbHost = anAttribute->GetValue();
1065
1066         anAttribute = anEntry->GetAttribute("daqLbPort"); // MAY
1067         if (anAttribute)
1068         {
1069                 fDAQlbPort = ((TString) anAttribute->GetValue()).Atoi();
1070         } else {
1071                 fDAQlbPort = 3306; // mysql
1072         }
1073
1074         anAttribute = anEntry->GetAttribute("daqLbUser");
1075         if (!anAttribute) {
1076                 AliError("Can't find daqLbUser attribute!");
1077                 return 4;
1078         }
1079         fDAQlbUser = anAttribute->GetValue();
1080
1081         anAttribute = anEntry->GetAttribute("daqLbDB");
1082         if (!anAttribute) {
1083                 AliError("Can't find daqLbDB attribute!");
1084                 return 4;
1085         }
1086         fDAQlbDB = anAttribute->GetValue();
1087
1088         anAttribute = anEntry->GetAttribute("daqLbTable");
1089         if (!anAttribute) {
1090                 AliError("Can't find daqLbTable attribute!");
1091                 return 4;
1092         }
1093         fDAQlbTable = anAttribute->GetValue();
1094
1095         anAttribute = anEntry->GetAttribute("shuttleLbTable");
1096         if (!anAttribute) {
1097                 AliError("Can't find shuttleLbTable attribute!");
1098                 return 4;
1099         }
1100         fShuttlelbTable = anAttribute->GetValue();
1101
1102         anAttribute = anEntry->GetAttribute("runTypeLbTable");
1103         if (!anAttribute) {
1104                 AliError("Can't find runTypeLbTable attribute!");
1105                 return 4;
1106         }
1107         fRunTypelbTable = anAttribute->GetValue();
1108
1109         anAttribute = anEntry->GetAttribute("ppmaxRetries");
1110         if (!anAttribute) {
1111                 AliError("Can't find ppmaxRetries attribute!");
1112                 return 4;
1113         }
1114         TString tmpStr = anAttribute->GetValue();
1115         fMaxRetries = tmpStr.Atoi();
1116
1117         anAttribute = anEntry->GetAttribute("ppTimeOut");
1118         if (!anAttribute) {
1119                 AliError("Can't find ppTimeOut attribute!");
1120                 return 4;
1121         }
1122         tmpStr = anAttribute->GetValue();
1123         fPPTimeOut = tmpStr.Atoi();
1124
1125         anAttribute = anEntry->GetAttribute("dcsTimeOut");
1126         if (!anAttribute) {
1127                 AliError("Can't find dcsTimeOut attribute!");
1128                 return 4;
1129         }
1130         tmpStr = anAttribute->GetValue();
1131         fDCSTimeOut = tmpStr.Atoi();
1132
1133         anAttribute = anEntry->GetAttribute("nDCSretries");
1134         if (!anAttribute) {
1135                 AliError("Can't find dcsTimeOut attribute!");
1136                 return 4;
1137         }
1138         tmpStr = anAttribute->GetValue();
1139         fDCSRetries = tmpStr.Atoi();
1140
1141         anAttribute = anEntry->GetAttribute("DCSQueryOffset");
1142         if (!anAttribute) {
1143                 AliError("Can't find DCSQueryOffset attribute!");
1144                 return 4;
1145         }
1146         tmpStr = anAttribute->GetValue();
1147         fDCSQueryOffset = tmpStr.Atoi();
1148
1149         anAttribute = anEntry->GetAttribute("DCSDelay");
1150         if (!anAttribute) {
1151                 AliError("Can't find DCSDelay attribute!");
1152                 return 4;
1153         }
1154         tmpStr = anAttribute->GetValue();
1155         fDCSDelay = tmpStr.Atoi();
1156
1157         anAttribute = anEntry->GetAttribute("ppMaxMem");
1158         if (!anAttribute) {
1159                 AliError("Can't find ppMaxMem attribute!");
1160                 return 4;
1161         }
1162         tmpStr = anAttribute->GetValue();
1163         fPPMaxMem = tmpStr.Atoi();
1164         
1165         anAttribute = anEntry->GetAttribute("monitorHost");
1166         if (!anAttribute) {
1167                 AliError("Can't find monitorHost attribute!");
1168                 return 4;
1169         }
1170         fMonitorHost = anAttribute->GetValue();
1171         
1172         anAttribute = anEntry->GetAttribute("monitorTable");
1173         if (!anAttribute) {
1174                 AliError("Can't find monitorTable attribute!");
1175                 return 4;
1176         }
1177         fMonitorTable = anAttribute->GetValue();
1178
1179         anAttribute = anEntry->GetAttribute("triggerWait"); // MAY
1180         if (!anAttribute) {
1181                 AliWarning(Form("triggerWait not set! default = ", fTriggerWait));
1182         }
1183         tmpStr = anAttribute->GetValue();
1184         fTriggerWait = tmpStr.Atoi();
1185         
1186         anAttribute = anEntry->GetAttribute("mode");
1187         if (!anAttribute) {
1188                 AliWarning("Run mode not set! Running in test mode.");
1189         } else {
1190           tmpStr = anAttribute->GetValue();
1191           if (tmpStr == "test")
1192           {
1193             fRunMode = kTest;
1194           } else if (tmpStr == "prod") {
1195             fRunMode = kProd;
1196           } else {
1197             AliWarning(Form("Not a valid run mode: %s", tmpStr.Data()));                
1198             AliWarning("Valid run modes are \"test\" and \"prod\". Running in test mode.");
1199           }
1200         }
1201
1202         anAttribute = anEntry->GetAttribute("keepDCSMap"); // MAY
1203         if (!anAttribute)
1204         {
1205                 AliWarning("keepDCSMap flag not set - default is FALSE");
1206         } else {
1207                 TString keepDCSMapStr = anAttribute->GetValue();
1208                 if (!(keepDCSMapStr == "0" || keepDCSMapStr == "1"))
1209                 {
1210                         AliError("keepDCSMap flag must be 0 or 1!");
1211                         return 4;
1212                 }
1213                 fKeepDCSMap = (Bool_t) keepDCSMapStr.Atoi();
1214         }
1215         
1216         anAttribute = anEntry->GetAttribute("keepTempFolder"); // MAY
1217         if (!anAttribute)
1218         {
1219                 AliWarning("keepTempFolder flag not set - default is FALSE");
1220         } else {
1221                 TString keepTempFolderStr = anAttribute->GetValue();
1222                 if (!(keepTempFolderStr == "0" || keepTempFolderStr == "1"))
1223                 {
1224                         AliError("keepTempFolder flag must be 0 or 1!");
1225                         return 4;
1226                 }
1227                 fKeepTempFolder = (Bool_t) keepTempFolderStr.Atoi();
1228         }
1229         
1230
1231         anAttribute = anEntry->GetAttribute("shuttleAdmin"); // MAY
1232         if (!anAttribute)
1233         {
1234                 AliDebug(2, "Warning! No \"shuttleAdmin\" attribute!");
1235         }
1236         else
1237         {
1238                 const char* anAdmin;
1239                 while ((anAdmin = anAttribute->GetValue()))
1240                 {
1241                         fAdmin[kGlobal]->AddLast(new TObjString(anAdmin));
1242                 }
1243         }
1244
1245         anAttribute = anEntry->GetAttribute("amandaAdmin"); // MAY
1246         if (!anAttribute)
1247         {
1248                 AliDebug(2, "Warning! No \"amandaAdmin\" attribute!");
1249         }
1250         else
1251         {
1252                 const char* anAdmin;
1253                 while ((anAdmin = anAttribute->GetValue()))
1254                 {
1255                         fAdmin[kAmanda]->AddLast(new TObjString(anAdmin));
1256                 }
1257         }
1258         
1259         anAttribute = anEntry->GetAttribute("sendMail"); // MAY
1260         if (!anAttribute)
1261         {
1262                 AliWarning("sendMail flag not set - default is FALSE");
1263         } else {
1264                 TString sendMailStr = anAttribute->GetValue();
1265                 if (!(sendMailStr == "0" || sendMailStr == "1"))
1266                 {
1267                         AliError("sendMail flag must be 0 or 1!");
1268                         return 4;
1269                 }
1270                 fSendMail = (Bool_t) sendMailStr.Atoi();
1271         }
1272                                                 
1273         anAttribute = anEntry->GetAttribute("passwdFilePath");
1274         if (!anAttribute) {
1275                 AliError("Can't find Passwords File Path attribute!");
1276                 return 4;
1277         }
1278         fPasswdFilePath = anAttribute->GetValue();
1279
1280         return 0;
1281 }
1282
1283 //______________________________________________________________________________________________
1284 UInt_t AliShuttleConfig::SetSysConfig(TList* list)
1285 {
1286         // Set the online FXS configuration (DAQ + DCS + HLT)
1287
1288
1289         TLDAPEntry* anEntry = 0;
1290         TLDAPAttribute* anAttribute = 0;
1291         
1292         if (list->GetEntries() != 3) 
1293         {
1294                 AliError(Form("Wrong number of online systems found: %d !", list->GetEntries()));
1295                 return 1;
1296         } 
1297
1298         TIter iter(list);
1299         Int_t count = 0;
1300         SystemCode iSys=kDAQ;
1301         
1302         while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
1303         {
1304                 anAttribute = anEntry->GetAttribute("system");
1305                 TString sysName = anAttribute->GetValue();
1306                 
1307                 if (sysName == "DAQ") 
1308                 {
1309                         iSys = kDAQ;
1310                         count += 1;
1311                 }
1312                 else if (sysName == "DCS")
1313                 {
1314                         iSys = kDCS;
1315                         count += 10;
1316                 }
1317                 else if (sysName == "HLT")
1318                 {
1319                         iSys = kHLT;
1320                         count += 100;
1321                 }
1322                 
1323                 anAttribute = anEntry->GetAttribute("dbHost");
1324                 if (!anAttribute) {
1325                         AliError(Form ("Can't find dbHost attribute for %s!!",
1326                                                 AliShuttleInterface::GetSystemName(iSys)));
1327                         return 5;
1328                 }
1329                 fFXSdbHost[iSys] = anAttribute->GetValue();
1330
1331                 anAttribute = anEntry->GetAttribute("dbPort"); // MAY
1332                 if (anAttribute)
1333                 {
1334                         fFXSdbPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
1335                 } else {
1336                         fFXSdbPort[iSys] = 3306; // mysql
1337                 }
1338
1339                 anAttribute = anEntry->GetAttribute("dbUser");
1340                 if (!anAttribute) {
1341                         AliError(Form ("Can't find dbUser attribute for %s!!",
1342                                                 AliShuttleInterface::GetSystemName(iSys)));
1343                         return 5;
1344                 }
1345                 fFXSdbUser[iSys] = anAttribute->GetValue();
1346
1347                 anAttribute = anEntry->GetAttribute("dbName");
1348                 if (!anAttribute) {
1349                         AliError(Form ("Can't find dbName attribute for %s!!",
1350                                                 AliShuttleInterface::GetSystemName(iSys)));
1351                         return 5;
1352                 }
1353
1354                 fFXSdbName[iSys] = anAttribute->GetValue();
1355                 anAttribute = anEntry->GetAttribute("dbTable");
1356                 if (!anAttribute) {
1357                         AliError(Form ("Can't find dbTable attribute for %s!!",
1358                                                 AliShuttleInterface::GetSystemName(iSys)));
1359                         return 5;
1360                 }
1361                 fFXSdbTable[iSys] = anAttribute->GetValue();
1362
1363                 anAttribute = anEntry->GetAttribute("fxsHost");
1364                 if (!anAttribute) {
1365                         AliError(Form ("Can't find fxsHost attribute for %s!!",
1366                                                 AliShuttleInterface::GetSystemName(iSys)));
1367                         return 5;
1368                 }
1369                 fFXSHost[iSys] = anAttribute->GetValue();
1370
1371                 anAttribute = anEntry->GetAttribute("fxsPort"); // MAY
1372                 if (anAttribute)
1373                 {
1374                         fFXSPort[iSys] = ((TString) anAttribute->GetValue()).Atoi();
1375                 } else {
1376                         fFXSPort[iSys] = 22; // scp port number
1377                 }
1378
1379                 anAttribute = anEntry->GetAttribute("fxsUser");
1380                 if (!anAttribute) {
1381                         AliError(Form ("Can't find fxsUser attribute for %s!!",
1382                                                 AliShuttleInterface::GetSystemName(iSys)));
1383                         return 5;
1384                 }
1385                 fFXSUser[iSys] = anAttribute->GetValue();
1386
1387                 anAttribute = anEntry->GetAttribute("fxsPasswd");
1388                 if (anAttribute) fFXSPass[iSys] = anAttribute->GetValue();
1389
1390                 anAttribute = anEntry->GetAttribute("fxsBaseFolder");
1391                 if (anAttribute) fFXSBaseFolder[iSys] = anAttribute->GetValue();
1392         
1393                 anAttribute = anEntry->GetAttribute("fxsAdmin"); // MAY
1394                 if (!anAttribute)
1395                 {
1396                         AliDebug(2, "Warning! No \"fxsAdmin\" attribute!");
1397                 }
1398                 else
1399                 {
1400                         const char* anAdmin;
1401                         while ((anAdmin = anAttribute->GetValue()))
1402                         {
1403                                 fAdmin[iSys]->AddLast(new TObjString(anAdmin));
1404                         }
1405                 }
1406         
1407         }
1408         
1409         if(count != 111) {
1410                 AliError(Form("Wrong system configuration! (code = %d)", count));
1411                 return 6;
1412         }
1413         
1414         return 0;
1415 }
1416
1417 //______________________________________________________________________________________________
1418 UInt_t AliShuttleConfig::SetPasswords(){
1419         
1420         AliInfo("Setting Passwords");
1421
1422         // Retrieving Passwords for DAQ lb, DAQ/DCS/HLT FXS
1423
1424         ifstream *inputfile = new ifstream(fPasswdFilePath.Data());
1425         if (!*inputfile) {
1426                 AliError(Form("Error opening file %s !", fPasswdFilePath.Data()));
1427                 inputfile->close();
1428                 delete inputfile;
1429                 return 1;
1430         }
1431
1432         TString line;
1433         Int_t nPwd=0;
1434         Int_t nPwdFake=0;
1435         while (line.ReadLine(*inputfile)) {
1436                 TObjArray *tokens = line.Tokenize(" \t");
1437                 TString system = ((TObjString *)tokens->At(0))->String(); 
1438                 TString password = ((TObjString *)tokens->At(1))->String();
1439                 if (system.Contains("DAQ_LB")){
1440                         fDAQlbPass=password;
1441                         nPwd++;
1442                         AliDebug(3,Form("DAQ_LB: Password %s for %s found", password.Data(), system.Data()));
1443                 }
1444                 else if (system.Contains("DAQ_DB")){
1445                         fFXSdbPass[0]=password;
1446                         nPwd++;
1447                         AliDebug(3,Form("DAQ_DB: Password %s for %s found", password.Data(), system.Data()));
1448                 }
1449                 else if (system.Contains("DCS_DB")){
1450                         fFXSdbPass[1]=password;
1451                         nPwd++;
1452                         AliDebug(3,Form("DCS_DB: Password %s for %s found", password.Data(), system.Data()));
1453                 }
1454                 else if (system.Contains("HLT_DB")){
1455                         fFXSdbPass[2]=password;
1456                         nPwd++;
1457                         AliDebug(3,Form("HLT_DB: Password %s for %s found", password.Data(), system.Data()));
1458                 }
1459                 else {
1460                         nPwdFake++;
1461                         AliDebug(3,Form("%i fake line(s) found in file %s", nPwdFake, fPasswdFilePath.Data()));
1462                         continue;
1463                 }
1464                 delete tokens;
1465         }
1466
1467         inputfile->close();
1468         delete inputfile;
1469
1470         if (nPwd!=4){
1471                 AliError(Form("Wrong file for DAQ Logbook password found %s (some passwors missing), please Check!", fPasswdFilePath.Data()));
1472                 return 2;
1473         }
1474
1475         return 0;
1476
1477 }
1478 //______________________________________________________________________________________________
1479 UInt_t AliShuttleConfig::SetDetConfig(TList* detList, TList* dcsList)
1480 {
1481         // Set the detector configuration (general settings + DCS amanda server and alias/DP lists)
1482
1483         TLDAPEntry* anEntry = 0;
1484         
1485         TIter iter(detList);
1486         while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
1487         {
1488                 
1489                 AliShuttleDetConfigHolder* detHolder = new AliShuttleDetConfigHolder(anEntry);
1490
1491                 if (!detHolder->IsValid()) {
1492                         AliError("Detector configuration error!");
1493                         delete detHolder;
1494                         return 7;
1495                 }
1496
1497                 TObjString* detStr = new TObjString(detHolder->GetDetector());
1498                 
1499                 // Look for DCS Configuration
1500                 TIter dcsIter(dcsList);
1501                 TLDAPEntry *dcsEntry = 0;
1502                 while ((dcsEntry = dynamic_cast<TLDAPEntry*> (dcsIter.Next())))
1503                 {
1504                         TString dn = dcsEntry->GetDn();
1505                         if(dn.Contains(detStr->GetName())) {
1506                                 AliDebug(2, Form("Found DCS configuration: dn = %s",dn.Data()));
1507                                 AliShuttleDCSConfigHolder* dcsHolder = new AliShuttleDCSConfigHolder(dcsEntry);
1508                                 if (!dcsHolder->IsValid()) {
1509                                         AliError("DCS configuration error!");
1510                                         delete detHolder;
1511                                         delete dcsHolder;
1512                                         return 7;
1513                                 }
1514                                 detHolder->AddDCSConfig(dcsHolder);
1515                         }
1516                 }
1517                 
1518                 
1519                 fDetectorMap.Add(detStr, detHolder);
1520                 fDetectorList.AddLast(detStr);
1521         }
1522         
1523         return 0;
1524 }
1525
1526 //______________________________________________________________________________________________
1527 UInt_t AliShuttleConfig::SetHostConfig(TList* list)
1528 {
1529         // Set the Shuttle machines configuration (which detectors processes each machine)
1530         
1531         TLDAPEntry* anEntry = 0;
1532         TLDAPAttribute* anAttribute = 0;
1533         
1534         fShuttleInstanceHost = gSystem->HostName();
1535         
1536         TIter iter(list);
1537         while ((anEntry = dynamic_cast<TLDAPEntry*> (iter.Next())))
1538         {
1539         
1540                 TString dn(anEntry->GetDn());
1541                 if (!dn.Contains(Form("shuttleHost=%s", fShuttleInstanceHost.Data()))) continue;
1542                 
1543                 if (!fProcessAll)
1544                 {
1545                         anAttribute = anEntry->GetAttribute("detectors");
1546                         const char *detName;
1547                         while((detName = anAttribute->GetValue())){
1548                                 TObjString *objDet= new TObjString(detName);
1549                                 fProcessedDetectors.Add(objDet);
1550                         }
1551                 }
1552         }       
1553         
1554         return 0;
1555 }
1556
1557
1558 //______________________________________________________________________________________________
1559 void AliShuttleConfig::Print(Option_t* option) const
1560 {
1561 // print configuration
1562 // options : "": print configuration for all detectors, aliases and DPs in compacted format
1563 //           "uncompact": print configuration for all detectors, aliases and DPs in uncompacted format
1564 //           "DET": print configuration for DET, aliases and DPs in compacted format
1565 //           "DET, uncompact": print configuration for DET, aliases and DPs in uncompacted format
1566
1567         TString result;
1568         result += '\n';
1569         
1570         TString mode = "test";
1571         if (fRunMode == kProd) mode = "production";
1572
1573         result += "########################################################################\n";
1574         result += Form(" Shuttle configuration from %s - Run Mode: <%s> \n", 
1575                                         fConfigHost.Data(), mode.Data());
1576         result += "########################################################################\n";
1577         result += Form("\nShuttle running on %s \n", fShuttleInstanceHost.Data());
1578
1579         if(fProcessAll) {
1580                 result += Form("All detectors will be processed! \n");
1581         } else {
1582                 result += "Detectors processed by this host: ";
1583                 TIter it(&fProcessedDetectors);
1584                 TObjString* aDet;
1585                 while ((aDet = (TObjString*) it.Next())) {
1586                         result += Form("%s ", aDet->String().Data());
1587                 }
1588                 result += "\n";
1589         }
1590
1591         result += Form("PP time out = %d - DCS time out = %d - max PP mem size = %d KB - max retries = %d "
1592                        "- DIM trigger waiting timeout = %d\n", 
1593                                 fPPTimeOut, fDCSTimeOut, fPPMaxMem, fMaxRetries, fTriggerWait);
1594         result += Form("FLAGS: keepDCSMap = %d - keepTempFolder = %d - SendMail = %d \n", 
1595                                 fKeepDCSMap, fKeepTempFolder, fSendMail);
1596         const TObjArray* shuttleAdmins = GetAdmins(kGlobal);
1597         if (shuttleAdmins->GetEntries() != 0)
1598         {
1599                 result += "SHUTTLE administrator(s): ";
1600                 TIter it(shuttleAdmins);
1601                 TObjString* anAdmin;
1602                 while ((anAdmin = (TObjString*) it.Next()))
1603                 {
1604                         result += Form("%s ", anAdmin->String().Data());
1605                 }
1606                 result += "\n";
1607         }
1608         const TObjArray* amandaAdmins = GetAdmins(kAmanda);
1609         if (amandaAdmins->GetEntries() != 0)
1610         {
1611                 result += "Amanda server administrator(s): ";
1612                 TIter it(amandaAdmins);
1613                 TObjString* anAdmin;
1614                 while ((anAdmin = (TObjString*) it.Next()))
1615                 {
1616                         result += Form("%s ", anAdmin->String().Data());
1617                 }
1618                 result += "\n\n";
1619         }
1620         result += "------------------------------------------------------\n";
1621
1622         result += Form("Logbook Configuration \n\n \tHost: %s:%d; \tUser: %s; ",
1623                 fDAQlbHost.Data(), fDAQlbPort, fDAQlbUser.Data());
1624
1625 //      result += "Password: ";
1626 //      result.Append('*', fDAQlbPass.Length());
1627         result += Form("\tDB: %s; \tTables: %s, %s, %s\n",
1628                 fDAQlbDB.Data(), fDAQlbTable.Data(), fShuttlelbTable.Data(), fRunTypelbTable.Data());
1629
1630         result += "\n\n";
1631         
1632         result += "------------------------------------------------------\n";
1633         result += "FXS configuration\n\n";
1634
1635         for(int iSys=0;iSys<3;iSys++){
1636                 result += Form("*** %s ***\n", AliShuttleInterface::GetSystemName(iSys));
1637                 result += Form("\tDB  host: %s:%d; \tUser: %s; \tName: %s; \tTable: %s\n",
1638                                                 fFXSdbHost[iSys].Data(), fFXSdbPort[iSys], fFXSdbUser[iSys].Data(),
1639                                                 fFXSdbName[iSys].Data(), fFXSdbTable[iSys].Data());
1640                 // result += Form("DB Password:",fFXSdbPass[iSys].Data());
1641                 result += Form("\tFXS host: %s:%d; \tUser: %s\n", fFXSHost[iSys].Data(), fFXSPort[iSys],
1642                                                 fFXSUser[iSys].Data());
1643                 // result += Form("FXS Password:",fFXSPass[iSys].Data());
1644                 const TObjArray* fxsAdmins = GetAdmins(iSys);
1645                 if (fxsAdmins->GetEntries() != 0)
1646                 {
1647                         result += "\tAdministrator(s): ";
1648                         TIter it(fxsAdmins);
1649                         TObjString* anAdmin;
1650                         while ((anAdmin = (TObjString*) it.Next()))
1651                         {
1652                                 result += Form("%s ", anAdmin->String().Data());
1653                         }
1654                         result += "\n\n";
1655                 }
1656         }
1657
1658         result += "------------------------------------------------------\n";
1659         result += "MonaLisa configuration\n\n";
1660         
1661         result += Form("\tHost: %s; \tTable name: %s",
1662                 fMonitorHost.Data(), fMonitorTable.Data());
1663                 
1664         result += "\n\n";
1665                 
1666         TString optStr(option);
1667
1668         result += "------------------------------------------------------\n";
1669         result += "Detector-specific configuration\n\n";
1670         
1671         TIter iter(fDetectorMap.GetTable());
1672         TPair* aPair = 0;
1673         
1674         while ((aPair = (TPair*) iter.Next())) {
1675                 AliShuttleDetConfigHolder* aHolder = (AliShuttleDetConfigHolder*) aPair->Value();
1676                 if (optStr != "" && !optStr.Contains(aHolder->GetDetector()) && 
1677                                 optStr.CompareTo("uncompact",TString::kIgnoreCase) != 0 )
1678                                 continue;
1679                 
1680                 result += Form("*** %s *** \n", aHolder->GetDetector());
1681
1682                 const TObjArray* responsibles = aHolder->GetResponsibles();
1683                 if (responsibles->GetEntries() != 0)
1684                 {
1685                         result += "\tDetector responsible(s): ";
1686                         TIter it(responsibles);
1687                         TObjString* aResponsible;
1688                         while ((aResponsible = (TObjString*) it.Next()))
1689                         {
1690                                 result += Form("%s ", aResponsible->String().Data());
1691                         }
1692                         result += "\n";
1693                 }
1694
1695                 result += Form("\tStrict run ordering: %s \n\n", aHolder->StrictRunOrder() ? "YES" : "NO");
1696                 
1697                 const TObjArray* dcsConfig = aHolder->GetDCSConfig();
1698                 
1699                 AliShuttleDCSConfigHolder* dcsHolder = 0;
1700                 TIter dcsIter(dcsConfig);
1701                 Int_t count=0;
1702                 while ((dcsHolder = dynamic_cast<AliShuttleDCSConfigHolder*> (dcsIter.Next())))
1703                 {
1704                         result += Form("\tAmanda server [%d]: %s:%d - MultiSplit = %d\n", count,
1705                                 dcsHolder->GetDCSHost(), dcsHolder->GetDCSPort(), dcsHolder->GetMultiSplit());
1706
1707                         const TObjArray* aliases = 0;
1708                         if (optStr.Contains("uncompact",TString::kIgnoreCase))
1709                         {
1710                                 aliases = dcsHolder->GetDCSAliases();
1711                         } else {
1712                                 aliases = dcsHolder->GetCompactDCSAliases();
1713                         }
1714
1715                         if (aliases->GetEntries() != 0)
1716                         {
1717                                 result += Form("\tDCS Aliases [%d]: ", count);
1718                                 TIter it(aliases);
1719                                 TObjString* anAlias;
1720                                 while ((anAlias = (TObjString*) it.Next()))
1721                                 {
1722                                         result += Form("%s ", anAlias->String().Data());
1723                                 }
1724                                 result += "\n";
1725                         }
1726
1727                         const TObjArray* dataPoints = 0;
1728                         if (optStr.Contains("uncompact",TString::kIgnoreCase))
1729                         {
1730                                 dataPoints = dcsHolder->GetDCSDataPoints();
1731                         } else {
1732                                 dataPoints = dcsHolder->GetCompactDCSDataPoints();
1733                         }
1734                         if (dataPoints->GetEntries() != 0)
1735                         {
1736                                 result += Form("\tDCS Data Points [%d]: ", count);
1737                                 TIter it(dataPoints);
1738                                 TObjString* aDataPoint;
1739                                 while ((aDataPoint = (TObjString*) it.Next())) {
1740                                         result += Form("%s ", aDataPoint->String().Data());
1741                                 }
1742                                 result += "\n";
1743                         }
1744                         count++;
1745                         result += "\n";
1746                 }
1747         }
1748         if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
1749
1750         AliInfo(result);
1751 }