stressProof.cxx

Go to the documentation of this file.
00001 // ************************************************************************* //
00002 // *                                                                       * //
00003 // *                        s t r e s s P r o o f                          * //
00004 // *                                                                       * //
00005 // * This file contains a set of test of PROOF related functionality.      * //
00006 // * The tests can be run as a standalone program or with the interpreter. * //
00007 // * To run as a standalone program:                                       * //
00008 // *                                                                       * //
00009 // *  $ cd $ROOTSYS/test                                                   * //
00010 // *  $ make stressProof                                                   * //
00011 // *  $ ./stressProof [-h] [-n <wrks>] [-v[v[v]]] [-l logfile]             * //
00012 // *                  [-dyn] [-ds] [-t testnum] [-h1 h1src] [master]       * //
00013 // *                                                                       * //
00014 // * Optional arguments:                                                   * //
00015 // *   -h          show help info                                          * //
00016 // *   master      entry point of the cluster where to run the test        * //
00017 // *               in the form '[user@]host.domain[:port]';                * //
00018 // *               default 'localhost:40000'                               * //
00019 // *   -n wrks     number of workers to be started when running on the     * //
00020 // *               local host; default is the nuber of local cores         * //
00021 // *   -d level    verbosity level [1]                                     * //
00022 // *   -l logfile  file where to redirect the processing logs; default is  * //
00023 // *               a temporary file deleted at the end of the test; in     * //
00024 // *               case of success                                         * //
00025 // *   -dyn        run the test in dynamic startup mode                    * //
00026 // *   -ds         force the dataset test if skipped by default            * //
00027 // *   -t testnum  run only test 'testnum' and the tests from which it     * //
00028 // *               depends                                                 * //
00029 // *   -h1 h1src   specify a location for the H1 files;                    * //
00030 // *               use h1src="download" to download them to a temporary    * //
00031 // *               location; by default the files are read directly from   * //
00032 // *               the ROOT http server; however this may give failures if * //
00033 // *               the connection is slow                                  * //
00034 // *   -punzip     use parallel unzipping for data-driven processing       * //
00035 // *                                                                       * //
00036 // * To run interactively:                                                 * //
00037 // * $ root                                                                * //
00038 // * root[] .L stressProof.cxx+                                            * //
00039 // * root[] stressProof(master, wrks, verbose, logfile, dyn, \             * //
00040 // *                                         skipds, testnum, h1src)       * //
00041 // *                                                                       * //
00042 // * The arguments have the same meaning as above except for               * //
00043 // *     verbose [Int_t]   increasing verbosity (0 == minimal)             * //
00044 // *     dyn     [Bool_t]  if kTRUE run in dynamic startup mode            * //
00045 // *     skipds  [Bool_t]  if kTRUE the dataset related tests are skipped  * //
00046 // *                                                                       * //
00047 // *                                                                       * //
00048 // * The successful output looks like this:                                * //
00049 // *                                                                       * //
00050 // *  ******************************************************************   * //
00051 // *  *  Starting  P R O O F - S T R E S S suite                       *   * //
00052 // *  ******************************************************************   * //
00053 // *  *  Log file: /tmp/ProofStress_XrcwBe                                 * //
00054 // *  ******************************************************************   * //
00055 // *   Test  1 : Open a session ................................... OK *   * //
00056 // *   Test  2 : Get session logs ................................. OK *   * //
00057 // *   Test  3 : Simple random number generation .................. OK *   * //
00058 // *   Test  4 : Dataset handling with H1 files ................... OK *   * //
00059 // *   Test  5 : H1: chain processing ............................. OK *   * //
00060 // *   Test  6 : H1: file collection processing ................... OK *   * //
00061 // *   Test  7 : H1: file collection, TPacketizer ................. OK *   * //
00062 // *   Test  8 : H1: by-name processing ........................... OK *   * //
00063 // *   Test  9 : H1: multi dataset processing ..................... OK *   * //
00064 // *   Test 10 : H1: multi dataset and entry list ................. OK *   * //
00065 // *   Test 11 : Package management with 'event' .................. OK *   * //
00066 // *   Test 12 : Package argument passing ......................... OK *   * //
00067 // *   Test 13 : Simple 'event' generation ........................ OK *   * //
00068 // *   Test 14 : Input data propagation ........................... OK *   * //
00069 // *   Test 15 : H1, Simple: async mode :.......................... OK *   * //
00070 // *   Test 16 : Admin functionality .............................. OK *   * //
00071 // *   Test 17 : Dynamic sub-mergers functionality ................ OK *   * //
00072 // *  * All registered tests have been passed  :-)                     *   * //
00073 // *  ******************************************************************   * //
00074 // *                                                                       * //
00075 // * The application redirects the processing logs to a log file which is  * //
00076 // * normally deleted at the end of a successful run; if the test fails    * //
00077 // * the caller is asked if she/he wants to keep the log file; if the      * //
00078 // * specifies a log file path of her/his choice, the log file is never    * //
00079 // * deleted.                                                              * //
00080 // *                                                                       * //
00081 // * SKIPPED means that the test cannot be run.                            * //
00082 // *                                                                       * //
00083 // * New tests can be easily added by providing a function performing the  * //
00084 // * test and a name for the test; see examples below.                     * //
00085 // *                                                                       * //
00086 // * It is also possible to trigger the automatic PROOF valgrind setup by  * //
00087 // * means of the env GETPROOF_VALGRIND.                                   * //
00088 // * E.g. to run the master in valgrind do                                 * //
00089 // *                                                                       * //
00090 // *     $ export GETPROOF_VALGRIND="valgrind=master"                      * //
00091 // * or                                                                    * //
00092 // *     $ export GETPROOF_VALGRIND="valgrind=workers"                     * //
00093 // *                                                                       * //
00094 // * before running stressProof. The syntax is the same as for standard    * //
00095 // * PROOF valgrind runs. See                                              * //
00096 // *   http://root.cern.ch/drupal/content/running-proof-query-valgrind     * //
00097 // *                                                                       * //
00098 // ************************************************************************* //
00099 
00100 #include <stdio.h>
00101 #include <stdlib.h>
00102 
00103 #include "Getline.h"
00104 #include "TChain.h"
00105 #include "TFile.h"
00106 #include "TFileCollection.h"
00107 #include "TFileInfo.h"
00108 #include "TH1F.h"
00109 #include "TH2F.h"
00110 #include "TList.h"
00111 #include "TMacro.h"
00112 #include "TMap.h"
00113 #include "TMath.h"
00114 #include "TNamed.h"
00115 #include "TParameter.h"
00116 #include "TProof.h"
00117 #include "TProofLog.h"
00118 #include "TProofMgr.h"
00119 #include "TQueryResult.h"
00120 #include "TStopwatch.h"
00121 #include "TString.h"
00122 #include "TSystem.h"
00123 #include "TROOT.h"
00124 
00125 #include "../tutorials/proof/getProof.C"
00126 
00127 static const char *urldef = "proof://localhost:40000";
00128 static TString gtutdir;
00129 static TString gsandbox;
00130 static Int_t gverbose = 1;
00131 static TString glogfile;
00132 static Int_t gpoints = 0;
00133 static Int_t totpoints = 53;
00134 static RedirectHandle_t gRH;
00135 static RedirectHandle_t gRHAdmin;
00136 static Double_t gH1Time = 0;
00137 static Double_t gSimpleTime = 0;
00138 static Int_t gH1Cnt = 0;
00139 static Int_t gSimpleCnt = 0;
00140 static TStopwatch gTimer;
00141 static Bool_t gTimedOut = kFALSE;
00142 static Bool_t gDynamicStartup = kFALSE;
00143 static Bool_t gSkipDataSetTest = kTRUE;
00144 static Bool_t gUseParallelUnzip = kFALSE;
00145 static TString gh1src("http://root.cern.ch/files/h1");
00146 static Bool_t gh1ok = kTRUE;
00147 static const char *gh1file[] = { "dstarmb.root", "dstarp1a.root", "dstarp1b.root", "dstarp2.root" };
00148 
00149 // The selectors
00150 static TList gSelectors;
00151 static TString gH1Sel("$ROOTSYS/tutorials/tree/h1analysis.C");
00152 static TString gEventSel("$ROOTSYS/tutorials/proof/ProofEvent.C");
00153 static TString gSimpleSel("$ROOTSYS/tutorials/proof/ProofSimple.C");
00154 static TString gTestsSel("$ROOTSYS/tutorials/proof/ProofTests.C");
00155 
00156 void stressProof(const char *url = "proof://localhost:40000",
00157                  Int_t nwrks = -1, Int_t verbose = 1,
00158                  const char *logfile = 0, Bool_t dyn = kFALSE,
00159                  Bool_t skipds = kTRUE, Int_t test = -1,
00160                  const char *h1pfx = 0);
00161 
00162 //_____________________________batch only_____________________
00163 #ifndef __CINT__
00164 int main(int argc,const char *argv[])
00165 {
00166 
00167    // Request for help?
00168    if (argc > 1 && !strcmp(argv[1],"-h")) {
00169       printf(" \n");
00170       printf(" PROOF test suite\n");
00171       printf(" \n");
00172       printf(" Usage:\n");
00173       printf(" \n");
00174       printf(" $ ./stressProof [-h] [-n <wrks>] [-v[v[v]]] [-l logfile] [-dyn] [-ds] [-t testnum] [-h1 h1src] [master]\n");
00175       printf(" \n");
00176       printf(" Optional arguments:\n");
00177       printf("   -h            prints this menu\n");
00178       printf("   master        entry point of the cluster where to run the test\n");
00179       printf("                 in the form '[user@]host.domain[:port]'; default 'localhost:40000'\n");
00180       printf("   -n wrks       number of workers to be started when running on the local host;\n");
00181       printf("                 default is the nuber of local cores\n");
00182       printf("   -d level      verbosity level [1]\n");
00183       printf("   -l logfile    file where to redirect the processing logs; must be writable;\n");
00184       printf("                 default is a temporary file deleted at the end of the test\n");
00185       printf("                 in case of success\n");
00186       printf("   -dyn          run the test in dynamicStartup mode\n");
00187       printf("   -ds           force the dataset test if skipped by default\n");
00188       printf("   -t testnum    run only test 'testnum' and the tests from which it depends\n");
00189       printf("   -h1 h1src     specify a location for the H1 files; use h1src=\"download\" to download\n");
00190       printf("                 to a temporary location; by default the files are read directly from the\n");
00191       printf("                 ROOT http server; however this may give failures if the connection is slow\n");
00192       printf("   -punzip       use parallel unzipping for data-driven processing.\n");
00193       printf(" \n");
00194       gSystem->Exit(0);
00195    }
00196 
00197    // Parse options
00198    const char *url = 0;
00199    Int_t nWrks = -1;
00200    Int_t verbose = 1;
00201    Int_t test = -1;
00202    const char *logfile = 0;
00203    const char *h1src = 0;
00204    Int_t i = 1;
00205    while (i < argc) {
00206       if (!strcmp(argv[i],"-h")) {
00207          // Ignore if not first argument
00208          i++;
00209       } else if (!strcmp(argv[i],"-n")) {
00210          if (i+1 == argc || argv[i+1][0] == '-') {
00211             printf(" -n should be followed by the number of workers: ignoring \n");
00212             i++;
00213          } else  {
00214             nWrks = atoi(argv[i+1]);
00215             i += 2;
00216          }
00217       } else if (!strcmp(argv[i],"-d")) {
00218          if (i+1 == argc || argv[i+1][0] == '-') {
00219             printf(" -d should be followed by the debug level: ignoring \n");
00220             i++;
00221          } else  {
00222             verbose = atoi(argv[i+1]);
00223             i += 2;
00224          }
00225       } else if (!strcmp(argv[i],"-l")) {
00226          if (i+1 == argc || argv[i+1][0] == '-') {
00227             printf(" -l should be followed by a path: ignoring \n");
00228             i++;
00229          } else { 
00230             logfile = argv[i+1];
00231             i += 2;
00232          }
00233       } else if (!strncmp(argv[i],"-v",2)) {
00234          // For backward compatibility
00235          if (!strcmp(argv[i],"-v")) verbose = 1;
00236          if (!strncmp(argv[i],"-vv",3)) verbose = 2;
00237          i++;
00238       } else if (!strncmp(argv[i],"-dyn",4)) {
00239          gDynamicStartup = kTRUE;
00240          i++;
00241       } else if (!strncmp(argv[i],"-ds",3)) {
00242          gSkipDataSetTest = kFALSE;
00243          i++;
00244       } else if (!strncmp(argv[i],"-punzip",7)) {
00245          gUseParallelUnzip = kTRUE;
00246          i++;
00247       } else if (!strcmp(argv[i],"-t")) {
00248          if (i+1 == argc || argv[i+1][0] == '-') {
00249             printf(" -t should be followed by a number: ignoring \n");
00250             i++;
00251          } else { 
00252             test = atoi(argv[i+1]);
00253             i += 2;
00254          }
00255       } else if (!strcmp(argv[i],"-h1")) {
00256          if (i+1 == argc || argv[i+1][0] == '-') {
00257             printf(" -h1 should be followed by a prefix: ignoring \n");
00258             i++;
00259          } else { 
00260             h1src = argv[i+1];
00261             i += 2;
00262          }
00263       } else {
00264          url = argv[i];
00265          i++;
00266       }
00267    }
00268    // Use defaults where required
00269    if (!url) url = urldef;
00270 
00271    stressProof(url, nWrks, verbose, logfile, gDynamicStartup, gSkipDataSetTest, test, h1src);
00272 
00273    gSystem->Exit(0);
00274 }
00275 #endif
00276 
00277 //_____________________________________________________________________________
00278 Int_t PutPoint()
00279 {
00280    // Print one '.' and count it
00281    printf(".");
00282    return ++gpoints;
00283 }
00284 
00285 //______________________________________________________________________________
00286 void PrintStressProgress(Long64_t total, Long64_t processed, Float_t, Long64_t)
00287 {
00288    // Print some progress information
00289 
00290    gSystem->RedirectOutput(0, 0, &gRH);
00291 
00292    char pc[2] = { '.', ':'};
00293    static int lstpc = 1;
00294 
00295    int ns = 0;
00296    if (processed < total) {
00297       ns += 6;
00298       fprintf(stderr, "%c %2.0f %%", pc[(lstpc++)%2],
00299                                     (total ? ((100.0*processed)/total) : 100.0));
00300    }
00301    while (ns--) fprintf(stderr, "\b");
00302 
00303    gSystem->RedirectOutput(glogfile, "a", &gRH);
00304 }
00305 
00306 //______________________________________________________________________________
00307 void CleanupSelector(const char *selpath)
00308 {
00309    // Remove all non source files associated with seletor at path 'selpath'
00310 
00311    if (!selpath) return;
00312 
00313    TString dirpath(gSystem->DirName(selpath));
00314    if (gSystem->AccessPathName(dirpath)) return;
00315    TString selname(gSystem->BaseName(selpath));
00316    selname.ReplaceAll(".C", "_C");
00317    void *dirp = gSystem->OpenDirectory(dirpath);
00318    if (!dirp) return;
00319    TString fn;
00320    const char *e = 0;
00321    while ((e = gSystem->GetDirEntry(dirp))) {
00322       if (!strncmp(e, selname.Data(), selname.Length())) {
00323          // Cleanup this entry
00324          fn.Form("%s/%s", dirpath.Data(), e);
00325          gSystem->Unlink(fn);
00326       }
00327    }
00328 }
00329 
00330 //_____________________________________________________________________________
00331 void AssertParallelUnzip()
00332 {
00333    // Set the parallel unzip option
00334 
00335    if (gUseParallelUnzip) {
00336       gProof->SetParameter("PROOF_UseParallelUnzip", (Int_t)1);
00337    } else {
00338       gProof->SetParameter("PROOF_UseParallelUnzip", (Int_t)0);
00339    }
00340 }
00341 
00342 //
00343 // Auxilliary classes for testing
00344 //
00345 typedef Int_t (*ProofTestFun_t)(void *);
00346 class ProofTest : public TNamed {
00347 private:
00348    Int_t           fSeq;  // Sequential number for the test
00349    ProofTestFun_t  fFun;  // Function to be executed for the test
00350    void           *fArgs; // Arguments to be passed to the function
00351    TString         fDeps;  // Test dependencies, e.g. "1,3"
00352    TString         fSels;  // Selectors used, e.g. "h1analysis,ProofSimple"
00353    Int_t           fDepFrom; // Index for looping over deps
00354    Int_t           fSelFrom; // Index for looping over selectors
00355    Bool_t          fEnabled; // kTRUE if this test is enabled
00356 
00357 public:
00358    ProofTest(const char *n, Int_t seq, ProofTestFun_t f, void *a = 0, const char *d = "", const char *sel = "")
00359            : TNamed(n,""), fSeq(seq), fFun(f), fArgs(a),
00360              fDeps(d), fSels(sel), fDepFrom(0), fSelFrom(0), fEnabled(kTRUE) { }
00361    virtual ~ProofTest() { }
00362 
00363    void   Disable() { fEnabled = kFALSE; }
00364    void   Enable() { fEnabled = kTRUE; }
00365    Bool_t IsEnabled() const { return fEnabled; }
00366 
00367    Int_t  NextDep(Bool_t reset = kFALSE);
00368    Int_t  NextSel(TString &sel, Bool_t reset = kFALSE);
00369    Int_t  Num() const { return fSeq; }
00370 
00371    Int_t  Run();
00372 };
00373 
00374 //
00375 // Timer to stop asynchronous actions
00376 //
00377 class TTimeOutTimer : public TTimer {
00378 public:
00379    TTimeOutTimer(Long_t ms);
00380    Bool_t  Notify();
00381 };
00382 
00383 TTimeOutTimer::TTimeOutTimer(Long_t ms)
00384               : TTimer(ms, kTRUE)
00385 {
00386    //constructor
00387    gSystem->AddTimer(this);
00388 }
00389 
00390 Bool_t TTimeOutTimer::Notify()
00391 {
00392    //notifier
00393    gTimedOut = kTRUE;
00394    Remove();       // one shot only
00395    return kTRUE;
00396 }
00397 //------------------------------------------------------------------------------
00398 //_____________________________________________________________________________
00399 Int_t ProofTest::NextDep(Bool_t reset)
00400 {
00401    // Return index of next dependency or -1 if none (or no more)
00402    // If reset is kTRUE, reset the internal counter before acting.
00403 
00404    if (reset) fDepFrom = 0;
00405 
00406    TString tkn;
00407    if (fDeps.Tokenize(tkn, fDepFrom, ",")) {
00408       if (tkn.IsDigit()) return tkn.Atoi();
00409    }
00410    // Not found
00411    return -1;
00412 }
00413 //_____________________________________________________________________________
00414 Int_t ProofTest::NextSel(TString &sel, Bool_t reset)
00415 {
00416    // Return index of next dependency or -1 if none (or no more)
00417    // If reset is kTRUE, reset the internal counter before acting.
00418 
00419    if (reset) fSelFrom = 0;
00420    if (fSels.Tokenize(sel, fSelFrom, ",")) {
00421       if (!sel.IsNull()) return 0;
00422    }
00423    // Not found
00424    return -1;
00425 }
00426 
00427 //_____________________________________________________________________________
00428 Int_t ProofTest::Run()
00429 {
00430    // Generic stress steering function; returns 0 on success, -1 on error
00431 
00432    gpoints = 0;
00433    printf(" Test %2d : %s ", fSeq, GetName());
00434    PutPoint();
00435    gSystem->RedirectOutput(glogfile, "a", &gRH);
00436    Int_t rc = (*fFun)(fArgs);
00437    gSystem->RedirectOutput(0, 0, &gRH);
00438    if (rc == 0) {
00439       Int_t np = totpoints - strlen(GetName()) - strlen(" OK *");
00440       while (np--) { printf("."); }
00441       printf(" OK *\n");
00442    } else if (rc == 1) {
00443       Int_t np = totpoints - strlen(GetName()) - strlen(" SKIPPED *");
00444       while (np--) { printf("."); }
00445       printf(" SKIPPED *\n");
00446    } else {
00447       Int_t np = totpoints - strlen(GetName()) - strlen(" FAILED *");
00448       while (np--) { printf("."); }
00449       printf(" FAILED *\n");
00450       gSystem->ShowOutput(&gRH);
00451    }
00452    // Done
00453    return rc;
00454 }
00455 
00456 // Test functions
00457 Int_t PT_Open(void *);
00458 Int_t PT_GetLogs(void *);
00459 Int_t PT_Simple(void *smg = 0);
00460 Int_t PT_H1Http(void *);
00461 Int_t PT_H1FileCollection(void *);
00462 Int_t PT_H1DataSet(void *);
00463 Int_t PT_H1MultiDataSet(void *);
00464 Int_t PT_H1MultiDSetEntryList(void *);
00465 Int_t PT_DataSets(void *);
00466 Int_t PT_Packages(void *);
00467 Int_t PT_Event(void *);
00468 Int_t PT_InputData(void *);
00469 Int_t PT_H1SimpleAsync(void *arg);
00470 Int_t PT_AdminFunc(void *arg);
00471 Int_t PT_PackageArguments(void *);
00472 
00473 // Arguments structures
00474 typedef struct {            // Open
00475    const char *url;
00476    Int_t       nwrks;
00477 } PT_Open_Args_t;
00478 
00479 // Packetizer parameters
00480 typedef struct {
00481    const char *fName;
00482    Int_t fType;
00483 } PT_Packetizer_t;
00484 
00485 static PT_Packetizer_t gStd_Old = { "TPacketizer", 0 };
00486 
00487 //_____________________________________________________________________________
00488 void stressProof(const char *url, Int_t nwrks, Int_t verbose, const char *logfile,
00489                  Bool_t dyn, Bool_t skipds, Int_t test, const char *h1src)
00490 {
00491    printf("******************************************************************\n");
00492    printf("*  Starting  P R O O F - S T R E S S  suite                      *\n");
00493    printf("******************************************************************\n");
00494 
00495    // Set dynamic mode
00496    gDynamicStartup = (!strcmp(url,"lite")) ? kFALSE : dyn;
00497 
00498    // Set verbosity
00499    gverbose = verbose;
00500 
00501    // Notify/warn about the dynamic startup option, if any
00502    TUrl uu(url), udef(urldef);
00503    Bool_t extcluster = (strcmp(uu.GetHost(), udef.GetHost()) ||
00504                        (uu.GetPort() != udef.GetPort())) ? kTRUE : kFALSE;
00505    if (gDynamicStartup && gverbose > 0) {
00506       // Check url
00507       if (extcluster) {
00508          printf("*   WARNING: request to run a test with per-job scheduling on    *\n");
00509          printf("*            an external cluster: %s .\n", url);
00510          printf("*            Make sure the dynamic option is set.                *\n");
00511          printf("******************************************************************\n");
00512          gDynamicStartup = kFALSE;
00513       } else {
00514          printf("*  Runnning in dynamic mode (per-job scheduling)                 *\n");
00515          printf("******************************************************************\n");
00516       }
00517    }
00518 
00519    // Dataset option
00520    if (!skipds) {
00521       gSkipDataSetTest = kFALSE;
00522    } else {
00523       gSkipDataSetTest = (!extcluster || !strcmp(url, "lite")) ? kFALSE : kTRUE;
00524    }
00525 
00526    // Log file path
00527    Bool_t usedeflog = kTRUE;
00528    FILE *flog = 0;
00529    if (logfile && strlen(logfile) > 0) {
00530       usedeflog = kFALSE;
00531       glogfile = logfile;
00532       if (glogfile.Contains("<tmpdir>"))
00533          glogfile.ReplaceAll("<tmpdir>", gSystem->TempDirectory());
00534       if (!gSystem->AccessPathName(glogfile, kFileExists)) {
00535          if (!gSystem->AccessPathName(glogfile, kWritePermission)) {
00536             printf(" >>> Cannot write to log file %s - ignore file request\n", logfile);
00537             usedeflog = kTRUE;
00538          }
00539       } else {
00540          // Create the file
00541          if (!(flog = fopen(logfile, "w"))) {
00542             printf(" >>> Cannot create log file %s - ignore file request\n", logfile);
00543             usedeflog = kTRUE;
00544          }
00545       }
00546    }
00547    if (usedeflog) {
00548       glogfile = "ProofStress_";
00549       if (!(flog = gSystem->TempFileName(glogfile, gSystem->TempDirectory()))) {
00550          printf(" >>> Cannot create a temporary log file on %s - exit\n", gSystem->TempDirectory());
00551          return;
00552       }
00553       fclose(flog);
00554       if (gverbose > 0) {
00555          printf("*  Log file: %s\n", glogfile.Data());
00556          printf("******************************************************************\n");
00557       }
00558    }
00559 
00560    if (gSkipDataSetTest && gverbose > 0) {
00561       printf("*  Test for dataset handling (#4, #8-10) skipped                **\n");
00562       printf("******************************************************************\n");
00563    }
00564    if (gUseParallelUnzip && gverbose > 0) {
00565       printf("*  Using parallel unzip where relevant                          **\n");
00566       printf("******************************************************************\n");
00567    }
00568    if (!strcmp(url,"lite") && gverbose > 0) {
00569       printf("*  PROOF-Lite session (tests #15 and #16 skipped)               **\n");
00570       printf("******************************************************************\n");
00571    }
00572    if (test > 0 && gverbose > 0) {
00573       if (test < 16) {
00574          printf("*  Running only test %2d (and related tests)                     **\n", test);
00575          printf("******************************************************************\n");
00576       } else {
00577          printf("*  Request for unknown test %2d : ignore                         **\n", test);
00578          printf("******************************************************************\n");
00579          test = -1;
00580       }
00581    }
00582    if (h1src && strlen(h1src) && gverbose > 0) {
00583       if (!strcmp(h1src, "download") && extcluster) {
00584          printf("*  External clusters: ignoring download request of H1 files\n");
00585          printf("******************************************************************\n");
00586       } else if (!gh1src.BeginsWith(h1src)) {
00587          printf("*  Taking H1 files from: %s\n", h1src);
00588          printf("******************************************************************\n");
00589          gh1src = h1src;
00590          gh1ok = kFALSE;
00591       }
00592    }
00593    //
00594    // Reset dataset settings
00595    gEnv->SetValue("Proof.DataSetManager","");
00596 
00597    //
00598    // Register tests
00599    //
00600    TList *testList = new TList;
00601    // Simple open
00602    PT_Open_Args_t PToa = { url, nwrks };
00603    testList->Add(new ProofTest("Open a session", 1, &PT_Open, (void *)&PToa));
00604    // Get logs
00605    testList->Add(new ProofTest("Get session logs", 2, &PT_GetLogs, (void *)&PToa, "1"));
00606    // Simple histogram generation
00607    testList->Add(new ProofTest("Simple random number generation", 3, &PT_Simple, 0, "1", "ProofSimple"));
00608    // Test of data set handling with the H1 http files
00609    testList->Add(new ProofTest("Dataset handling with H1 files", 4, &PT_DataSets, 0, "1"));
00610    // H1 analysis over HTTP (chain)
00611    testList->Add(new ProofTest("H1: chain processing", 5, &PT_H1Http, 0, "1", "h1analysis"));
00612    // H1 analysis over HTTP (file collection)
00613    testList->Add(new ProofTest("H1: file collection processing", 6, &PT_H1FileCollection, 0, "1", "h1analysis"));
00614    // H1 analysis over HTTP: classic packetizer
00615    testList->Add(new ProofTest("H1: file collection, TPacketizer", 7, &PT_H1FileCollection, (void *)&gStd_Old, "1", "h1analysis"));
00616    // H1 analysis over HTTP by dataset name
00617    testList->Add(new ProofTest("H1: by-name processing", 8, &PT_H1DataSet, 0, "1,4", "h1analysis"));
00618    // H1 analysis over HTTP by dataset name splitted in two
00619    testList->Add(new ProofTest("H1: multi dataset processing", 9, &PT_H1MultiDataSet, 0, "1,4", "h1analysis"));
00620    // H1 analysis over HTTP by dataset name
00621    testList->Add(new ProofTest("H1: multi dataset and entry list", 10, &PT_H1MultiDSetEntryList, 0, "1,4", "h1analysis"));
00622    // Test package management with 'event'
00623    testList->Add(new ProofTest("Package management with 'event'", 11, &PT_Packages, 0, "1"));
00624    // Test package argument passing
00625    testList->Add(new ProofTest("Package argument passing", 12, &PT_PackageArguments, 0, "1", "ProofTests"));
00626    // Simple event analysis
00627    testList->Add(new ProofTest("Simple 'event' generation", 13, &PT_Event, 0, "1", "ProofEvent"));
00628    // Test input data propagation (it only works in the static startup mode)
00629    testList->Add(new ProofTest("Input data propagation", 14, &PT_InputData, 0, "1", "ProofTests"));
00630    // Test asynchronous running
00631    testList->Add(new ProofTest("H1, Simple: async mode", 15, &PT_H1SimpleAsync, 0, "1,3,5", "h1analysis,ProofSimple"));
00632    // Test admin functionality
00633    testList->Add(new ProofTest("Admin functionality", 16, &PT_AdminFunc, 0, "1"));
00634    // Test merging via submergers
00635    Bool_t useMergers = kTRUE;
00636    testList->Add(new ProofTest("Dynamic sub-mergers functionality", 17, &PT_Simple, (void *)&useMergers, "1", "ProofSimple"));
00637 
00638    // The selectors
00639    gSystem->ExpandPathName(gH1Sel);
00640    gSystem->ExpandPathName(gEventSel);
00641    gSystem->ExpandPathName(gSimpleSel);
00642    gSystem->ExpandPathName(gTestsSel);
00643    gSelectors.Add(new TNamed("h1analysis", gH1Sel.Data()));
00644    gSelectors.Add(new TNamed("ProofEvent", gEventSel.Data()));
00645    gSelectors.Add(new TNamed("ProofSimple", gSimpleSel.Data()));
00646    gSelectors.Add(new TNamed("ProofTests", gTestsSel.Data()));
00647    if (gverbose > 0) printf("*  Cleaning all non-source files associated to:\n");
00648 
00649    // Check what to run
00650    ProofTest *t = 0, *treq = 0;
00651    TIter nxt(testList);
00652    if (test > 0) {
00653       // Disable first all the tests
00654       while ((t = (ProofTest *)nxt())) {
00655          t->Disable();
00656          if (t->Num() == test) treq = t;
00657       }
00658       if (!treq) {
00659          printf("* Test %2d not found among the registered tests - exiting        **\n", test);
00660          printf("******************************************************************\n");
00661          return;
00662       }
00663       // Enable the required tests
00664       Int_t tn = -1;
00665       while ((tn = treq->NextDep()) > 0) {
00666          nxt.Reset();
00667          while ((t = (ProofTest *)nxt())) {
00668             if (t->Num() == tn) {
00669                t->Enable();
00670                break;
00671             }
00672          }
00673       }
00674       // Reset associated selectors
00675       TString sel;
00676       while ((treq->NextSel(sel)) == 0) {
00677          TNamed *nm = (TNamed *) gSelectors.FindObject(sel.Data());
00678          if (nm) {
00679             CleanupSelector(nm->GetTitle());
00680             if (gverbose > 0)
00681                printf("*     %s   \t in %s\n", nm->GetName(), gSystem->DirName(nm->GetTitle()));
00682          }
00683       }
00684       // Enable the required test
00685       treq->Enable();
00686    } else {
00687       // Clean all the selectors
00688       TIter nxs(&gSelectors);
00689       TNamed *nm = 0;
00690       while ((nm = (TNamed *)nxs())) {
00691          CleanupSelector(nm->GetTitle());
00692          if (gverbose > 0)
00693             printf("*     %s   \t in %s\n", nm->GetName(), gSystem->DirName(nm->GetTitle()));
00694       }
00695    }
00696    if (gverbose > 0)
00697       printf("******************************************************************\n");
00698 
00699    // Add the ACLiC option to the selector strings
00700    gH1Sel += "+";
00701    gEventSel += "+";
00702    gSimpleSel += "+";
00703    gTestsSel += "+";
00704 
00705    //
00706    // Run the tests
00707    //
00708    Bool_t failed = kFALSE;
00709    nxt.Reset();
00710    while ((t = (ProofTest *)nxt()))
00711       if (t->IsEnabled()) {
00712          if (t->Run() < 0) {
00713             failed = kTRUE;
00714             break;
00715          }
00716       }
00717 
00718    // Done
00719    if (failed) {
00720       Bool_t kept = kTRUE;
00721       if (usedeflog && !gROOT->IsBatch()) {
00722          char *answer = Getline(" Some tests failed: would you like to keep the log file (N,Y)? [Y] ");
00723          if (answer && (answer[0] == 'N' || answer[0] == 'n')) {
00724             // Remove log file
00725             gSystem->Unlink(glogfile);
00726             kept = kFALSE;
00727          }
00728       }
00729       if (kept)
00730          printf("* Log file kept at %s\n", glogfile.Data());
00731    } else {
00732       printf("* All registered tests have been passed  :-)                     *\n");
00733       // Remove log file if not passed by the user
00734       if (usedeflog)
00735          gSystem->Unlink(glogfile);
00736    }
00737 
00738    printf("******************************************************************\n");
00739    if (gProof) {
00740       gProof->GetStatistics((verbose > 0));
00741       // Reference time measured on a HP DL580 24 core (4 x Intel(R) Xeon(R) CPU X7460
00742       // @ 2.132 GHz, 48GB RAM, 1 Gb/s NIC) with 2 workers.
00743       const double reftime = 21.060;
00744       double rootmarks = (gProof->GetCpuTime() > 0) ? 1000 * reftime / gProof->GetCpuTime() : -1;
00745       printf(" ROOTMARKS = %.2f ROOT version: %s\t%s@%d\n", rootmarks, gROOT->GetVersion(),
00746              gROOT->GetSvnBranch(), gROOT->GetSvnRevision());
00747       printf("******************************************************************\n");
00748    }
00749 
00750    // If not PROOF-Lite, stop the daemon used for the test
00751    if (gProof && !gProof->IsLite() && !extcluster) {
00752       // Close the instance
00753       gProof->Close("S");
00754       delete gProof;
00755       // The daemon runs on a port shifted by 1
00756       if (killXrootdAt(uu.GetPort()+1, "xpdtut") != 0) {
00757          printf("+++ Warning: test daemon probably still running!\n");
00758       }
00759    }
00760 }
00761 
00762 //_____________________________________________________________________________
00763 Int_t PT_H1AssertFiles(const char *h1src)
00764 {
00765    // Make sure that the needed H1 files are available at 'src'
00766    // If 'src' is "download", the files are download under <tutdir>/h1
00767 
00768    if (!h1src || strlen(h1src) <= 0) {
00769       printf("\n >>> Test failure: src dir undefined\n");
00770       return -1;
00771    }
00772 
00773    // Special case
00774    if (!strcmp(h1src,"download")) {
00775       gh1src = TString::Format("%s/h1", gtutdir.Data());
00776       if (gSystem->AccessPathName(gh1src)) {
00777          if (gSystem->MakeDirectory(gh1src) != 0) {
00778             printf("\n >>> Test failure: could not create dir %s\n", gh1src.Data());
00779             return -1;
00780          }
00781       }
00782       // Copy the files now
00783       Int_t i = 0;
00784       for (i = 0; i < 4; i++) {
00785          TString src = TString::Format("http://root.cern.ch/files/h1/%s", gh1file[i]);
00786          TString dst = TString::Format("%s/%s", gh1src.Data(), gh1file[i]);
00787          if (!TFile::Cp(src, dst)) {
00788             printf("\n >>> Test failure: problems retrieving %s\n", src.Data());
00789             return -1;
00790          }
00791          gSystem->RedirectOutput(0, 0, &gRH);
00792          printf("%d\b", i);
00793          gSystem->RedirectOutput(glogfile, "a", &gRH);
00794       }
00795       // Done
00796       gh1ok = kTRUE;
00797       return 0;
00798    }
00799 
00800    // Make sure the files exist at 'src'
00801    Int_t i = 0;
00802    for (i = 0; i < 4; i++) {
00803       TString src = TString::Format("%s/%s", h1src, gh1file[i]);
00804       if (gSystem->AccessPathName(src)) {
00805          printf("\n >>> Test failure: file %s does not exist\n", src.Data());
00806          return -1;
00807       }
00808       gSystem->RedirectOutput(0, 0, &gRH);
00809       printf("%d\b", i);
00810       gSystem->RedirectOutput(glogfile, "a", &gRH);
00811    }
00812    gh1src = h1src;
00813 
00814    // Done
00815    gh1ok = kTRUE;
00816    return 0;
00817 }
00818 
00819 //_____________________________________________________________________________
00820 Int_t PT_CheckSimple(TQueryResult *qr, Long64_t nevt, Int_t nhist)
00821 {
00822    // Check the result of the ProofSimple analysis
00823 
00824    if (!qr) {
00825       printf("\n >>> Test failure: query result not found\n");
00826       return -1;
00827    }
00828 
00829    // Make sure the number of processed entries is the one expected
00830    PutPoint();
00831    if (qr->GetEntries() != nevt) {
00832       printf("\n >>> Test failure: wrong number of entries processed: %lld (expected %lld)\n",
00833              qr->GetEntries(), nevt);
00834       return -1;
00835    }
00836 
00837    // Make sure the output list is there
00838    PutPoint();
00839    TList *out = qr->GetOutputList();
00840    if (!out) {
00841       printf("\n >>> Test failure: output list not found\n");
00842       return -1;
00843    }
00844 
00845    // Get the histos
00846    PutPoint();
00847    TH1F **hist = new TH1F*[nhist];
00848    for (Int_t i=0; i < nhist; i++) {
00849       hist[i] = dynamic_cast<TH1F *>(out->FindObject(Form("h%d",i)));
00850       if (!hist[i]) {
00851          printf("\n >>> Test failure: 'h%d' histo not found\n", i);
00852          return -1;
00853       }
00854    }
00855 
00856    // Check the mean values
00857    PutPoint();
00858    for (Int_t i=0; i < nhist; i++) {
00859       Double_t ave = hist[i]->GetMean();
00860       Double_t rms = hist[i]->GetRMS();
00861       if (TMath::Abs(ave) > 5 * rms / TMath::Sqrt(hist[i]->GetEntries())) {
00862          printf("\n >>> Test failure: 'h%d' histo: mean > 5 * RMS/Sqrt(N)\n", i);
00863          return -1;
00864       }
00865    }
00866 
00867    // Done
00868    PutPoint();
00869    return 0;
00870 }
00871 
00872 //_____________________________________________________________________________
00873 Int_t PT_CheckH1(TQueryResult *qr, Int_t irun = 0)
00874 {
00875    // Check the result of the H1 analysis
00876 
00877    if (!qr) {
00878       printf("\n >>> Test failure: output list not found\n");
00879       return -1;
00880    }
00881 
00882    // Make sure the number of processed entries is the one expected
00883    PutPoint();
00884    Long64_t runEntries[2] = {283813, 7525};
00885    if (qr->GetEntries() != runEntries[irun]) {
00886       printf("\n >>> Test failure: wrong number of entries processed: %lld (expected 283813)\n", qr->GetEntries());
00887       return -1;
00888    }
00889 
00890    // Make sure the output list is there
00891    PutPoint();
00892    TList *out = qr->GetOutputList();
00893    if (!out) {
00894       printf("\n >>> Test failure: output list not found\n");
00895       return -1;
00896    }
00897 
00898    // Check the 'hdmd' histo
00899    PutPoint();
00900    TH1F *hdmd = dynamic_cast<TH1F*>(out->FindObject("hdmd"));
00901    if (!hdmd) {
00902       printf("\n >>> Test failure: 'hdmd' histo not found\n");
00903       return -1;
00904    }
00905    if ((Int_t)(hdmd->GetEntries()) != 7525) {
00906       printf("\n >>> Test failure: 'hdmd' histo: wrong number"
00907              " of entries (%d: expected 7525) \n",(Int_t)(hdmd->GetEntries()));
00908       return -1;
00909    }
00910    if (TMath::Abs((hdmd->GetMean() - 0.15512023) / 0.15512023) > 0.001) {
00911       printf("\n >>> Test failure: 'hdmd' histo: wrong mean"
00912              " (%f: expected 0.15512023) \n", hdmd->GetMean());
00913       return -1;
00914    }
00915 
00916    PutPoint();
00917    TH2F *h2 = dynamic_cast<TH2F*>(out->FindObject("h2"));
00918    if (!h2) {
00919       printf("\n >>> Test failure: 'h2' histo not found\n");
00920       return -1;
00921    }
00922    if ((Int_t)(h2->GetEntries()) != 7525) {
00923       printf("\n >>> Test failure: 'h2' histo: wrong number"
00924              " of entries (%d: expected 7525) \n",(Int_t)(h2->GetEntries()));
00925       return -1;
00926    }
00927    if (TMath::Abs((h2->GetMean() - 0.15245688) / 0.15245688) > 0.001) {
00928       printf("\n >>> Test failure: 'h2' histo: wrong mean"
00929              " (%f: expected 0.15245688) \n", h2->GetMean());
00930       return -1;
00931    }
00932 
00933    // Done
00934    PutPoint();
00935    return 0;
00936 }
00937 
00938 //_____________________________________________________________________________
00939 Int_t PT_Open(void *args)
00940 {
00941    // Test session opening
00942 
00943    // Checking arguments
00944    PutPoint();
00945    PT_Open_Args_t *PToa = (PT_Open_Args_t *)args;
00946    if (!PToa) {
00947       printf("\n >>> Test failure: invalid arguments: %p\n", args);
00948       return -1;
00949    }
00950 
00951    // Temp dir for PROOF tutorials
00952    PutPoint();
00953    TString tmpdir(gSystem->TempDirectory()), us;
00954 #if !defined(R__MACOSX) 
00955    if (!tmpdir.EndsWith(us.Data())) {
00956       UserGroup_t *ug = gSystem->GetUserInfo(gSystem->GetUid());
00957       if (ug) {
00958          us.Form("/%s", ug->fUser.Data());
00959          tmpdir += us;
00960          delete ug;
00961       } else {
00962          printf("\n >>> Test failure: could not get user info");
00963          return -1;
00964       }
00965    }
00966    gtutdir.Form("%s/.proof-tutorial", tmpdir.Data());
00967 #else
00968    gtutdir.Form("%s/.proof", tmpdir.Data());
00969 #endif
00970    if (gSystem->AccessPathName(gtutdir)) {
00971       if (gSystem->mkdir(gtutdir, kTRUE) != 0) {
00972          printf("\n >>> Test failure: could not assert/create the temporary directory"
00973                 " for the tutorial (%s)", gtutdir.Data());
00974          return -1;
00975       }
00976    }
00977 
00978    // String to initialize the dataset manager
00979    TString dsetmgrstr;
00980    dsetmgrstr.Form("file dir:%s/datasets opt:-Cq:As:Sb:", gtutdir.Data());
00981    gEnv->SetValue("Proof.DataSetManager", dsetmgrstr.Data());
00982 
00983    // String to initialize the package dir
00984    TString packdir;
00985    packdir.Form("%s/packages", gtutdir.Data());
00986    gEnv->SetValue("Proof.PackageDir", packdir.Data());
00987 
00988    // Get the PROOF Session
00989    PutPoint();
00990    TProof *p = getProof(PToa->url, PToa->nwrks, gtutdir.Data(), "force", gDynamicStartup, kTRUE);
00991    if (!p || !(p->IsValid())) {
00992       printf("\n >>> Test failure: could not start the session\n");
00993       return -1;
00994    }
00995 
00996    PutPoint();
00997    if (PToa->nwrks > 0 && p->GetParallel() != PToa->nwrks) {
00998       printf("\n >>> Test failure: number of workers different from requested\n");
00999       return -1;
01000    }
01001 
01002    // Clear Cache
01003    p->ClearCache();
01004 
01005    // Get some useful info about the cluster (the sandbox dir ...)
01006    gSystem->RedirectOutput(0, 0, &gRH);
01007    TString testPrint(TString::Format("%s/testPrint.log", gtutdir.Data()));
01008    gSystem->RedirectOutput(testPrint, "w", &gRHAdmin);
01009    gProof->Print();
01010    gSystem->RedirectOutput(0, 0, &gRHAdmin);
01011    gSystem->RedirectOutput(glogfile, "a", &gRH);
01012    TMacro macroPrint(testPrint);
01013    TObjString *os = macroPrint.GetLineWith("Working directory:");
01014    if (!os) {
01015       printf("\n >>> Test failure: problem parsing output from Print()\n");
01016       return -1;
01017    }
01018    Int_t from = strlen("Working directory:") + 1;
01019    if (!os->GetString().Tokenize(gsandbox, from, " ")) {
01020       printf("\n >>> Test failure: no sandbox dir found\n");
01021       return -1;
01022    }
01023    gsandbox = gSystem->DirName(gsandbox);
01024    gsandbox = gSystem->DirName(gsandbox);
01025    PutPoint();
01026 
01027    // Done
01028    PutPoint();
01029    return 0;
01030 }
01031 
01032 //_____________________________________________________________________________
01033 Int_t PT_GetLogs(void *args)
01034 {
01035    // Test log retrieving
01036 
01037    // Checking arguments
01038    PutPoint();
01039    PT_Open_Args_t *PToa = (PT_Open_Args_t *)args;
01040    if (!PToa) {
01041       printf("\n >>> Test failure: invalid arguments: %p\n", args);
01042       return -1;
01043    }
01044 
01045    PutPoint();
01046    TProofLog *pl = TProof::Mgr(PToa->url)->GetSessionLogs();
01047    if (!pl) {
01048       printf("\n >>> Test failure: could not get the logs from last session\n");
01049       return -1;
01050    }
01051 
01052    PutPoint();
01053    if (PToa->nwrks > 0 && pl->GetListOfLogs()->GetSize() != (PToa->nwrks + 1)) {
01054       printf("\n >>> Test failure: number of logs different from workers of workers + 1\n");
01055       return -1;
01056    }
01057 
01058    // Done
01059    PutPoint();
01060    return 0;
01061 }
01062 
01063 //_____________________________________________________________________________
01064 Int_t PT_Simple(void *submergers)
01065 {
01066    // Test run for the ProofSimple analysis (see tutorials)
01067 
01068    // Checking arguments
01069    PutPoint();
01070    if (!gProof) {
01071       printf("\n >>> Test failure: no PROOF session found\n");
01072       return -1;
01073    }
01074 
01075    // Setup submergers if required
01076    if (submergers) {
01077       gProof->SetParameter("PROOF_UseMergers", 0);
01078    }
01079 
01080    // Define the number of events and histos
01081    Long64_t nevt = 1000000;
01082    Int_t nhist = 16;
01083    // The number of histograms is added as parameter in the input list
01084    gProof->SetParameter("ProofSimple_NHist", (Long_t)nhist);
01085 
01086    // Clear the list of query results
01087    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01088 
01089    // Process
01090    PutPoint();
01091    gProof->SetPrintProgress(&PrintStressProgress);
01092    gTimer.Start();
01093    gProof->Process(gSimpleSel.Data(), nevt);
01094    gTimer.Stop();
01095    gProof->SetPrintProgress(0);
01096 
01097    // Count
01098    gSimpleCnt++;
01099    gSimpleTime += gTimer.RealTime();
01100 
01101    // Remove any setting related to submergers
01102    gProof->DeleteParameters("PROOF_UseMergers");
01103 
01104    // Check the results
01105    PutPoint();
01106    return PT_CheckSimple(gProof->GetQueryResult(), nevt, nhist);
01107 }
01108 
01109 //_____________________________________________________________________________
01110 Int_t PT_H1Http(void *)
01111 {
01112    // Test run for the H1 analysis as a chain reading the data from HTTP
01113 
01114    // Checking arguments
01115    PutPoint();
01116    if (!gProof) {
01117       printf("\n >>> Test failure: no PROOF session found\n");
01118       return -1;
01119    }
01120 
01121    // Set/unset the parallel unzip flag
01122    AssertParallelUnzip();
01123 
01124    // Create the chain
01125    PutPoint();
01126    TChain *chain = new TChain("h42");
01127 
01128    // Assert the files, if needed
01129    if (!gh1ok) {
01130       if (PT_H1AssertFiles(gh1src.Data()) != 0) {
01131          gProof->SetPrintProgress(0);
01132          printf("\n >>> Test failure: could not assert the H1 files\n");
01133          return -1;
01134       }
01135    }
01136    Int_t i = 0;
01137    for (i = 0; i < 4; i++) {
01138       chain->Add(TString::Format("%s/%s", gh1src.Data(), gh1file[i]));
01139    }
01140 
01141    // Clear the list of query results
01142    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01143 
01144    // Process
01145    PutPoint();
01146    chain->SetProof();
01147    PutPoint();
01148    gProof->SetPrintProgress(&PrintStressProgress);
01149    gTimer.Start();
01150    chain->Process(gH1Sel.Data());
01151    gTimer.Stop();
01152    gProof->SetPrintProgress(0);
01153    gProof->RemoveChain(chain);
01154 
01155    // Count
01156    gH1Cnt++;
01157    gH1Time += gTimer.RealTime();
01158 
01159    // Check the results
01160    PutPoint();
01161    return PT_CheckH1(gProof->GetQueryResult());
01162 }
01163 
01164 //_____________________________________________________________________________
01165 Int_t PT_H1FileCollection(void *arg)
01166 {
01167    // Test run for the H1 analysis as a file collection reading the data from HTTP
01168 
01169    // Checking arguments
01170    PutPoint();
01171    if (!gProof) {
01172       printf("\n >>> Test failure: no PROOF session found\n");
01173       return -1;
01174    }
01175 
01176    // Set/unset the parallel unzip flag
01177    AssertParallelUnzip();
01178 
01179    // Are we asked to change the packetizer strategy?
01180    if (arg) {
01181       PT_Packetizer_t *strategy = (PT_Packetizer_t *)arg;
01182       if (strcmp(strategy->fName, "TPacketizerAdaptive")) {
01183          gProof->SetParameter("PROOF_Packetizer", strategy->fName);
01184       } else {
01185          if (strategy->fType != 1)
01186             gProof->SetParameter("PROOF_PacketizerStrategy", strategy->fType);
01187       }
01188    }
01189 
01190    // Create the file collection
01191    PutPoint();
01192    TFileCollection *fc = new TFileCollection("h42");
01193 
01194    // Assert the files, if needed
01195    if (!gh1ok) {
01196       if (PT_H1AssertFiles(gh1src.Data()) != 0) {
01197          printf("\n >>> Test failure: could not assert the H1 files\n");
01198          return -1;
01199       }
01200    }
01201    Int_t i = 0;
01202    for (i = 0; i < 4; i++) {
01203       fc->Add(new TFileInfo(TString::Format("%s/%s", gh1src.Data(), gh1file[i])));
01204    }
01205 
01206    // Clear the list of query results
01207    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01208 
01209    // Process
01210    PutPoint();
01211    gProof->SetPrintProgress(&PrintStressProgress);
01212    gTimer.Start();
01213    gProof->Process(fc, gH1Sel.Data());
01214    gTimer.Stop();
01215    gProof->SetPrintProgress(0);
01216 
01217    // Restore settings
01218    gProof->DeleteParameters("PROOF_Packetizer");
01219    gProof->DeleteParameters("PROOF_PacketizerStrategy");
01220 
01221    // Count
01222    gH1Cnt++;
01223    gH1Time += gTimer.RealTime();
01224 
01225    // Check the results
01226    PutPoint();
01227    return PT_CheckH1(gProof->GetQueryResult());
01228 }
01229 
01230 //_____________________________________________________________________________
01231 Int_t PT_H1DataSet(void *)
01232 {
01233    // Test run for the H1 analysis as a named dataset reading the data from HTTP
01234 
01235    // Checking arguments
01236    if (!gProof) {
01237       printf("\n >>> Test failure: no PROOF session found\n");
01238       return -1;
01239    }
01240    // Not yet supported for PROOF-Lite
01241    if (gSkipDataSetTest) {
01242       return 1;
01243    }
01244    PutPoint();
01245 
01246    // Set/unset the parallel unzip flag
01247    AssertParallelUnzip();
01248 
01249    // Name for the target dataset
01250    const char *dsname = "h1dset";
01251 
01252    // Clear the list of query results
01253    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01254 
01255    // Process the dataset by name
01256    PutPoint();
01257    gProof->SetPrintProgress(&PrintStressProgress);
01258    gTimer.Start();
01259    gProof->Process(dsname, gH1Sel.Data());
01260    gTimer.Stop();
01261    gProof->SetPrintProgress(0);
01262 
01263    // Count
01264    gH1Cnt++;
01265    gH1Time += gTimer.RealTime();
01266 
01267    // Check the results
01268    PutPoint();
01269    return PT_CheckH1(gProof->GetQueryResult());
01270 }
01271 
01272 //_____________________________________________________________________________
01273 Int_t PT_H1MultiDataSet(void *)
01274 {
01275    // Test run for the H1 analysis as a named dataset reading the data from HTTP
01276 
01277    // Checking arguments
01278    if (!gProof) {
01279       printf("\n >>> Test failure: no PROOF session found\n");
01280       return -1;
01281    }
01282    // Not yet supported for PROOF-Lite
01283    if (gSkipDataSetTest) {
01284       return 1;
01285    }
01286    PutPoint();
01287 
01288    // Set/unset the parallel unzip flag
01289    AssertParallelUnzip();
01290 
01291    // Name for the target dataset
01292    const char *dsname = "h1dseta h1dsetb";
01293 
01294    // Clear the list of query results
01295    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01296 
01297    // Process the dataset by name
01298    PutPoint();
01299    gProof->SetPrintProgress(&PrintStressProgress);
01300    gTimer.Start();
01301    gProof->Process(dsname, gH1Sel.Data());
01302    gTimer.Stop();
01303    gProof->SetPrintProgress(0);
01304 
01305    // Count
01306    gH1Cnt++;
01307    gH1Time += gTimer.RealTime();
01308 
01309    // Check the results
01310    PutPoint();
01311    return PT_CheckH1(gProof->GetQueryResult());
01312 }
01313 
01314 //_____________________________________________________________________________
01315 Int_t PT_H1MultiDSetEntryList(void *)
01316 {
01317    // Test run using the H1 analysis for the multi-dataset functionality and
01318    // entry-lists
01319 
01320    // Checking arguments
01321    if (!gProof) {
01322       printf("\n >>> Test failure: no PROOF session found\n");
01323       return -1;
01324    }
01325    // Not yet supported for PROOF-Lite
01326    if (gSkipDataSetTest) {
01327       return 1;
01328    }
01329    PutPoint();
01330 
01331    // Set/unset the parallel unzip flag
01332    AssertParallelUnzip();
01333 
01334    // Multiple dataset used to create the entry list
01335    TString dsname("h1dseta|h1dsetb");
01336 
01337    // Clear the list of query results
01338    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01339 
01340    // Entry-list creation run
01341    PutPoint();
01342    gProof->SetPrintProgress(&PrintStressProgress);
01343    gTimer.Start();
01344    gProof->Process(dsname, gH1Sel.Data(), "fillList=elist.root");
01345    gTimer.Stop();
01346    gProof->SetPrintProgress(0);
01347    // Cleanup entry-list from the input list
01348    TIter nxi(gProof->GetInputList());
01349    TObject *o = 0;
01350    while ((o = nxi())) {
01351       if (!strncmp(o->GetName(), "elist", 6) || !strcmp(o->GetName(), "fillList")) {
01352          gProof->GetInputList()->Remove(o);
01353          delete o;
01354       }
01355    }
01356 
01357    // Count
01358    gH1Cnt++;
01359    gH1Time += gTimer.RealTime();
01360 
01361    // Run using the entrylist
01362    dsname = "h1dseta<<elist.root h1dsetb?enl=elist.root";
01363    PutPoint();
01364    gProof->SetPrintProgress(&PrintStressProgress);
01365    gTimer.Start();
01366    gProof->Process(dsname, gH1Sel.Data());
01367    gTimer.Stop();
01368    gProof->SetPrintProgress(0);
01369 
01370    // Unlink the entry list file
01371    gSystem->Unlink("elist.root");
01372    // Cleanup entry-list from the input list
01373    nxi.Reset();
01374    while ((o = nxi())) {
01375       if (!strncmp(o->GetName(), "elist", 6)) {
01376          gProof->GetInputList()->Remove(o);
01377          delete o;
01378       }
01379    }
01380 
01381    // Check the results
01382    PutPoint();
01383    return PT_CheckH1(gProof->GetQueryResult(), 1);
01384 }
01385 
01386 //_____________________________________________________________________________
01387 Int_t PT_DataSets(void *)
01388 {
01389    // Test dataset registration, verification, usage, removal.
01390    // Use H1 analysis files on HTTP as example
01391 
01392    // Checking arguments
01393    if (!gProof) {
01394       printf("\n >>> Test failure: no PROOF session found\n");
01395       return -1;
01396    }
01397    // Not yet supported for PROOF-Lite
01398    if (gSkipDataSetTest) {
01399       return 1;
01400    }
01401    PutPoint();
01402 
01403    // Cleanup the area
01404    PutPoint();
01405    TMap *dsm = gProof->GetDataSets();
01406    if (!dsm) {
01407       printf("\n >>> Test failure: could not retrieve map of datasets (even empty)!\n");
01408       return -1;
01409    }
01410    if (dsm->GetSize() > 0) {
01411       // Remove the datasets already registered
01412       TIter nxd(dsm);
01413       TObjString *os = 0;
01414       while ((os = (TObjString *)nxd())) {
01415          gProof->RemoveDataSet(os->GetName());
01416       }
01417       // Check the result
01418       delete dsm;
01419       dsm = gProof->GetDataSets();
01420       if (!dsm || dsm->GetSize() > 0) {
01421          printf("\n >>> Test failure: could not cleanup the dataset area! (%p)\n", dsm);
01422          delete dsm;
01423          return -1;
01424       }
01425    }
01426    delete dsm;
01427 
01428    // Create the file collection
01429    PutPoint();
01430    TFileCollection *fc = new TFileCollection();
01431    TFileCollection *fca = new TFileCollection();
01432    TFileCollection *fcb = new TFileCollection();
01433 
01434    // Assert the files, if needed
01435    if (!gh1ok) {
01436       if (PT_H1AssertFiles(gh1src.Data()) != 0) {
01437          printf("\n >>> Test failure: could not assert the H1 files\n");
01438          return -1;
01439       }
01440    }
01441    Int_t i = 0;
01442    for (i = 0; i < 4; i++) {
01443       fc->Add(new TFileInfo(TString::Format("%s/%s", gh1src.Data(), gh1file[i])));
01444       if (i < 2) {
01445          fca->Add(new TFileInfo(TString::Format("%s/%s", gh1src.Data(), gh1file[i])));
01446       } else {
01447          fcb->Add(new TFileInfo(TString::Format("%s/%s", gh1src.Data(), gh1file[i])));
01448       }
01449    }
01450    fc->Update();
01451    fca->Update();
01452    fcb->Update();
01453 
01454    // Name for this dataset
01455    const char *dsname = "h1dset";
01456    const char *dsnamea = "h1dseta";
01457    const char *dsnameb = "h1dsetb";
01458 
01459    // Register the dataset
01460    PutPoint();
01461    gProof->RegisterDataSet(dsname, fc);
01462    gProof->RegisterDataSet(dsnamea, fca);
01463    gProof->RegisterDataSet(dsnameb, fcb);
01464    // Check the result
01465    dsm = gProof->GetDataSets();
01466    if (!dsm || dsm->GetSize() != 3) {
01467       printf("\n >>> Test failure: could not register '%s,%s,%s' (%p)\n",
01468              dsname, dsnamea, dsnameb, dsm);
01469       delete dsm;
01470       return -1;
01471    }
01472    delete dsm;
01473 
01474    // Test removal
01475    PutPoint();
01476    gProof->RemoveDataSet(dsname);
01477    gProof->RemoveDataSet(dsnamea);
01478    gProof->RemoveDataSet(dsnameb);
01479    // Check the result
01480    dsm = gProof->GetDataSets();
01481    if (!dsm || dsm->GetSize() != 0) {
01482       printf("\n >>> Test failure: could not cleanup '%s,%s,%s' (%p)\n",
01483              dsname, dsnamea, dsnameb, dsm);
01484       delete dsm;
01485       return -1;
01486    }
01487    delete dsm;
01488 
01489    // Re-register the dataset
01490    PutPoint();
01491    gProof->RegisterDataSet(dsname, fc);
01492    gProof->RegisterDataSet(dsnamea, fca);
01493    gProof->RegisterDataSet(dsnameb, fcb);
01494    // Check the result
01495    dsm = gProof->GetDataSets();
01496    if (!dsm || dsm->GetSize() != 3) {
01497       printf("\n >>> Test failure: could not re-register '%s,%s,%s' (%p)\n",
01498              dsname, dsnamea, dsnameb, dsm);
01499       delete dsm;
01500       return -1;
01501    }
01502    delete dsm;
01503 
01504    // Verify the dataset
01505    PutPoint();
01506    if (gProof->VerifyDataSet(dsname) != 0) {
01507       printf("\n >>> Test failure: could not verify '%s'!\n", dsname);
01508       return -1;
01509    }
01510    if (gProof->VerifyDataSet(dsnamea) != 0) {
01511       printf("\n >>> Test failure: could not verify '%s'!\n", dsnamea);
01512       return -1;
01513    }
01514    if (gProof->VerifyDataSet(dsnameb) != 0) {
01515       printf("\n >>> Test failure: could not verify '%s'!\n", dsnameb);
01516       return -1;
01517    }
01518    gProof->ShowDataSets();
01519 
01520    // Remove the file collection
01521    delete fc;
01522    delete fca;
01523    delete fcb;
01524 
01525    // Done
01526    PutPoint();
01527    return 0;
01528 }
01529 
01530 //_____________________________________________________________________________
01531 Int_t PT_Packages(void *)
01532 {
01533    // Test package clearing, uploading, enabling, removal.
01534    // Use event.par as example.
01535 
01536    // Checking arguments
01537    PutPoint();
01538    if (!gProof) {
01539       printf("\n >>> Test failure: no PROOF session found\n");
01540       return -1;
01541    }
01542 
01543    // Cleanup the area
01544    PutPoint();
01545    TList *packs = gProof->GetListOfPackages();
01546    if (!packs) {
01547       printf("\n >>> Test failure: could not retrieve list of packages (even empty)!\n");
01548       return -1;
01549    }
01550    if (packs->GetSize() > 0) {
01551       // Remove the packages already available
01552       gProof->ClearPackages();
01553       // Check the result
01554       packs = gProof->GetListOfPackages();
01555       if (!packs || packs->GetSize() > 0) {
01556          printf("\n >>> Test failure: could not cleanup the package area!\n");
01557          return -1;
01558       }
01559    }
01560 
01561    // Name and location for this package
01562    const char *pack = "event";
01563    TString packpath("$ROOTSYS/tutorials/proof/event.par");
01564    gSystem->ExpandPathName(packpath);
01565 
01566    // Upload the package
01567    PutPoint();
01568    gProof->UploadPackage(packpath);
01569    // Check the result
01570    packs = gProof->GetListOfPackages();
01571    if (!packs || packs->GetSize() != 1) {
01572       printf("\n >>> Test failure: could not upload '%s'!\n", packpath.Data());
01573       return -1;
01574    }
01575 
01576    // Test cleanup
01577    PutPoint();
01578    gProof->ClearPackage(pack);
01579    // Check the result
01580    packs = gProof->GetListOfPackages();
01581    if (!packs || packs->GetSize() != 0) {
01582       printf("\n >>> Test failure: could not cleanup '%s'!\n", pack);
01583       return -1;
01584    }
01585 
01586    // Re-upload the package
01587    PutPoint();
01588    gProof->UploadPackage(packpath);
01589    // Check the result
01590    packs = gProof->GetListOfPackages();
01591    if (!packs || packs->GetSize() != 1) {
01592       printf("\n >>> Test failure: could not re-upload '%s'!\n", packpath.Data());
01593       return -1;
01594    }
01595 
01596    // Enable the package
01597    PutPoint();
01598    gProof->EnablePackage(pack);
01599    // Check the result
01600    packs = gProof->GetListOfEnabledPackages();
01601    if (!packs || packs->GetSize() != 1) {
01602       printf("\n >>> Test failure: could not enable '%s'!\n", pack);
01603       return -1;
01604    }
01605 
01606    // Done
01607    PutPoint();
01608    return 0;
01609 }
01610 
01611 //_____________________________________________________________________________
01612 Int_t PT_Event(void *)
01613 {
01614    // Test run for the ProofEvent analysis (see tutorials)
01615 
01616    // Checking arguments
01617    PutPoint();
01618    if (!gProof) {
01619       printf("\n >>> Test failure: no PROOF session found\n");
01620       return -1;
01621    }
01622 
01623    // Define the number of events
01624    Long64_t nevt = 100000;
01625 
01626    // Clear the list of query results
01627    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01628 
01629    // Process
01630    PutPoint();
01631    gProof->SetPrintProgress(&PrintStressProgress);
01632    gProof->Process(gEventSel.Data(), nevt);
01633    gProof->SetPrintProgress(0);
01634 
01635    // Make sure the query result is there
01636    PutPoint();
01637    TQueryResult *qr = 0;
01638    if (!(qr = gProof->GetQueryResult())) {
01639       printf("\n >>> Test failure: query result not found\n");
01640       return -1;
01641    }
01642 
01643    // Make sure the number of processed entries is the one expected
01644    PutPoint();
01645    if (qr->GetEntries() != nevt) {
01646       printf("\n >>> Test failure: wrong number of entries processed: %lld (expected %lld)\n",
01647              qr->GetEntries(), nevt);
01648       return -1;
01649    }
01650 
01651    // Make sure the output list is there
01652    PutPoint();
01653    if (!(gProof->GetOutputList())) {
01654       printf("\n >>> Test failure: output list not found\n");
01655       return -1;
01656    }
01657 
01658    // Check the 'histo'
01659    PutPoint();
01660    TH1F *histo = dynamic_cast<TH1F*>(gProof->GetOutputList()->FindObject("histo"));
01661    if (!histo) {
01662       printf("\n >>> Test failure: 'histo' not found\n");
01663       return -1;
01664    }
01665 
01666    // Check the mean values
01667    Double_t ave = histo->GetMean();
01668    Double_t rms = histo->GetRMS();
01669    if (TMath::Abs(ave - 50) > 10 * rms / TMath::Sqrt(histo->GetEntries())) {
01670       printf("\n >>> Test failure: 'histo': mean > 5 * RMS/Sqrt(N)\n");
01671       return -1;
01672    }
01673 
01674    // Done
01675    PutPoint();
01676    return 0;
01677 }
01678 
01679 //_____________________________________________________________________________
01680 Int_t PT_InputData(void *)
01681 {
01682    // Test input data functionality
01683 
01684    // Checking arguments
01685    if (!gProof) {
01686       printf("\n >>> Test failure: no PROOF session found\n");
01687       return -1;
01688    }
01689    PutPoint();
01690 
01691    // Create the test information to be send via input and retrieved
01692    TH1F *h1 = new TH1F("h1data","Input data from file",100,-5.,5.);
01693    h1->FillRandom("gaus", 1000);
01694    TList *h1list = new TList;
01695    h1list->SetName("h1list");
01696    h1list->SetOwner(kTRUE);
01697    h1list->Add(h1);
01698    h1list->Add(new TParameter<Double_t>("h1avg", h1->GetMean()));
01699    h1list->Add(new TParameter<Double_t>("h1rms", h1->GetRMS()));
01700    TString datafile = glogfile;
01701    datafile += ("_h1data.root");
01702    TFile *f = TFile::Open(datafile, "RECREATE");
01703    if (!f) {
01704       printf("\n >>> Test failure: could not open file for input data\n");
01705       return -1;
01706    }
01707    f->cd();
01708    h1list->Write(0, TObject::kSingleKey, 0);
01709    f->Close();
01710    gProof->SetInputDataFile(datafile.Data());
01711 
01712    // Histo to be sent from memory
01713    TH1F *h2 = new TH1F("h2data","Input data from memory",100,-5.,5.);
01714    h2->FillRandom("gaus", 1000);
01715    TList *h2list = new TList;
01716    h2list->SetName("h2list");
01717    h2list->SetOwner(kTRUE);
01718    h2list->Add(h2);
01719    h2list->Add(new TParameter<Double_t>("h2avg", h2->GetMean()));
01720    h2list->Add(new TParameter<Double_t>("h2rms", h2->GetRMS()));
01721    gProof->AddInputData(h2list);
01722 
01723    // Normal input parameter
01724    gProof->AddInput(new TNamed("InputObject", glogfile.Data()));
01725 
01726    // Type of test
01727    gProof->AddInput(new TNamed("ProofTests_Type", "InputData"));
01728 
01729    // Define the number of events
01730    Long64_t nevt = 1;
01731 
01732    // Clear the list of query results
01733    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01734 
01735    // Process
01736    PutPoint();
01737    gProof->SetPrintProgress(&PrintStressProgress);
01738    gProof->Process(gTestsSel.Data(), nevt);
01739    gProof->SetPrintProgress(0);
01740 
01741    // Cleanup
01742    gSystem->Unlink(datafile.Data());
01743    gProof->ClearInputData(h1list);
01744    gProof->ClearInputData(h2list);
01745    delete h1list;
01746    delete h2list;
01747 
01748    // Make sure the query result is there
01749    PutPoint();
01750    TQueryResult *qr = 0;
01751    if (!(qr = gProof->GetQueryResult())) {
01752       printf("\n >>> Test failure: query result not found\n");
01753       return -1;
01754    }
01755 
01756    // Make sure the output list is there
01757    PutPoint();
01758    if (!(gProof->GetOutputList())) {
01759       printf("\n >>> Test failure: output list not found\n");
01760       return -1;
01761    }
01762 
01763    // Check the 'histo's
01764    PutPoint();
01765    TH1I *stat = dynamic_cast<TH1I*>(gProof->GetOutputList()->FindObject("TestStat"));
01766    if (!stat) {
01767       printf("\n >>> Test failure: 'TestStat' histo not found\n");
01768       return -1;
01769    }
01770 
01771    // Test how many workers got everything successfully
01772    Int_t nw = (Int_t) stat->GetBinContent(1);
01773    PutPoint();
01774 
01775    if (TMath::Abs(stat->GetBinContent(2) - nw) > .1) {
01776       printf("\n >>> Test failure: histo 'h1' not correctly received on all workers (%.0f/%d)\n",
01777              stat->GetBinContent(2), nw);
01778       return -1;
01779    }
01780    if (TMath::Abs(stat->GetBinContent(3) - nw) > .1) {
01781       printf("\n >>> Test failure: histo 'h2' not correctly received on all workers (%.0f/%d)\n",
01782              stat->GetBinContent(3), nw);
01783       return -1;
01784    }
01785    if (TMath::Abs(stat->GetBinContent(4) - nw) > .1) {
01786       printf("\n >>> Test failure: test input object not correctly received on all workers (%.0f/%d)\n",
01787              stat->GetBinContent(4), nw);
01788       return -1;
01789    }
01790 
01791    // Done
01792    PutPoint();
01793    return 0;
01794 }
01795 
01796 //_____________________________________________________________________________
01797 Int_t PT_PackageArguments(void *)
01798 {
01799    // Testing passing arguments to packages
01800 
01801    // Checking arguments
01802    if (!gProof) {
01803       printf("\n >>> Test failure: no PROOF session found\n");
01804       return -1;
01805    }
01806    PutPoint();
01807 
01808    // Passing a 'const char *': upload packtest1
01809    const char *pack1 = "packtest1";
01810    TString pack1path("$ROOTSYS/tutorials/proof/packtest1.par");
01811    gSystem->ExpandPathName(pack1path);
01812    PutPoint();
01813    gProof->UploadPackage(pack1path);
01814    // Check the result
01815    TList *packs = gProof->GetListOfPackages();
01816    if (!packs || !packs->FindObject(pack1)) {
01817       printf("\n >>> Test failure: could not upload '%s'!\n", pack1path.Data());
01818       return -1;
01819    }
01820    // Enable the package now passing a 'const char *' argument
01821    TString arg("ProofTest.ConstChar");
01822    if (gProof->EnablePackage(pack1, arg) != 0) {
01823       printf("\n >>> Test failure: could not enable '%s' with argument: '%s'!\n", pack1path.Data(), arg.Data());
01824       return -1;
01825    }
01826 
01827    // Type of test
01828    gProof->SetParameter("ProofTests_Type", "PackTest1");
01829 
01830    // Define the number of events
01831    Long64_t nevt = 1;
01832 
01833    // Clear the list of query results
01834    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01835 
01836    // Variable to check
01837    gProof->SetParameter("testenv", arg.Data());
01838 
01839    // Process
01840    PutPoint();
01841    gProof->SetPrintProgress(&PrintStressProgress);
01842    gProof->Process(gTestsSel.Data(), nevt);
01843    gProof->SetPrintProgress(0);
01844 
01845    // Some cleanup
01846    gProof->ClearPackage(pack1);
01847    gProof->DeleteParameters("ProofTests_Type");
01848    gProof->DeleteParameters("testenv");
01849 
01850    // Make sure the query result is there
01851    PutPoint();
01852    TQueryResult *qr = 0;
01853    if (!(qr = gProof->GetQueryResult())) {
01854       printf("\n >>> Test failure: query result not found\n");
01855       return -1;
01856    }
01857 
01858    // Make sure the output list is there
01859    PutPoint();
01860    if (!(gProof->GetOutputList())) {
01861       printf("\n >>> Test failure: output list not found\n");
01862       return -1;
01863    }
01864 
01865    // Check the 'histo's
01866    PutPoint();
01867    TH1I *stat = dynamic_cast<TH1I*>(gProof->GetOutputList()->FindObject("TestStat"));
01868    if (!stat) {
01869       printf("\n >>> Test failure: 'TestStat' histo not found\n");
01870       return -1;
01871    }
01872 
01873    // Test how many workers got everything successfully
01874    Int_t nw = (Int_t) stat->GetBinContent(1);
01875    PutPoint();
01876 
01877    if (TMath::Abs(stat->GetBinContent(2) - nw) > .1) {
01878       printf("\n >>> Test failure: var '%s' not correctly set on all workers (%.0f/%d)\n",
01879              arg.Data(), stat->GetBinContent(2), nw);
01880       return -1;
01881    }
01882 
01883    // Passing a 'TList *': upload packtest2
01884    const char *pack2 = "packtest2";
01885    TString pack2path("$ROOTSYS/tutorials/proof/packtest2.par");
01886    gSystem->ExpandPathName(pack2path);
01887    PutPoint();
01888    gProof->UploadPackage(pack2path);
01889    // Check the result
01890    packs = gProof->GetListOfPackages();
01891    if (!packs || !packs->FindObject(pack2)) {
01892       printf("\n >>> Test failure: could not upload '%s'!\n", pack2path.Data());
01893       return -1;
01894    }
01895    // Create the argument list
01896    TList *argls = new TList;
01897    argls->Add(new TNamed("ProofTest.ArgOne", "2."));
01898    argls->Add(new TNamed("ProofTest.ArgTwo", "3."));
01899    argls->Add(new TNamed("ProofTest.ArgThree", "4."));
01900    // Enable the package now passing the 'TList *' argument
01901    if (gProof->EnablePackage(pack2, argls) != 0) {
01902       printf("\n >>> Test failure: could not enable '%s' with argument: '%s'!\n", pack2path.Data(), arg.Data());
01903       return -1;
01904    }
01905 
01906    // Type of test
01907    gProof->SetParameter("ProofTests_Type", "PackTest2");
01908 
01909    // Clear the list of query results
01910    if (gProof->GetQueryResults()) gProof->GetQueryResults()->Clear();
01911 
01912    // Variable to check
01913    TString envs("ProofTest.ArgOne,ProofTest.ArgTwo,ProofTest.ArgThree");
01914    gProof->SetParameter("testenv", envs.Data());
01915 
01916    // Process
01917    PutPoint();
01918    gProof->SetPrintProgress(&PrintStressProgress);
01919    gProof->Process(gTestsSel.Data(), nevt);
01920    gProof->SetPrintProgress(0);
01921 
01922    // Some cleanup
01923    gProof->ClearPackage(pack2);
01924    gProof->DeleteParameters("ProofTests_Type");
01925    gProof->DeleteParameters("testenv");
01926 
01927    // Make sure the query result is there
01928    PutPoint();
01929    qr = 0;
01930    if (!(qr = gProof->GetQueryResult())) {
01931       printf("\n >>> Test failure: query result not found\n");
01932       return -1;
01933    }
01934 
01935    // Make sure the output list is there
01936    PutPoint();
01937    if (!(gProof->GetOutputList())) {
01938       printf("\n >>> Test failure: output list not found\n");
01939       return -1;
01940    }
01941 
01942    // Check the 'histo's
01943    PutPoint();
01944    if (!(stat = dynamic_cast<TH1I*>(gProof->GetOutputList()->FindObject("TestStat")))) {
01945       printf("\n >>> Test failure: 'TestStat' histo not found\n");
01946       return -1;
01947    }
01948 
01949    // Test how many workers got everything successfully
01950    nw = (Int_t) stat->GetBinContent(1);
01951    PutPoint();
01952 
01953    if (TMath::Abs(stat->GetBinContent(2) - nw) > .1) {
01954       printf("\n >>> Test failure: var 'ProofTest.ArgOne' not correctly set on all workers (%.0f/%d)\n",
01955              stat->GetBinContent(2), nw);
01956       return -1;
01957    }
01958 
01959    if (TMath::Abs(stat->GetBinContent(3) - nw) > .1) {
01960       printf("\n >>> Test failure: var 'ProofTest.ArgTwo' not correctly set on all workers (%.0f/%d)\n",
01961              stat->GetBinContent(3), nw);
01962       return -1;
01963    }
01964 
01965    if (TMath::Abs(stat->GetBinContent(4) - nw) > .1) {
01966       printf("\n >>> Test failure: var 'ProofTest.ArgThree' not correctly set on all workers (%.0f/%d)\n",
01967              stat->GetBinContent(4), nw);
01968       return -1;
01969    }
01970 
01971    // Done
01972    PutPoint();
01973    return 0;
01974 }
01975 
01976 //_____________________________________________________________________________
01977 Int_t PT_H1SimpleAsync(void *arg)
01978 {
01979    // Test run for the H1 and Simple analysis in asynchronous mode 
01980 
01981    // Checking arguments
01982    if (!gProof) {
01983       printf("\n >>> Test failure: no PROOF session found\n");
01984       return -1;
01985    }
01986    // Not yet supported for PROOF-Lite
01987    if (gProof->IsLite()) {
01988       return 1;
01989    }
01990    PutPoint();
01991 
01992    // Set/unset the parallel unzip flag
01993    AssertParallelUnzip();
01994 
01995    // Are we asked to change the packetizer strategy?
01996    if (arg) {
01997       PT_Packetizer_t *strategy = (PT_Packetizer_t *)arg;
01998       if (strcmp(strategy->fName, "TPacketizerAdaptive")) {
01999          gProof->SetParameter("PROOF_Packetizer", strategy->fName);
02000       } else {
02001          if (strategy->fType != 1)
02002             gProof->SetParameter("PROOF_PacketizerStrategy", strategy->fType);
02003       }
02004    }
02005 
02006    // Create the file collection
02007    PutPoint();
02008    TFileCollection *fc = new TFileCollection("h42");
02009 
02010    // Assert the files, if needed
02011    if (!gh1ok) {
02012       if (PT_H1AssertFiles(gh1src.Data()) != 0) {
02013          printf("\n >>> Test failure: could not assert the H1 files\n");
02014          return -1;
02015       }
02016    }
02017    Int_t i = 0;
02018    for (i = 0; i < 4; i++) {
02019       fc->Add(new TFileInfo(TString::Format("%s/%s", gh1src.Data(), gh1file[i])));
02020    }
02021 
02022    // Clear the list of query results
02023    PutPoint();
02024    if (gProof->GetQueryResults()) {
02025       gProof->GetQueryResults()->Clear();
02026       gProof->Remove("cleanupdir");
02027    }
02028 
02029    // Submit the processing requests
02030    PutPoint();
02031    gProof->SetPrintProgress(&PrintStressProgress);
02032    gProof->Process(fc, gH1Sel.Data(), "ASYN");
02033 
02034    // Define the number of events and histos
02035    Long64_t nevt = 1000000;
02036    Int_t nhist = 16;
02037    // The number of histograms is added as parameter in the input list
02038    gProof->SetParameter("ProofSimple_NHist", (Long_t)nhist);
02039    gProof->Process(gSimpleSel.Data(), nevt, "ASYN");
02040 
02041    // Wait a bit as a function of previous runnings
02042    Double_t dtw = 10;
02043    if (gH1Cnt > 0 && gSimpleTime > 0) {
02044       dtw = gH1Time / gH1Cnt + gSimpleTime / gSimpleCnt + 1;
02045       if (dtw < 10) dtw = 10;
02046    }
02047    Int_t tw = (Int_t) (5 * dtw);
02048 
02049    gTimedOut = kFALSE;
02050    TTimeOutTimer t(tw*1000);
02051 
02052    // Wait for the processing
02053    while (!gProof->IsIdle() && !gTimedOut)
02054       gSystem->InnerLoop();
02055 
02056    gProof->SetPrintProgress(0);
02057    PutPoint();
02058 
02059    // Retrieve the list of available query results
02060    TList *ql = gProof->GetQueryResults();
02061    if (ql && ql->GetSize() > 0) {
02062       ql->Print();
02063    }
02064 
02065    TString ref;
02066    TIter nxq(ql, kIterBackward);
02067    Int_t nd = 2;
02068    TQueryResult *qr = 0;
02069    while ((qr = (TQueryResult *)nxq()) && nd > 0) {
02070       ref.Form("%s:%s", qr->GetTitle(), qr->GetName());
02071       gProof->Retrieve(ref);
02072       qr = gProof->GetQueryResult(ref);
02073       if (qr && qr->GetSelecImp()) {
02074          if (!strcmp(qr->GetSelecImp()->GetTitle(), "h1analysis")) {
02075             PutPoint();
02076             if (PT_CheckH1(qr) != 0) return -1;
02077             nd--;
02078          } else if (!strcmp(qr->GetSelecImp()->GetTitle(), "ProofSimple")) {
02079             PutPoint();
02080             if (PT_CheckSimple(qr, nevt, nhist) != 0) return -1;
02081             nd--;
02082          } else {
02083             printf("\n >>> Test failure: query with unexpected selector '%s'\n", qr->GetSelecImp()->GetTitle());
02084             return -1;
02085          }
02086       } else {
02087          printf("\n >>> Test failure: query undefined (%p) or with empty selector macro ('%s')\n", qr, ref.Data());
02088          return -1;
02089       }
02090    }
02091 
02092    // Done
02093    PutPoint();
02094    return 0;
02095 }
02096 
02097 //_____________________________________________________________________________
02098 Int_t PT_AdminFunc(void *)
02099 {
02100    // Test run for the admin functionality
02101 
02102    // Checking arguments
02103    if (!gProof) {
02104       printf("\n >>> Test failure: no PROOF session found\n");
02105       return -1;
02106    }
02107    // Not yet supported for PROOF-Lite
02108    if (gProof->IsLite()) {
02109       return 1;
02110    }
02111    PutPoint();
02112    // Attach to the manager
02113    TProofMgr *mgr = gProof->GetManager();
02114    if (!mgr) {
02115       printf("\n >>> Test failure: no PROOF manager found\n");
02116       return -1;
02117    }
02118    PutPoint();
02119    // Directory for this test
02120    TString testDir(TString::Format("%s/stressProof-Admin", gtutdir.Data()));
02121    if (gSystem->AccessPathName(testDir)) {
02122       // Create the directory
02123       if (gSystem->MakeDirectory(testDir)) {
02124          printf("\n >>> Test failure: cannot create %s\n", testDir.Data());
02125          return -1;
02126       }
02127    }
02128    // Create a small test file
02129    TMacro testMacro;
02130    testMacro.AddLine("// Test macro");
02131    testMacro.AddLine("#include \"TSystem.h\"");
02132    testMacro.AddLine("void testMacro(Int_t opt = 1)");
02133    testMacro.AddLine("{");
02134    testMacro.AddLine("   if (opt == 1) {");
02135    testMacro.AddLine("      Printf(\"Pid: \", gSystem->GetPid());");
02136    testMacro.AddLine("   }");
02137    testMacro.AddLine("}");
02138    // Save the file in the temporary area
02139    TString testFile(TString::Format("%s/testMacro.C", testDir.Data()));
02140    if (!gSystem->AccessPathName(testFile)) {
02141       // The file exists: remove it first
02142       if (gSystem->Unlink(testFile)) {
02143          printf("\n >>> Test failure: cannot unlink %s\n", testFile.Data());
02144          return -1;
02145       }
02146    }
02147    testMacro.SaveSource(testFile);
02148    FileStat_t stloc;
02149    if (gSystem->GetPathInfo(testFile, stloc) != 0) {
02150       // The file was not created
02151       printf("\n >>> Test failure: file %s was not created\n", testFile.Data());
02152       return -1;
02153    }
02154    // Reference checksum
02155    TMD5 *testMacroMd5 = testMacro.Checksum();
02156    if (!testMacroMd5) {
02157       // MD5 sum not calculated
02158       printf("\n >>> Test failure: could not calculate the md5 sum of the test macro\n");
02159       return -1;
02160    }
02161    PutPoint();
02162 
02163    // Send the file to the sandbox
02164    if (mgr->PutFile(testFile, "~/", "force") != 0) {
02165       // The file was not sent over correctly
02166       printf("\n >>> Test failure: problems sending file to master sandbox\n");
02167       return -1;
02168    }
02169    PutPoint();
02170    // Retrieve the file
02171    TString testFile1(TString::Format("%s/testMacro.cxx", testDir.Data()));
02172    if (mgr->GetFile("~/testMacro.C", testFile1, "force") != 0) {
02173       // The file was not retrieved correctly
02174       printf("\n >>> Test failure: problems retrieving file from the master sandbox\n");
02175       return -1;
02176    }
02177    PutPoint();
02178 
02179    // Test 'ls'
02180    gSystem->RedirectOutput(0, 0, &gRH);
02181    TString testLs(TString::Format("%s/testLs.log", testDir.Data()));
02182    gSystem->RedirectOutput(testLs, "w", &gRHAdmin);
02183    mgr->Ls("~/testMacro.C");
02184    gSystem->RedirectOutput(0, 0, &gRHAdmin);
02185    gSystem->RedirectOutput(glogfile, "a", &gRH);
02186    TMacro macroLs(testLs);
02187    TString testLsLine = TString::Format("%s/testMacro.C", gsandbox.Data());
02188    testLsLine.Remove(0, testLsLine.Index(".proof-tutorial")); // the first part of <tmp> maybe sligthly different
02189    if (!macroLs.GetLineWith(testLsLine)) {
02190       printf("\n >>> Test failure: Ls: output not consistent (line: '%s')\n", testLsLine.Data());
02191       return -1;
02192    }
02193    PutPoint();
02194 
02195    // Test 'more'
02196    gSystem->RedirectOutput(0, 0, &gRH);
02197    TString testMore(TString::Format("%s/testMore.log", testDir.Data()));
02198    gSystem->RedirectOutput(testMore, "w", &gRHAdmin);
02199    mgr->More("~/testMacro.C");
02200    gSystem->RedirectOutput(0, 0, &gRHAdmin);
02201    gSystem->RedirectOutput(glogfile, "a", &gRH);
02202    TMacro macroMore(testMore);
02203    if (macroMore.GetListOfLines()->GetSize() < 2) {
02204       printf("\n >>> Test failure: More output not too short: %d lines\n",
02205                                    macroMore.GetListOfLines()->GetSize());
02206       return -1;
02207    }
02208    macroMore.GetListOfLines()->Remove(macroMore.GetListOfLines()->First());
02209    macroMore.GetListOfLines()->Remove(macroMore.GetListOfLines()->First());
02210    TMD5 *testMoreMd5 = macroMore.Checksum();
02211    if (!testMoreMd5) {
02212       // MD5 sum not calculated
02213       printf("\n >>> Test failure: could not calculate the md5 sum of the 'more' result\n");
02214       return -1;
02215    }
02216    if (strcmp(testMacroMd5->AsString(), testMoreMd5->AsString())) {
02217       printf("\n >>> Test failure: More: result not consistent with reference: {%s, %s}\n",
02218                                          testMacroMd5->AsString(), testMoreMd5->AsString());
02219       return -1;
02220    }
02221    PutPoint();
02222 
02223    // Test 'stat'
02224    FileStat_t strem;
02225    if (mgr->Stat("~/testMacro.C", strem) != 0) {
02226       // Stat failure
02227       printf("\n >>> Test failure: could not stat remotely the test file\n");
02228       return -1;
02229    }
02230    if (strem.fSize != stloc.fSize) {
02231       // Stat failure
02232       printf("\n >>> Test failure: stat sizes inconsistent: %lld vs %lld (bytes)\n", strem.fSize, stloc.fSize);
02233       return -1;
02234    }
02235    PutPoint();
02236 
02237    // Test 'cp' and 'md5sum;
02238    if (mgr->Cp("http://root.cern.ch/files/h1/dstarmb.root", "~/") != 0) {
02239       // Cp failure
02240       printf("\n >>> Test failure: could not retrieve remotely dstarmb.root from the Root Web server\n");
02241       return -1;
02242    }
02243    TString sum;
02244    if (mgr->Md5sum("~/dstarmb.root", sum) != 0) {
02245       // MD5
02246       printf("\n >>> Test failure: calculating the md5sum of dstarmb.root\n");
02247       return -1;
02248    }
02249    if (sum != "0a60055370e16d954f90fb50c2d1a801") {
02250       // MD5 wrong
02251       printf("\n >>> Test failure: wrong value for md5sum of dstarmb.root: %s\n", sum.Data());
02252       return -1;
02253    }
02254    PutPoint();
02255 
02256    // Clean up sums
02257    SafeDelete(testMoreMd5);
02258    SafeDelete(testMacroMd5);
02259 
02260    // Done
02261    PutPoint();
02262    return 0;
02263 
02264 }

Generated on Tue Jul 5 15:15:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1