AliPhysics  cda3415 (cda3415)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AvailableSoftware.C
Go to the documentation of this file.
1 
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 # include <TList.h>
19 # include <TPRegexp.h>
20 # include <TObjString.h>
21 # include <fstream>
22 #else
23 class TString;
24 class TList;
25 #endif
26 
34 {
35  static const char* GetField(TObject* o)
36  {
37  static TString r;
38  if (!o) return "";
39  TString s(o->GetName());
40  TString t = s.Strip(TString::kBoth,' ');
41  r = t.Strip(TString::kBoth, '\t');
42  return r.Data();
43  }
49  static TList* GetMap()
50  {
51  static TList l;
52  if (l.GetEntries() > 0) return &l;
53  TString c("wget -q http://alimonitor.cern.ch/packages/ -O - | "
54  "sed -n -e '/<tr class=table_row/,/<\\/tr>/ p' | "
55  "sed -n -e '/<td/,/<\\/td>/ p' | "
56  "sed -e '/\\/*td.*>/d' | "
57  "sed -e 's/<a.*>\\(.*\\)<\\/a>/\\1/'");
58  TString values = gSystem->GetFromPipe(c);
59  TObjArray* tokens = values.Tokenize("\n");
60  Int_t n = tokens->GetEntries();
61  std::ofstream out("values");
62  out << values << std::endl;
63  out.close();
64  // Printf("%s", values.Data());
65  // tokens->ls();
66  for (Int_t i = 0; i < n; i += 1) { // 2-3 lines per package
67  TObject* opack = tokens->At(i+0);
68  TString pack = GetField(opack);
69  if (pack.IsNull()) {
70  i += 2;
71  continue;
72  }
73  TObjString* odeps = static_cast<TObjString*>(tokens->At(i+1));
74  TObjString* oblank= static_cast<TObjString*>(tokens->At(i+2));
75  TObjString* oavail= static_cast<TObjString*>(tokens->At(i+3));
76  TObjString* odate = static_cast<TObjString*>(tokens->At(i+4));
77  i += 4;
78  if (oblank) {
79  TString blk = GetField(oblank);
80  if (!blk.IsNull())
81  ::Warning("", "blanck is not blanck: \"%s\"", oblank->GetName());
82  }
83  if (oavail) {
84  TString avail = GetField(oavail);
85  if (!avail.EqualTo("Available")) continue;
86  }
87 
88  // TString& pack = opack->String();
89  pack.ReplaceAll("VO_ALICE@", "");
90 
91  // TString& deps = odeps->String();
92  TString deps = GetField(odeps);
93  deps.ReplaceAll("VO_ALICE@", "");
94  if (!(pack.BeginsWith("AliPhysics") ||
95  pack.BeginsWith("AliRoot") ||
96  pack.BeginsWith("ROOT"))) continue;
97  if (pack.Contains(".post_install")) continue;
98 
99  l.Add(new TNamed(pack, deps));
100  // Printf("%-30s: %s", pack.Data(), deps.Data());
101  }
102  l.Sort();
103  // l.ls();
104  tokens->Delete();
105  delete tokens;
106 
107  return &l;
108  }
122  static TObject* GetPackage(const TString& name,
123  const TString& query)
124  {
125  TList* l = GetMap();
126  Bool_t list = (query.Contains("list", TString::kIgnoreCase) ||
127  query.Contains("help", TString::kIgnoreCase));
128  Bool_t last = (query.Contains("last", TString::kIgnoreCase) ||
129  query.Contains("newest", TString::kIgnoreCase));
130  Bool_t nots = (query.Contains("nonspecial", TString::kIgnoreCase) ||
131  query.Contains("regular", TString::kIgnoreCase) ||
132  query.Contains("normal", TString::kIgnoreCase) ||
133  query.Contains("standard", TString::kIgnoreCase));
134  Bool_t rele = (query.Contains("release", TString::kIgnoreCase));
135  Bool_t anat = (query.Contains("analysis", TString::kIgnoreCase));
136  if (!query.IsNull() && (!list && !last && !nots && !rele && !anat)) {
137  Info("GetPackage", "%s=%s already specified, leaving that",
138  name.Data(), query.Data());
139  TObject* o = l->FindObject(Form("%s::%s",name.Data(),query.Data()));
140  return o;
141  }
142 
143  TString relPat;
144  relPat.Form("%s::v[0-9]-[0-9]{2}+-(Rev-|)[0-9]{2}", name.Data());
145  if (name.Contains("AliPhysics")) relPat.Append("-[0-9]{2}");
146  if (name.Contains("ROOT")) relPat.Append("(-alice[0-9]*|)");
147  relPat.Append("(-[0-9]+|)$");
148  TPRegexp pRele(relPat);
149  TPRegexp pAnat(Form("%s::vAN-[0-9]{8}(-[0-9]+|)$", name.Data()));
150  TString vers(Form("%s::%s", name.Data(), query.Data()));
151 
152  if (list) {
153  TString qual;
154  if (nots) qual.Append("regular ");
155  if (rele) qual.Append("release ");
156  if (anat) qual.Append("analysis ");
157 
158  Printf("Available %sversion of %s", qual.Data(), name.Data());
159  }
160  TIter prev(l, kIterBackward);
161  TObject* o = 0;
162  TObject* r = 0;
163  Bool_t m = false;
164  while ((o = prev())) {
165  TString n(o->GetName());
166  if (!n.BeginsWith(name)) {
167  if (m) break;
168  continue;
169  }
170 
171  // We found the package
172  m = true;
173 
174  if (last || list) {
175  Bool_t isRele = pRele.MatchB(n);
176  Bool_t isAnat = pAnat.MatchB(n);
177  Bool_t isSpec = !(isRele || isAnat);
178  if (nots && isSpec) continue;
179  if (anat && !isAnat) continue;
180  if (rele && !isRele) continue;
181  if (list) {
182  n.ReplaceAll(Form("%s::", name.Data()), "");
183  Printf("\t%s", n.Data());
184  continue;
185  }
186  r = o;
187  break;
188  }
189  if (!vers.EqualTo(n)) continue;
190  r = o;
191  break;
192  }
193  if (!r && !list)
194  Warning("GetPackage", "No match found for %s", vers.Data());
195  return r;
196  }
197  static Bool_t GetVer(TObject* pack, const TString& name, TString& ret)
198  {
199  if (!pack) {
200  // if (!ret.IsNull()) ret = "";
201  return false;
202  }
203 
204  ret = pack->GetName();
205  ret.ReplaceAll(Form("%s::", name.Data()), "");
206  return true;
207  }
208 
218  static Bool_t GetDep(TObject* pack, const TString& which, TString& ret)
219  {
220  if (!pack) return false;
221  TString deps(pack->GetTitle());
222  TObjArray* tokens = deps.Tokenize(",");
223  TIter next(tokens);
224  TObjString* s = 0;
225  while ((s = static_cast<TObjString*>(next()))) {
226  TString t = s->String().Strip(TString::kBoth);
227  if (t.BeginsWith(which)) {
228  ret = t;
229  ret.ReplaceAll(Form("%s::",which.Data()), "");
230  break;
231  }
232  }
233  tokens->Delete();
234  delete tokens;
235  return !(ret.IsNull());
236  }
237  static Bool_t Check(TString& aliphysics,
238  TString& aliroot,
239  TString& root)
240  {
241  // Figure out what to do.
242  Bool_t show = (aliphysics.Contains("list", TString::kIgnoreCase) ||
243  aliroot.Contains("list", TString::kIgnoreCase) ||
244  root.Contains( "list", TString::kIgnoreCase));
245 
246  TObject* foundPhysics = GetPackage("AliPhysics", aliphysics);
247  GetVer(foundPhysics, "AliPhysics", aliphysics);
248  GetDep(foundPhysics, "AliRoot", aliroot);
249 
250  TObject* foundAliRoot = GetPackage("AliRoot", aliroot);
251  GetVer(foundAliRoot, "AliRoot", aliroot);
252  GetDep(foundAliRoot, "ROOT", root);
253 
254  TObject* foundRoot = GetPackage("ROOT", root);
255  GetVer(foundRoot, "ROOT", root);
256 
257  if (show) return false;
258 
259  if (aliphysics.IsNull() ||
260  aliroot.IsNull() ||
261  root.IsNull()) {
262  Warning("Check", "Missing packages (%s,%s,%s)",
263  aliphysics.Data(), aliroot.Data(), root.Data());
264  return false;
265  }
266  return true;
267  }
268  static void Test(const TString& phy,
269  const TString& ali=TString(),
270  const TString& roo=TString())
271  {
272  TString aliphysics(Form("list,%s", phy.Data()));
273  TString aliroot (Form("list,%s", ali.Data()));
274  TString root (Form("list,%s", roo.Data()));
275  Printf("Checking with AliPhysics=%s AliROOT=%s ROOT=%s",
276  phy.Data(), ali.Data(), roo.Data());
277  AvailableSoftware::Check(aliphysics,aliroot, root);
278 
279  aliphysics = Form("last,%s",phy.Data());
280  aliroot = Form("last,%s",ali.Data());
281  root = Form("last,%s",roo.Data());
282  if (AvailableSoftware::Check(aliphysics,aliroot, root))
283  Printf("Got AliPhysics=%s AliROOT=%s ROOT=%s",
284  aliphysics.Data(), aliroot.Data(), root.Data());
285  }
286 
287  static void Test()
288  {
289  Printf("All available");
291 
292  Printf("All regular");
293  AvailableSoftware::Test("regular","regular","regular");
294 
295  Printf("All releases");
296  AvailableSoftware::Test("release","release","release");
297 
298  Printf("All analysis tags");
299  AvailableSoftware::Test("analysis","analysis","analysis");
300  }
301 };
302 #endif
static const char * GetField(TObject *o)
static void Test(const TString &phy, const TString &ali=TString(), const TString &roo=TString())
TSystem * gSystem
TList * list
TCanvas * c
Definition: TestFitELoss.C:172
int Int_t
Definition: External.C:63
static Bool_t GetVer(TObject *pack, const TString &name, TString &ret)
static Bool_t Check(TString &aliphysics, TString &aliroot, TString &root)
static Bool_t GetDep(TObject *pack, const TString &which, TString &ret)
static TObject * GetPackage(const TString &name, const TString &query)
static TList * GetMap()
bool Bool_t
Definition: External.C:53