2 * @file AvailableSoftware.C
3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Tue Oct 16 17:54:11 2012
6 * @brief Find available packages
8 * @ingroup pwglf_forward_trains_util
11 #ifndef AVAILABLESOFTWARE_C
12 #define AVAILABLESOFTWARE_C
17 # include <TObjArray.h>
23 * Helper code to find available packages on Grid
26 * @ingroup pwglf_forward_trains_util
28 struct AvailableSoftware
30 static Bool_t Check(TString& aliroot, TString& root, Bool_t debug=false)
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
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));
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,\\}-");
54 c.Append("Rev-[0-9]\\{1,\\}");
56 c.Append("[0-9]\\{1,\\}-AN");
58 c.Append("\\([0-9]\\{1,\\}\\|Rev\\)-\\(AN\\|[0-9]\\{1,\\}\\)");
59 c.Append("/,/VO_ALICE@ROOT::/ p' | ");
62 c.Append("sed -n '/<a.*VO_ALICE@AliRoot::/,/VO_ALICE@ROOT::/ p' | ");
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' ");
69 Printf("Command: %s", c.Data());
71 if (show || aliroot.IsNull()) {
72 Warning("AvaliableSoftware::Check", "No AliROOT/ROOT version specified, "
73 "available packages are:\n"
81 else if (!aliroot.IsNull())
85 if (mode == 0) return true;
87 if (debug) Printf("Mode=0x%02x", mode);
89 TString values = gSystem->GetFromPipe(c);
90 TObjArray* tokens = values.Tokenize(" \t\n");
91 Int_t n = tokens->GetEntries();
93 // If we asked to select the last possible version, do so here and get out
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());
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());
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",
125 static void Test(const TString& ali, const TString& roo=TString())
127 TString aliroot(Form("list,%s",ali.Data()));
129 Printf("Checking with AliROOT=%s ROOT=%s", ali.Data(), roo.Data());
130 AvailableSoftware::Check(aliroot, root);
132 aliroot = Form("last,%s",ali.Data());
133 AvailableSoftware::Check(aliroot, root);
134 Printf("Got AliROOT=%s ROOT=%s", aliroot.Data(), root.Data());
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");