]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleConfig.cxx
introducing status management: The processing per subdetector is divided into several...
[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.6  2006/07/19 10:09:55  jgrosseo
19 new configuration, accesst to DAQ FES (Alberto)
20
21 Revision 1.5  2006/07/10 13:01:41  jgrosseo
22 enhanced storing of last sucessfully processed run (alberto)
23
24 Revision 1.4  2006/06/12 09:11:16  jgrosseo
25 coding conventions (Alberto)
26
27 Revision 1.3  2006/06/06 14:26:40  jgrosseo
28 o) removed files that were moved to STEER
29 o) shuttle updated to follow the new interface (Alberto)
30
31 Revision 1.7  2006/05/12 09:07:16  colla
32 12/05/06
33 New configuration complete
34
35 Revision 1.2  2006/03/07 07:52:34  hristov
36 New version (B.Yordanov)
37
38 Revision 1.4  2005/11/19 14:20:31  byordano
39 logbook config added to AliShuttleConfig
40
41 Revision 1.3  2005/11/17 19:24:25  byordano
42 TList changed to TObjArray in AliShuttleConfig
43
44 Revision 1.2  2005/11/17 14:43:23  byordano
45 import to local CVS
46
47 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
48 Initial import as subdirectory in AliRoot
49
50 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
51 SHUTTLE package
52
53 Revision 1.3  2005/08/30 09:13:02  byordano
54 some docs added
55
56 */
57
58
59 //
60 // This class keeps the AliShuttle configuration.
61 // It reads the configuration for LDAP server.
62 // For every child entry in basedn which has schema type 'shuttleConfig'
63 // it creates a detector configuration. This configuration includes:
64 // DCS server host and port and the set of aliases for which data from
65 // will be retrieved (used by AliShuttle).
66 //
67
68
69 #include "AliShuttleConfig.h"
70 #include "AliShuttleInterface.h"
71
72 #include "AliLog.h"
73
74 #include <TSystem.h>
75 #include <TObjString.h>
76 #include <TLDAPResult.h>
77 #include <TLDAPEntry.h>
78 #include <TLDAPAttribute.h>
79
80
81 AliShuttleConfig::AliShuttleConfigHolder::AliShuttleConfigHolder(const TLDAPEntry* entry):
82 fDetector(""),
83 fDCSHost(""),
84 fDCSPort(0),
85 fDCSAliases(),
86 fIsValid(kFALSE),
87 fSkipDCSQuery(kFALSE)
88 {
89 // constructor of the shuttle configuration holder
90
91         TLDAPAttribute* anAttribute;
92
93         anAttribute = entry->GetAttribute("det"); // MUST
94         fDetector = anAttribute->GetValue();
95
96         anAttribute = entry->GetAttribute("DCSHost"); // MAY
97         if (!anAttribute) {
98                 AliWarning(
99                         Form("%s has not DCS host entry - Shuttle will skip DCS data query!",
100                                 fDetector.Data()));
101                 fIsValid = kTRUE;
102                 fSkipDCSQuery = kTRUE;
103                 return;
104         }
105
106         fDCSHost = anAttribute->GetValue();
107
108         anAttribute = entry->GetAttribute("DCSPort"); // MAY
109         if (!anAttribute) {
110                 AliError(Form("Invalid configuration! %s has DCS Host but no port number!",
111                                 fDetector.Data()));
112                 return;
113         }
114         TString portStr = anAttribute->GetValue();
115         fDCSPort = portStr.Atoi();
116
117         anAttribute = entry->GetAttribute("DCSAlias"); // MAY
118         if (!anAttribute) {
119                 AliError(Form("Invalid configuration! %s has DCS host settings but no DCSAlias entries!",
120                                 fDetector.Data()));
121                 return;
122         }
123
124         const char* anAlias;
125         while ((anAlias = anAttribute->GetValue())) {
126                 fDCSAliases.AddLast(new TObjString(anAlias));
127         }
128
129         fIsValid = kTRUE;
130
131
132 }
133
134 //______________________________________________________________________________________________
135 AliShuttleConfig::AliShuttleConfigHolder::~AliShuttleConfigHolder()
136 {
137 // destructor of the shuttle configuration holder
138
139         fDCSAliases.Delete();
140 }
141
142 ClassImp(AliShuttleConfig)
143
144 //______________________________________________________________________________________________
145 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
146         const char* binddn, const char* password, const char* basedn):
147         fIsValid(kFALSE),
148         fProcessAll(kFALSE)
149 {
150         //
151         // host: ldap server host
152         // port: ldap server port
153         // binddn: binddn used for ldap binding (simple bind is used!).
154         // password: password for binddn
155         // basedn: this is basedn whose childeren entries which have
156         // (objectClass=shuttleConfig) will be used as detector configurations.
157         //
158
159         TLDAPServer aServer(host, port, binddn, password, 3);
160
161         if (!aServer.IsConnected()) {
162                 AliError(Form("Can't connect to ldap server %s:%d", 
163                                 host, port));
164                 return;
165         }
166
167         // reads configuration for the shuttle running on this machine
168         
169         fShuttleInstanceHost = gSystem->HostName();
170         TString queryFilter = "(ShuttleHost=";
171         queryFilter += fShuttleInstanceHost;
172         queryFilter += ")";     
173         
174         TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
175                         queryFilter.Data());
176
177         if (!aResult) {
178                 AliError(Form("Can't find configuration with base DN: %s",
179                                 basedn));
180                 return;
181         }
182
183         if (aResult->GetCount() == 0) {
184                 AliError(Form("No Shuttle instance for host = %s!",
185                                         fShuttleInstanceHost.Data()));
186                 AliError(Form("All detectors will be processed."));
187                 fProcessAll=kTRUE;
188         }
189
190         if (aResult->GetCount() > 1) {
191                 AliError(Form("More than one Shuttle instance for host %s!",
192                                         fShuttleInstanceHost.Data()));
193                 return;
194         }
195
196         TLDAPEntry* anEntry;
197         TLDAPAttribute* anAttribute;
198
199         if(!fProcessAll){
200                 anEntry = aResult->GetNext();
201                 anAttribute = anEntry->GetAttribute("detectors");
202                 const char *detName;
203                 while((detName = anAttribute->GetValue())){
204                         TObjString *objDet= new TObjString(detName);
205                         fProcessedDetectors.Add(objDet);
206                 }
207         }
208
209         // Detector configuration (DCS Archive DB settings)
210
211         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
212                         "(objectClass=AliShuttleDetector)");
213         if (!aResult) {
214                 AliError(Form("Can't find configuration with base DN: %s",
215                                 basedn));
216                 return;
217         }
218
219
220         while ((anEntry = aResult->GetNext())) {
221                 AliShuttleConfigHolder* aHolder = new AliShuttleConfigHolder(anEntry);
222                 delete anEntry;
223
224                 if (!aHolder->IsValid()) {
225                         AliError("Detector configuration error!");
226                         delete aHolder;
227                         return;
228                 }
229
230                 TObjString* detStr = new TObjString(aHolder->GetDetector());
231                 fDetectorMap.Add(detStr, aHolder);
232                 fDetectorList.AddLast(detStr);
233         }
234
235         delete aResult;
236
237         // Global configuration (DAQ logbook)
238
239         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
240                         "(objectClass=AliShuttleGlobalConfig)");
241         if (!aResult) {
242                 AliError(Form("Can't find configuration with base DN: %s",
243                                 basedn));
244                 return;
245         }
246
247         if (aResult->GetCount() == 0) {
248                 AliError("Can't find DAQ logbook configuration!");
249                 return;
250         }
251
252         if (aResult->GetCount() > 1) {
253                 AliError("More than one DAQ logbook configuration found!");
254                 return;
255         }
256
257         anEntry = aResult->GetNext();
258
259         anAttribute = anEntry->GetAttribute("DAQLogbookHost");
260         if (!anAttribute) {
261                 AliError("Can't find DAQLogbookHost attribute!");
262                 return;
263         }
264         fDAQlbHost = anAttribute->GetValue();
265
266         anAttribute = anEntry->GetAttribute("DAQLogbookUser");
267         if (!anAttribute) {
268                 AliError("Can't find DAQLogbookUser attribute!");
269                 return;
270         }
271         fDAQlbUser = anAttribute->GetValue();
272
273         anAttribute = anEntry->GetAttribute("DAQLogbookPassword");
274         if (!anAttribute) {
275                 AliError("Can't find DAQLogbookPassword attribute!");
276                 return;
277         }
278         fDAQlbPass = anAttribute->GetValue();
279
280         anAttribute = anEntry->GetAttribute("MaxPPRetries");
281         if (!anAttribute) {
282                 AliError("Can't find MaxPPRetries attribute!");
283                 return;
284         }
285         TString tmpStr = anAttribute->GetValue();
286   fMaxPPRetries = tmpStr.Atoi();
287
288         anAttribute = anEntry->GetAttribute("MaxRetries");
289         if (!anAttribute) {
290                 AliError("Can't find MaxRetries attribute!");
291                 return;
292         }
293         tmpStr = anAttribute->GetValue();
294   fMaxRetries = tmpStr.Atoi();
295
296   delete anEntry;
297         delete aResult;
298
299         // FES configuration (FES logbook and hosts)
300
301
302         for(int iSys=0;iSys<3;iSys++){
303                 queryFilter = Form("(system=%s)", AliShuttleInterface::fkSystemNames[iSys]);
304                 aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
305                 if (!aResult) {
306                         AliError(Form("Can't find configuration for system: %s",
307                                         AliShuttleInterface::fkSystemNames[iSys]));
308                         return;
309                 }
310
311                 if (aResult->GetCount() != 1 ) {
312                         AliError("Error in FES configuration!");
313                         return;
314                 }
315
316                 anEntry = aResult->GetNext();
317
318                 anAttribute = anEntry->GetAttribute("LogbookHost");
319                 if (!anAttribute) {
320                         AliError(Form ("Can't find LogbookHost attribute for %s!!",
321                                                 AliShuttleInterface::fkSystemNames[iSys]));
322                         return;
323                 }
324                 fFESlbHost[iSys] = anAttribute->GetValue();
325
326                 anAttribute = anEntry->GetAttribute("LogbookUser");
327                 if (!anAttribute) {
328                         AliError(Form ("Can't find LogbookUser attribute for %s!!",
329                                                 AliShuttleInterface::fkSystemNames[iSys]));
330                         return;
331                 }
332                 fFESlbUser[iSys] = anAttribute->GetValue();
333
334                 anAttribute = anEntry->GetAttribute("LogbookPassword");
335                 if (!anAttribute) {
336                         AliError(Form ("Can't find LogbookPassword attribute for %s!!",
337                                                 AliShuttleInterface::fkSystemNames[iSys]));
338                         return;
339                 }
340                 fFESlbPass[iSys] = anAttribute->GetValue();
341
342                 anAttribute = anEntry->GetAttribute("FSHost");
343                 if (!anAttribute) {
344                         AliError(Form ("Can't find FSHost attribute for %s!!",
345                                                 AliShuttleInterface::fkSystemNames[iSys]));
346                         return;
347                 }
348                 fFESHost[iSys] = anAttribute->GetValue();
349
350                 anAttribute = anEntry->GetAttribute("FSUser");
351                 if (!anAttribute) {
352                         AliError(Form ("Can't find FSUser attribute for %s!!",
353                                                 AliShuttleInterface::fkSystemNames[iSys]));
354                         return;
355                 }
356                 fFESUser[iSys] = anAttribute->GetValue();
357
358                 anAttribute = anEntry->GetAttribute("FSPassword");
359                 if (anAttribute) fFESPass[iSys] = anAttribute->GetValue();
360
361                 delete anEntry;
362                 delete aResult;
363         }
364
365         fIsValid = kTRUE;
366 }
367
368 //______________________________________________________________________________________________
369 AliShuttleConfig::~AliShuttleConfig()
370 {
371 // destructor
372
373         fDetectorMap.DeleteAll();
374 }
375
376 //______________________________________________________________________________________________
377 const TObjArray* AliShuttleConfig::GetDetectors() const
378 {
379         //
380         // returns collection of TObjString which contains the name
381         // of every detector which is in the configuration.
382         //
383
384         return &fDetectorList;
385 }
386
387 //______________________________________________________________________________________________
388 Bool_t AliShuttleConfig::HasDetector(const char* detector) const
389 {
390         //
391         // checks for paricular detector in the configuration.
392         //
393         return fDetectorMap.GetValue(detector) != NULL;
394 }
395
396 //______________________________________________________________________________________________
397 const char* AliShuttleConfig::GetDCSHost(const char* detector) const
398 {
399         //
400         // returns DCS server host used by particular detector
401         //
402         
403         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
404         if (!aHolder) {
405                 AliError(Form("There isn't configuration for detector: %s",
406                         detector));
407                 return NULL;
408         }
409
410         return aHolder->GetDCSHost();
411 }
412
413 //______________________________________________________________________________________________
414 Int_t AliShuttleConfig::GetDCSPort(const char* detector) const
415 {
416         //
417         // returns DCS server port used by particular detector
418         //
419
420
421         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
422         if (!aHolder) {
423                 AliError(Form("There isn't configuration for detector: %s",
424                         detector));
425                 return 0;
426         }
427
428         return aHolder->GetDCSPort();
429 }
430
431 //______________________________________________________________________________________________
432 const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector) const
433 {
434         //
435         // returns collection of TObjString which represents the set of aliases
436         // which used for data retrieval for particular detector
437         //
438
439         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
440         if (!aHolder) {
441                 AliError(Form("There isn't configuration for detector: %s",
442                         detector));
443                 return NULL;
444         }
445
446         return aHolder->GetDCSAliases();
447 }
448
449 //______________________________________________________________________________________________
450 Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
451 {
452         // return TRUE if detector is handled by host or if fProcessAll is TRUE
453
454         if(fProcessAll) return kTRUE;
455         TIter iter(&fProcessedDetectors);
456         TObjString* detName;
457         while((detName = (TObjString*) iter.Next())){
458                 if(detName->String() == detector) return kTRUE;
459         }
460         return kFALSE;
461 }
462
463 //______________________________________________________________________________________________
464 void AliShuttleConfig::Print(Option_t* /*option*/) const
465 {
466 // print configuration
467         
468         TString result;
469         result += '\n';
470
471         result += Form("\nShuttle running on %s \n\n", fShuttleInstanceHost.Data());
472
473         if(fProcessAll) {
474                 result += Form("All detectors will be processed! \n\n");
475         } else {
476                 result += "Detectors processed by this host: ";
477                 TIter it(&fProcessedDetectors);
478                 TObjString* aDet;
479                 while ((aDet = (TObjString*) it.Next())) {
480                         result += Form("%s ", aDet->String().Data());
481                 }
482                 result += "\n\n";
483         }
484
485         result += Form("DAQ Logbook Configuration \n \tHost: %s - User: %s - ",
486                 fDAQlbHost.Data(), fDAQlbUser.Data());
487
488         result += "Password: ";
489         result.Append('*', fDAQlbPass.Length());
490         result += "\n\n";
491
492         for(int iSys=0;iSys<3;iSys++){
493                 result += Form("FES Configuration for %s system\n", AliShuttleInterface::fkSystemNames[iSys]);
494                 result += Form("\tLogbook host: \t%s - \tUser: %s\n",
495                                                 fFESlbHost[iSys].Data(), fFESlbUser[iSys].Data());
496                 // result += Form("Logbook Password:",fFESlbPass[iSys].Data());
497                 result += Form("\tFES host: \t%s - \tUser: %s\n\n", fFESHost[iSys].Data(), fFESUser[iSys].Data());
498                 // result += Form("FES Password:",fFESPass[iSys].Data());
499         }
500
501         TIter iter(fDetectorMap.GetTable());
502         TPair* aPair;
503         while ((aPair = (TPair*) iter.Next())) {
504                 AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) aPair->Value();
505                 if(aHolder->SkipDCSQuery()) continue;
506                 result += Form("DCS archive DB configuration for *** %s *** \n", aHolder->GetDetector());
507                 result += Form("\tAmanda server: %s:%d \n", aHolder->GetDCSHost(), aHolder->GetDCSPort());
508
509                 result += "\tDCS Aliases: ";
510                 const TObjArray* aliases = aHolder->GetDCSAliases();
511                 TIter it(aliases);
512                 TObjString* anAlias;
513                 while ((anAlias = (TObjString*) it.Next())) {
514                         result += Form("%s ", anAlias->String().Data());
515                 }
516
517                 result += "\n\n";
518
519         }
520
521         if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
522
523         AliInfo(result);
524 }