Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
finalizeProof.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_proof
3///
4/// Macro to finalize queries run with the macro tutorials/runProof .
5/// This macro uses an existing PROOF session or starts one at the indicated URL.
6/// In the case non existing PROOF session is found and no URL is given, the macro
7/// tries to start a local PROOF session.
8///
9/// To run the macro:
10///
11/// root[] .L proof/finalizeProof.C+
12/// root[] finalizeProof("<analysis>")
13///
14/// See runProof.C for the analysis currently available.
15///
16/// The macro looks for the last completed queries for the chosen analysis and
17/// asks which one to finalize. If there is only available, it finalizes it
18/// without asking.
19/// All queries are considered for this, both those run synchronously and those
20/// run asynchronously, e.g. runProof("h1(asyn)").
21///
22///
23/// \macro_code
24///
25/// \author Gerardo Ganis
26
27#include "Getline.h"
28#include "TChain.h"
29#include "TEnv.h"
30#include "TProof.h"
31#include "TString.h"
32#include "TDrawFeedback.h"
33#include "TList.h"
34#include "TQueryResult.h"
35#include "TObjArray.h"
36
37#include "getProof.C"
38
39void finalizeProof(const char *what = "simple",
40 const char *url = "proof://localhost:11093",
41 Int_t nwrks = -1)
42{
43
44 // Temp dir for PROOF tutorials
45 TString tutdir = Form("%s/.proof-tutorial", gSystem->TempDirectory());
46 if (gSystem->AccessPathName(tutdir)) {
47 Printf("runProof: creating the temporary directory"
48 " for the tutorial (%s) ... ", tutdir.Data());
49 if (gSystem->mkdir(tutdir, kTRUE) != 0) {
50 Printf("runProof: could not assert / create the temporary directory"
51 " for the tutorial (%s)", tutdir.Data());
52 return;
53 }
54 }
55
56 // Get / Attach-to the PROOF Session
57 TProof *proof = getProof(url, nwrks, tutdir.Data(), "");
58 if (!proof) {
59 Printf("runProof: could not start/attach a PROOF session");
60 return;
61 }
62
63 // Get the last session run for the tutorial
64 TObjArray *qt = new TObjArray();
65 TString lasttag;
66 TString proofsessions(Form("%s/sessions",tutdir.Data()));
67 // Save tag of the used session
68 FILE *fs = fopen(proofsessions.Data(), "r");
69 if (!fs) {
70 Printf("runProof: could not create files for sessions tags");
71 } else {
72 char line[1024];
73 while (fgets(line, sizeof(line), fs)) {
74 int l = strlen(line);
75 if (l <= 0) continue;
76 if (strncmp(line,"session-",strlen("session-"))) continue;
77 if (line[l-1] == '\n') line[l-1] = 0;
78 lasttag = line;
79 qt->Add(new TObjString(lasttag.Data()));
80 }
81 fclose(fs);
82 }
83
84 // Retrieve the list of available query results
85 TList *ql = proof->GetListOfQueries("A");
86 if (!ql || ql->GetSize() <= 0) {
87 Printf("runProof: no queries to be finalized");
88 return;
89 }
90 ql->Print();
91
92 // Where is the code to run
93 char *rootbin = gSystem->Which(gSystem->Getenv("PATH"), "root.exe", kExecutePermission);
94 if (!rootbin) {
95 Printf("runProof: root.exe not found: please check the environment!");
96 return;
97 }
98 TString rootsys = gSystem->GetDirName(rootbin);
99 rootsys = gSystem->GetDirName(rootsys);
100 TString tutorials(Form("%s/tutorials", rootsys.Data()));
101 delete[] rootbin;
102
103 // Create feedback displayer
104 TDrawFeedback fb(proof);
105
106 // Parse 'what'; it is in the form 'analysis(arg1,arg2,...)'
107 TString args(what);
108 args.ReplaceAll("("," ");
109 args.ReplaceAll(")"," ");
110 args.ReplaceAll(","," ");
111 Ssiz_t from = 0;
112 TString act, tok;
113 if (!args.Tokenize(act, from, " ")) {
114 // Cannot continue
115 Printf("runProof: action not found: check your arguments (%s)", what);
116 return;
117 }
118
119 TObjArray *qa = new TObjArray();
120 TString sel;
121 // Action
122 if (act == "simple") {
123 sel = "ProofSimple";
124 } else if (act == "h1") {
125 sel = "h1analysis";
126 } else if (act == "pythia8") {
127 sel = "ProofPythia";
128 } else {
129 // Do not know what to run
130 Printf("runProof: unknown tutorial: %s", what);
131 }
132
133 // Get last completed queries for the chosen analysis
134 TString ref;
135 Int_t nt = qt->GetEntriesFast();
136 while (ref.IsNull() && nt--) {
137 lasttag = ((TObjString *)(qt->At(nt)))->GetName();
138 if (!lasttag.IsNull())
139 Printf("runProof: checking session: %s", lasttag.Data());
140 TIter nxq(ql);
141 TQueryResult *qr = 0;
142 while ((qr = (TQueryResult *)nxq())) {
143 if (qr->IsDone() && !lasttag.CompareTo(qr->GetTitle()) &&
144 !sel.CompareTo(qr->GetSelecImp()->GetTitle())) {
145 TString r = Form("%s:%s",qr->GetTitle(),qr->GetName());
146 qa->Add(new TObjString(r.Data()));
147 }
148 }
149 if (qa->GetEntriesFast() > 0) {
150 Int_t qn = 0;
151 if (qa->GetEntriesFast() > 1) {
152 // Query the client which query to finalize
153 Printf("finalizeProof: queries completed for analysis '%s'", act.Data());
154 for (Int_t k = 0; k < qa->GetEntriesFast(); k++) {
155 Printf(" [%d] %s", k, ((TObjString *)(qa->At(k)))->GetName());
156 }
157 Bool_t ask = kTRUE;
158 while (ask) {
159 char *answer = Getline("finalizeProof: enter the one you would like to finalize? [0] ");
160 if (answer) {
161 if (answer[0] == 'Q' || answer[0] == 'q') {
162 ask = kFALSE;
163 return;
164 }
165 TString sn(answer);
166 sn.Remove(sn.Length()-1);
167 if (sn.IsDigit()) {
168 qn = sn.Atoi();
169 if (qn >= 0 && qn < qa->GetEntriesFast()) {
170 break;
171 } else {
172 Printf("finalizeProof: choice must be in [0,%d] ('Q' to quit)",
173 qa->GetEntriesFast()-1);
174 }
175 } else {
176 if (sn.IsNull()) {
177 qn = 0;
178 break;
179 } else {
180 Printf("finalizeProof: choice must be a number in [0,%d] ('Q' to quit) (%s)",
181 qa->GetEntriesFast()-1, sn.Data());
182 }
183 }
184 }
185 }
186 }
187 ref = ((TObjString *)(qa->At(qn)))->GetName();
188 }
189 }
190 if (!ref.IsNull()) {
191 // Retrieve
192 proof->Retrieve(ref);
193 // Finalize
194 proof->Finalize(ref);
195 } else {
196 Printf("runProof: no queries to be finalized for analysis '%s'", act.Data());
197 return;
198 }
199}
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:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
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:2489
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
@ kExecutePermission
Definition TSystem.h:43
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
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 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:457
const char * Data() const
Definition TString.h:376
Bool_t IsNull() const
Definition TString.h:414
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1665
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition TSystem.cxx:906
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:1296
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1548
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1032
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition TSystem.cxx:1482
TLine * line
Attaches to a PROOF session, possibly at the indicated URL.
static const char * what
Definition stlLoader.cc:5
TLine l
Definition textangle.C:4