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