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