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)
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 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' ");
46 if (aliroot.EqualTo("list", TString::kIgnoreCase) ||
47 root.EqualTo("list", TString::kIgnoreCase) ||
49 Warning("AvaliableSoftware::Check", "No AliROOT/ROOT version specified, "
50 "available packages are:\n"
56 if (aliroot.EqualTo("last", TString::kIgnoreCase))
58 else if (!aliroot.IsNull())
62 if (mode == 0) return true;
65 TString values = gSystem->GetFromPipe(c);
66 TObjArray* tokens = values.Tokenize(" \t\n");
67 Int_t n = tokens->GetEntries();
69 // If we asked to select the last possible version, do so here and get out
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());
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());
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",