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