]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/AvailableSoftware.C
28ea49af8cdbc6fc2fbabcd6cbd11f25f75fc0e8
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / AvailableSoftware.C
1 /**
2  * @file   AvailableSoftware.C
3  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4  * @date   Tue Oct 16 17:54:11 2012
5  * 
6  * @brief  Find available packages
7  * 
8  * @ingroup pwglf_forward_trains_util
9  */
10
11 #ifndef AVAILABLESOFTWARE_C
12 #define AVAILABLESOFTWARE_C
13 #ifndef __CINT__
14 # include <TString.h>
15 # include <TSystem.h>
16 # include <TError.h>
17 # include <TObjArray.h>
18 #else
19 class TString;
20 #endif
21
22 /**
23  * Helper code to find available packages on Grid
24  * 
25  *
26  * @ingroup pwglf_forward_trains_util
27  */
28 struct AvailableSoftware
29 {
30   static Bool_t Check(TString& aliroot, TString& root)
31   {
32     // Figure out what to do.  
33     // If mode == 0, then do nothing. 
34     // If bit 0 is set in mode (0x1), then list and exit 
35     // If bit 1 is set in mode (0x2), select last AliROOT/ROOT version 
36     // If bit 2 is set in mode (0x4), select ROOT corresponding to AliROOT
37     UShort_t mode = 0; 
38
39     TString c("wget -q http://alimonitor.cern.ch/packages/ -O - | "
40               "sed -n -e '/<tr/,/<\\/tr>/ p' | "
41               "sed -n '/<a.*VO_ALICE@AliRoot::/,/VO_ALICE@ROOT::/ p' | "
42               "sed -n -e 's/.*VO_ALICE@AliRoot::\\([-0-9a-zA-Z]*\\).*/%\\1%/p' "
43               "  -e 's/.*VO_ALICE@ROOT::\\([-0-9a-zA-Z]*\\).*/\\1@/p' | "
44               "tr -d '\\n' | tr '@' '\\n' | tr '%' '\\t' ");
45
46     if (aliroot.EqualTo("list", TString::kIgnoreCase) ||
47         root.EqualTo("list", TString::kIgnoreCase) || 
48         aliroot.IsNull()) {
49       Warning("AvaliableSoftware::Check", "No AliROOT/ROOT version specified, "
50               "available packages are:\n" 
51               "\tAliROOT \tROOT:");
52       gSystem->Exec(c);
53       return false;
54     }
55
56     if (aliroot.EqualTo("last", TString::kIgnoreCase)) 
57       mode |= 0x2;
58     else if (!aliroot.IsNull()) 
59       mode |= 0x4; 
60
61     // Nothing to do 
62     if (mode == 0) return true; 
63     
64
65     TString    values = gSystem->GetFromPipe(c);
66     TObjArray* tokens = values.Tokenize(" \t\n");
67     Int_t      n      = tokens->GetEntries();
68
69     // If we asked to select the last possible version, do so here and get out
70     if (mode & 0x2) { 
71       aliroot = tokens->At(n-2)->GetName();
72       root    = tokens->At(n-1)->GetName();
73       Info("AvaliableSoftware::Check", 
74            "Selecting lastest possible AliROOT/ROOT: %s/%s", 
75            aliroot.Data(), root.Data());
76       delete tokens;
77       return true;
78     }
79     
80     // We get here if we're asked to find a ROOT version compatible
81     // with the selected AliROOT version. 
82     for (Int_t i = 0; i < n; i += 2) {
83       if (aliroot.EqualTo(tokens->At(i)->GetName(), 
84                                   TString::kIgnoreCase)) { 
85         root = tokens->At(i+1)->GetName();
86         Info("AvaliableSoftware::Check",
87              "Found ROOT version compatible with AliROOT %s: %s",
88              aliroot.Data(), root.Data());
89         delete tokens;
90         return true;
91       }
92     }
93     // If we get here, then we didn't find a ROOT version compatible
94     // with the selected AliROOT, and we should fail. 
95     Warning("AvaliableSoftware::Check",
96             "Didn't find a ROOT version compatible with AliROOT %s", 
97             aliroot.Data());
98     delete tokens; 
99     return false;
100   }
101 };
102 #endif