/** * @file AvailableSoftware.C * @author Christian Holm Christensen * @date Tue Oct 16 17:54:11 2012 * * @brief Find available packages * * @ingroup pwglf_forward_trains_util */ #ifndef AVAILABLESOFTWARE_C #define AVAILABLESOFTWARE_C #ifndef __CINT__ # include # include # include # include #else class TString; #endif /** * Helper code to find available packages on Grid * * * @ingroup pwglf_forward_trains_util */ struct AvailableSoftware { static Bool_t Check(TString& aliroot, TString& root, Bool_t debug=false) { // Figure out what to do. // If mode == 0, then do nothing. // If bit 0 is set in mode (0x1), then list and exit // If bit 1 is set in mode (0x2), select last AliROOT/ROOT version // If bit 2 is set in mode (0x4), select ROOT corresponding to AliROOT UShort_t mode = 0; Bool_t show = (aliroot.Contains("list", TString::kIgnoreCase) || root.Contains( "list", TString::kIgnoreCase)); Bool_t last = (aliroot.Contains("last", TString::kIgnoreCase) || aliroot.Contains("newest", TString::kIgnoreCase)); Bool_t nots = (aliroot.Contains("nonspecial", TString::kIgnoreCase) || aliroot.Contains("regular", TString::kIgnoreCase) || aliroot.Contains("standard", TString::kIgnoreCase)); Bool_t rele = (aliroot.Contains("release", TString::kIgnoreCase)); Bool_t anat = (aliroot.Contains("analysis", TString::kIgnoreCase)); TString c("wget -q http://alimonitor.cern.ch/packages/ -O - | " "sed -n -e '// p' | "); if (rele || anat || nots) { c.Append("sed -n '/Exec(c); return false; } if (last) mode |= 0x2; else if (!aliroot.IsNull()) mode |= 0x4; // Nothing to do if (mode == 0) return true; if (debug) Printf("Mode=0x%02x", mode); TString values = gSystem->GetFromPipe(c); TObjArray* tokens = values.Tokenize(" \t\n"); Int_t n = tokens->GetEntries(); // If we asked to select the last possible version, do so here and get out if (mode & 0x2) { aliroot = tokens->At(n-2)->GetName(); root = tokens->At(n-1)->GetName(); Info("AvaliableSoftware::Check", "Selecting lastest possible AliROOT/ROOT: %s/%s", aliroot.Data(), root.Data()); delete tokens; return true; } // We get here if we're asked to find a ROOT version compatible // with the selected AliROOT version. for (Int_t i = 0; i < n; i += 2) { if (aliroot.EqualTo(tokens->At(i)->GetName(), TString::kIgnoreCase)) { root = tokens->At(i+1)->GetName(); Info("AvaliableSoftware::Check", "Found ROOT version compatible with AliROOT %s: %s", aliroot.Data(), root.Data()); delete tokens; return true; } } // If we get here, then we didn't find a ROOT version compatible // with the selected AliROOT, and we should fail. Warning("AvaliableSoftware::Check", "Didn't find a ROOT version compatible with AliROOT %s", aliroot.Data()); delete tokens; return false; } static void Test(const TString& ali, const TString& roo=TString()) { TString aliroot(Form("list,%s",ali.Data())); TString root(roo); Printf("Checking with AliROOT=%s ROOT=%s", ali.Data(), roo.Data()); AvailableSoftware::Check(aliroot, root); aliroot = Form("last,%s",ali.Data()); AvailableSoftware::Check(aliroot, root); Printf("Got AliROOT=%s ROOT=%s", aliroot.Data(), root.Data()); } static void Test() { Printf("All available"); AvailableSoftware::Test(""); Printf("All regular"); AvailableSoftware::Test("regular"); Printf("All releases"); AvailableSoftware::Test("release"); Printf("All analysis tags"); AvailableSoftware::Test("analysis"); } }; #endif