00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "Getline.h"
00022 #include "TChain.h"
00023 #include "TEnv.h"
00024 #include "TProof.h"
00025 #include "TString.h"
00026 #include "TDrawFeedback.h"
00027 #include "TList.h"
00028 #include "TQueryResult.h"
00029 #include "TObjArray.h"
00030
00031 #include "getProof.C"
00032
00033 void finalizeProof(const char *what = "simple",
00034 const char *url = "proof://localhost:11093",
00035 Int_t nwrks = -1)
00036 {
00037
00038
00039 TString tutdir = Form("%s/.proof-tutorial", gSystem->TempDirectory());
00040 if (gSystem->AccessPathName(tutdir)) {
00041 Printf("runProof: creating the temporary directory"
00042 " for the tutorial (%s) ... ", tutdir.Data());
00043 if (gSystem->mkdir(tutdir, kTRUE) != 0) {
00044 Printf("runProof: could not assert / create the temporary directory"
00045 " for the tutorial (%s)", tutdir.Data());
00046 return;
00047 }
00048 }
00049
00050
00051 TProof *proof = getProof(url, nwrks, tutdir.Data(), "");
00052 if (!proof) {
00053 Printf("runProof: could not start/attach a PROOF session");
00054 return;
00055 }
00056
00057
00058 TObjArray *qt = new TObjArray();
00059 TString lasttag;
00060 TString proofsessions(Form("%s/sessions",tutdir.Data()));
00061
00062 FILE *fs = fopen(proofsessions.Data(), "r");
00063 if (!fs) {
00064 Printf("runProof: could not create files for sessions tags");
00065 } else {
00066 char line[1024];
00067 while (fgets(line, sizeof(line), fs)) {
00068 int l = strlen(line);
00069 if (l <= 0) continue;
00070 if (strncmp(line,"session-",strlen("session-"))) continue;
00071 if (line[l-1] == '\n') line[l-1] = 0;
00072 lasttag = line;
00073 qt->Add(new TObjString(lasttag.Data()));
00074 }
00075 fclose(fs);
00076 }
00077
00078
00079 TList *ql = proof->GetListOfQueries("A");
00080 if (!ql || ql->GetSize() <= 0) {
00081 Printf("runProof: no queries to be finalized");
00082 return;
00083 }
00084 ql->Print();
00085
00086
00087 char *rootbin = gSystem->Which(gSystem->Getenv("PATH"), "root.exe", kExecutePermission);
00088 if (!rootbin) {
00089 Printf("runProof: root.exe not found: please check the environment!");
00090 return;
00091 }
00092 TString rootsys(gSystem->DirName(rootbin));
00093 rootsys = gSystem->DirName(rootsys);
00094 TString tutorials(Form("%s/tutorials", rootsys.Data()));
00095 delete[] rootbin;
00096
00097
00098 TDrawFeedback fb(proof);
00099
00100
00101 TString args(what);
00102 args.ReplaceAll("("," ");
00103 args.ReplaceAll(")"," ");
00104 args.ReplaceAll(","," ");
00105 Ssiz_t from = 0;
00106 TString act, tok;
00107 if (!args.Tokenize(act, from, " ")) {
00108
00109 Printf("runProof: action not found: check your arguments (%s)", what);
00110 return;
00111 }
00112
00113 TObjArray *qa = new TObjArray();
00114 TString sel;
00115
00116 if (act == "simple") {
00117 sel = "ProofSimple";
00118 } else if (act == "h1") {
00119 sel = "h1analysis";
00120 } else if (act == "pythia8") {
00121 sel = "ProofPythia";
00122 } else {
00123
00124 Printf("runProof: unknown tutorial: %s", what);
00125 }
00126
00127
00128 TString ref;
00129 Int_t nt = qt->GetEntriesFast();
00130 while (ref.IsNull() && nt--) {
00131 lasttag = ((TObjString *)(qt->At(nt)))->GetName();
00132 if (!lasttag.IsNull())
00133 Printf("runProof: checking session: %s", lasttag.Data());
00134 TIter nxq(ql);
00135 TQueryResult *qr = 0;
00136 while ((qr = (TQueryResult *)nxq())) {
00137 if (qr->IsDone() && !lasttag.CompareTo(qr->GetTitle()) &&
00138 !sel.CompareTo(qr->GetSelecImp()->GetTitle())) {
00139 TString r = Form("%s:%s",qr->GetTitle(),qr->GetName());
00140 qa->Add(new TObjString(r.Data()));
00141 }
00142 }
00143 if (qa->GetEntriesFast() > 0) {
00144 Int_t qn = 0;
00145 if (qa->GetEntriesFast() > 1) {
00146
00147 Printf("finalizeProof: queries completed for analysis '%s'", act.Data());
00148 for (Int_t k = 0; k < qa->GetEntriesFast(); k++) {
00149 Printf(" [%d] %s", k, ((TObjString *)(qa->At(k)))->GetName());
00150 }
00151 Bool_t ask = kTRUE;
00152 while (ask) {
00153 char *answer = Getline("finalizeProof: enter the one you would like to finalize? [0] ");
00154 if (answer) {
00155 if (answer[0] == 'Q' || answer[0] == 'q') {
00156 ask = kFALSE;
00157 return;
00158 }
00159 TString sn(answer);
00160 sn.Remove(sn.Length()-1);
00161 if (sn.IsDigit()) {
00162 qn = sn.Atoi();
00163 if (qn >= 0 && qn < qa->GetEntriesFast()) {
00164 break;
00165 } else {
00166 Printf("finalizeProof: choice must be in [0,%d] ('Q' to quit)",
00167 qa->GetEntriesFast()-1);
00168 }
00169 } else {
00170 if (sn.IsNull()) {
00171 qn = 0;
00172 break;
00173 } else {
00174 Printf("finalizeProof: choice must be a number in [0,%d] ('Q' to quit) (%s)",
00175 qa->GetEntriesFast()-1, sn.Data());
00176 }
00177 }
00178 }
00179 }
00180 }
00181 ref = ((TObjString *)(qa->At(qn)))->GetName();
00182 }
00183 }
00184 if (!ref.IsNull()) {
00185
00186 proof->Retrieve(ref);
00187
00188 proof->Finalize(ref);
00189 } else {
00190 Printf("runProof: no queries to be finalized for analysis '%s'", act.Data());
00191 return;
00192 }
00193 }