]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/AvailableSoftware.C
Merge remote-tracking branch 'origin/flatdev' into mergeFlat2Master
[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, Bool_t debug=false)
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     Bool_t show = (aliroot.Contains("list", TString::kIgnoreCase) ||
40                    root.Contains(   "list", TString::kIgnoreCase));
41     Bool_t last = (aliroot.Contains("last", TString::kIgnoreCase) || 
42                    aliroot.Contains("newest", TString::kIgnoreCase));
43     Bool_t nots = (aliroot.Contains("nonspecial", TString::kIgnoreCase) ||
44                    aliroot.Contains("regular",    TString::kIgnoreCase) ||
45                    aliroot.Contains("standard",   TString::kIgnoreCase));
46     Bool_t rele = (aliroot.Contains("release",    TString::kIgnoreCase));
47     Bool_t anat = (aliroot.Contains("analysis",   TString::kIgnoreCase));
48     
49     TString c("wget -q http://alimonitor.cern.ch/packages/ -O - | "
50               "sed -n -e '/<tr/,/<\\/tr>/ p' | ");
51     if (rele || anat || nots) {
52       c.Append("sed -n '/<a.*VO_ALICE@AliRoot::v[0-9]\\{1,\\}-[0-9]\\{1,\\}-");
53       if (rele)
54         c.Append("Rev-[0-9]\\{1,\\}");
55       else if (anat) 
56         c.Append("[0-9]\\{1,\\}-AN");
57       else if (nots) 
58         c.Append("\\([0-9]\\{1,\\}\\|Rev\\)-\\(AN\\|[0-9]\\{1,\\}\\)");
59       c.Append("/,/VO_ALICE@ROOT::/ p' | ");
60     }
61     else 
62       c.Append("sed -n '/<a.*VO_ALICE@AliRoot::/,/VO_ALICE@ROOT::/ p' | ");
63     
64     c.Append("sed -n -e 's/.*VO_ALICE@AliRoot::\\([-0-9a-zA-Z]*\\).*/%\\1%/p' "
65              "  -e 's/.*VO_ALICE@ROOT::\\([-0-9a-zA-Z]*\\).*/\\1@/p' | "
66              "tr -d '\\n' | tr '@' '\\n' | tr '%' '\\t' ");
67     
68     if (debug) 
69       Printf("Command: %s", c.Data());
70
71     if (show || aliroot.IsNull()) {
72       Warning("AvaliableSoftware::Check", "No AliROOT/ROOT version specified, "
73               "available packages are:\n" 
74               "\tAliROOT \tROOT:");
75       gSystem->Exec(c);
76       return false;
77     }
78
79     if (last) 
80       mode |= 0x2;
81     else if (!aliroot.IsNull()) 
82       mode |= 0x4; 
83
84     // Nothing to do 
85     if (mode == 0) return true; 
86     
87     if (debug) Printf("Mode=0x%02x", mode);
88
89     TString    values = gSystem->GetFromPipe(c);
90     TObjArray* tokens = values.Tokenize(" \t\n");
91     Int_t      n      = tokens->GetEntries();
92
93     // If we asked to select the last possible version, do so here and get out
94     if (mode & 0x2) { 
95       aliroot = tokens->At(n-2)->GetName();
96       root    = tokens->At(n-1)->GetName();
97       Info("AvaliableSoftware::Check", 
98            "Selecting lastest possible AliROOT/ROOT: %s/%s", 
99            aliroot.Data(), root.Data());
100       delete tokens;
101       return true;
102     }
103     
104     // We get here if we're asked to find a ROOT version compatible
105     // with the selected AliROOT version. 
106     for (Int_t i = 0; i < n; i += 2) {
107       if (aliroot.EqualTo(tokens->At(i)->GetName(), 
108                                   TString::kIgnoreCase)) { 
109         root = tokens->At(i+1)->GetName();
110         Info("AvaliableSoftware::Check",
111              "Found ROOT version compatible with AliROOT %s: %s",
112              aliroot.Data(), root.Data());
113         delete tokens;
114         return true;
115       }
116     }
117     // If we get here, then we didn't find a ROOT version compatible
118     // with the selected AliROOT, and we should fail. 
119     Warning("AvaliableSoftware::Check",
120             "Didn't find a ROOT version compatible with AliROOT %s", 
121             aliroot.Data());
122     delete tokens; 
123     return false;
124   }
125   static void Test(const TString& ali, const TString& roo=TString())
126   {
127     TString aliroot(Form("list,%s",ali.Data()));
128     TString root(roo);
129     Printf("Checking with AliROOT=%s ROOT=%s", ali.Data(), roo.Data());
130     AvailableSoftware::Check(aliroot, root);
131
132     aliroot = Form("last,%s",ali.Data());
133     AvailableSoftware::Check(aliroot, root);
134     Printf("Got AliROOT=%s ROOT=%s", aliroot.Data(), root.Data());
135   }
136     
137   static void Test()
138   {
139     Printf("All available");
140     AvailableSoftware::Test("");
141     Printf("All regular");
142     AvailableSoftware::Test("regular");
143     Printf("All releases");
144     AvailableSoftware::Test("release");
145     Printf("All analysis tags");
146     AvailableSoftware::Test("analysis");
147   }
148 };
149 #endif