Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
finalizeProof.C File Reference

Detailed Description

Macro to finalize queries run with the macro tutorials/runProof .

This macro uses an existing PROOF session or starts one at the indicated URL. In the case non existing PROOF session is found and no URL is given, the macro tries to start a local PROOF session.

To run the macro:

root[] .L proof/finalizeProof.C+ root[] finalizeProof("<analysis>")

See runProof.C for the analysis currently available.

The macro looks for the last completed queries for the chosen analysis and asks which one to finalize. If there is only available, it finalizes it without asking. All queries are considered for this, both those run synchronously and those run asynchronously, e.g. runProof("h1(asyn)").

#include "Getline.h"
#include "TChain.h"
#include "TEnv.h"
#include "TProof.h"
#include "TString.h"
#include "TDrawFeedback.h"
#include "TList.h"
#include "TQueryResult.h"
#include "TObjArray.h"
#include "getProof.C"
void finalizeProof(const char *what = "simple",
const char *url = "proof://localhost:11093",
Int_t nwrks = -1)
{
// Temp dir for PROOF tutorials
TString tutdir = Form("%s/.proof-tutorial", gSystem->TempDirectory());
if (gSystem->AccessPathName(tutdir)) {
Printf("runProof: creating the temporary directory"
" for the tutorial (%s) ... ", tutdir.Data());
if (gSystem->mkdir(tutdir, kTRUE) != 0) {
Printf("runProof: could not assert / create the temporary directory"
" for the tutorial (%s)", tutdir.Data());
return;
}
}
// Get / Attach-to the PROOF Session
TProof *proof = getProof(url, nwrks, tutdir.Data(), "");
if (!proof) {
Printf("runProof: could not start/attach a PROOF session");
return;
}
// Get the last session run for the tutorial
TObjArray *qt = new TObjArray();
TString lasttag;
TString proofsessions(Form("%s/sessions",tutdir.Data()));
// Save tag of the used session
FILE *fs = fopen(proofsessions.Data(), "r");
if (!fs) {
Printf("runProof: could not create files for sessions tags");
} else {
char line[1024];
while (fgets(line, sizeof(line), fs)) {
int l = strlen(line);
if (l <= 0) continue;
if (strncmp(line,"session-",strlen("session-"))) continue;
if (line[l-1] == '\n') line[l-1] = 0;
lasttag = line;
qt->Add(new TObjString(lasttag.Data()));
}
fclose(fs);
}
// Retrieve the list of available query results
TList *ql = proof->GetListOfQueries("A");
if (!ql || ql->GetSize() <= 0) {
Printf("runProof: no queries to be finalized");
return;
}
ql->Print();
// Where is the code to run
char *rootbin = gSystem->Which(gSystem->Getenv("PATH"), "root.exe", kExecutePermission);
if (!rootbin) {
Printf("runProof: root.exe not found: please check the environment!");
return;
}
TString rootsys = gSystem->GetDirName(rootbin);
rootsys = gSystem->GetDirName(rootsys);
TString tutorials(Form("%s/tutorials", rootsys.Data()));
delete[] rootbin;
// Create feedback displayer
TDrawFeedback fb(proof);
// Parse 'what'; it is in the form 'analysis(arg1,arg2,...)'
TString args(what);
args.ReplaceAll("("," ");
args.ReplaceAll(")"," ");
args.ReplaceAll(","," ");
Ssiz_t from = 0;
TString act, tok;
if (!args.Tokenize(act, from, " ")) {
// Cannot continue
Printf("runProof: action not found: check your arguments (%s)", what);
return;
}
TObjArray *qa = new TObjArray();
// Action
if (act == "simple") {
sel = "ProofSimple";
} else if (act == "h1") {
sel = "h1analysis";
} else if (act == "pythia8") {
sel = "ProofPythia";
} else {
// Do not know what to run
Printf("runProof: unknown tutorial: %s", what);
}
// Get last completed queries for the chosen analysis
TString ref;
Int_t nt = qt->GetEntriesFast();
while (ref.IsNull() && nt--) {
lasttag = ((TObjString *)(qt->At(nt)))->GetName();
if (!lasttag.IsNull())
Printf("runProof: checking session: %s", lasttag.Data());
TIter nxq(ql);
TQueryResult *qr = 0;
while ((qr = (TQueryResult *)nxq())) {
if (qr->IsDone() && !lasttag.CompareTo(qr->GetTitle()) &&
!sel.CompareTo(qr->GetSelecImp()->GetTitle())) {
TString r = Form("%s:%s",qr->GetTitle(),qr->GetName());
qa->Add(new TObjString(r.Data()));
}
}
if (qa->GetEntriesFast() > 0) {
Int_t qn = 0;
if (qa->GetEntriesFast() > 1) {
// Query the client which query to finalize
Printf("finalizeProof: queries completed for analysis '%s'", act.Data());
for (Int_t k = 0; k < qa->GetEntriesFast(); k++) {
Printf(" [%d] %s", k, ((TObjString *)(qa->At(k)))->GetName());
}
Bool_t ask = kTRUE;
while (ask) {
char *answer = Getline("finalizeProof: enter the one you would like to finalize? [0] ");
if (answer) {
if (answer[0] == 'Q' || answer[0] == 'q') {
ask = kFALSE;
return;
}
TString sn(answer);
sn.Remove(sn.Length()-1);
if (sn.IsDigit()) {
qn = sn.Atoi();
if (qn >= 0 && qn < qa->GetEntriesFast()) {
break;
} else {
Printf("finalizeProof: choice must be in [0,%d] ('Q' to quit)",
qa->GetEntriesFast()-1);
}
} else {
if (sn.IsNull()) {
qn = 0;
break;
} else {
Printf("finalizeProof: choice must be a number in [0,%d] ('Q' to quit) (%s)",
qa->GetEntriesFast()-1, sn.Data());
}
}
}
}
}
ref = ((TObjString *)(qa->At(qn)))->GetName();
}
}
if (!ref.IsNull()) {
// Retrieve
proof->Retrieve(ref);
// Finalize
proof->Finalize(ref);
} else {
Printf("runProof: no queries to be finalized for analysis '%s'", act.Data());
return;
}
}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
int Ssiz_t
Definition RtypesCore.h:67
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2481
@ kExecutePermission
Definition TSystem.h:45
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
void Print(Option_t *option="") const override
Default print for collections, calls Print(option, 1).
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Utility class to draw objects in the feedback list during queries.
A doubly linked list.
Definition TList.h:38
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
void Add(TObject *obj) override
Definition TObjArray.h:68
Collectable string class.
Definition TObjString.h:28
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition TProof.h:316
Int_t Retrieve(Int_t query, const char *path=0)
Send retrieve request for the qry-th query in fQueries.
Definition TProof.cxx:5948
Long64_t Finalize(Int_t query=-1, Bool_t force=kFALSE)
Finalize the qry-th query in fQueries.
Definition TProof.cxx:5883
virtual TList * GetListOfQueries(Option_t *opt="")
Ask the master for the list of queries.
Definition TProof.cxx:2088
A container class for query results.
TMacro * GetSelecImp() const
virtual Bool_t IsDone() const
Basic string class.
Definition TString.h:139
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:450
const char * Data() const
Definition TString.h:380
Bool_t IsNull() const
Definition TString.h:418
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1666
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition TSystem.cxx:909
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1299
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1549
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1035
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition TSystem.cxx:1485
TLine * line
Attaches to a PROOF session, possibly at the indicated URL.
static const char * what
Definition stlLoader.cc:6
TLine l
Definition textangle.C:4
Author
Gerardo Ganis

Definition in file finalizeProof.C.