ProofTests.C

Go to the documentation of this file.
00001 #define ProofTests_cxx
00002 
00003 //////////////////////////////////////////////////////////
00004 //
00005 // Auxilliary TSelector used to test PROOF functionality
00006 //
00007 //////////////////////////////////////////////////////////
00008 
00009 #include "ProofTests.h"
00010 #include <TEnv.h>
00011 #include <TH1F.h>
00012 #include <TH1I.h>
00013 #include <TMath.h>
00014 #include <TString.h>
00015 #include <TSystem.h>
00016 #include <TParameter.h>
00017 
00018 //_____________________________________________________________________________
00019 ProofTests::ProofTests()
00020 {
00021    // Constructor
00022 
00023    fTestType = 0;
00024    fStat = 0;
00025 }
00026 
00027 //_____________________________________________________________________________
00028 ProofTests::~ProofTests()
00029 {
00030    // Destructor
00031 
00032 }
00033 
00034 //_____________________________________________________________________________
00035 void ProofTests::ParseInput()
00036 {
00037    // This function sets some control member variables based on the input list
00038    // content. Called by Begin and SlaveBegin.
00039 
00040    // Determine the test type
00041    TNamed *ntype = dynamic_cast<TNamed*>(fInput->FindObject("ProofTests_Type"));
00042    if (ntype) {
00043       if (!strcmp(ntype->GetTitle(), "InputData")) {
00044          fTestType = 0;
00045       } else if (!strcmp(ntype->GetTitle(), "PackTest1")) {
00046          fTestType = 1;
00047       } else if (!strcmp(ntype->GetTitle(), "PackTest2")) {
00048          fTestType = 2;
00049       } else {
00050          Warning("ParseInput", "unknown type: '%s'", ntype->GetTitle());
00051       }
00052    }
00053    Info("ParseInput", "test type: %d (from '%s')", fTestType, ntype ? ntype->GetTitle() : "undef");
00054 }
00055 
00056 //_____________________________________________________________________________
00057 void ProofTests::Begin(TTree * /*tree*/)
00058 {
00059    // The Begin() function is called at the start of the query.
00060    // When running with PROOF Begin() is only called on the client.
00061    // The tree argument is deprecated (on PROOF 0 is passed).
00062 
00063    // Fill relevant members
00064    ParseInput();
00065 }
00066 
00067 //_____________________________________________________________________________
00068 void ProofTests::SlaveBegin(TTree * /*tree*/)
00069 {
00070    // The SlaveBegin() function is called after the Begin() function.
00071    // When running with PROOF SlaveBegin() is called on each slave server.
00072    // The tree argument is deprecated (on PROOF 0 is passed).
00073 
00074    TString option = GetOption();
00075 
00076    // Fill relevant members
00077    ParseInput();
00078 
00079    // Output histo
00080    fStat = new TH1I("TestStat", "Test results", 20, .5, 20.5);
00081    fOutput->Add(fStat);
00082 
00083    // We were started
00084    fStat->Fill(1.);
00085 
00086    // Depends on the test
00087    if (fTestType == 0) {
00088       // Retrieve objects from the input list and copy them to the output
00089       // H1
00090       TList *h1list = dynamic_cast<TList*>(fInput->FindObject("h1list"));
00091       if (h1list) {
00092          // Retrieve objects from the input list and copy them to the output
00093          TH1F *h1 = dynamic_cast<TH1F*>(h1list->FindObject("h1data"));
00094          if (h1) {
00095             TParameter<Double_t> *h1avg = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1avg"));
00096             TParameter<Double_t> *h1rms = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1rms"));
00097             if (h1avg && h1rms) {
00098                if (TMath::Abs(h1avg->GetVal() - h1->GetMean()) < 0.0001) {
00099                   if (TMath::Abs(h1rms->GetVal() - h1->GetRMS()) < 0.0001) {
00100                      fStat->Fill(2.);
00101                   }
00102                }
00103             } else {
00104                Info("SlaveBegin", "%d: info 'h1avg' or 'h1rms' not found!", fTestType);
00105             }
00106          } else {
00107             Info("SlaveBegin", "%d: input histo 'h1data' not found!", fTestType);
00108          }
00109       } else {
00110          Info("SlaveBegin", "%d: input list 'h1list' not found!", fTestType);
00111       }
00112       // H2
00113       TList *h2list = dynamic_cast<TList*>(fInput->FindObject("h2list"));
00114       if (h2list) {
00115          // Retrieve objects from the input list and copy them to the output
00116          TH1F *h2 = dynamic_cast<TH1F*>(h2list->FindObject("h2data"));
00117          if (h2) {
00118             TParameter<Double_t> *h2avg = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2avg"));
00119             TParameter<Double_t> *h2rms = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2rms"));
00120             if (h2avg && h2rms) {
00121                if (TMath::Abs(h2avg->GetVal() - h2->GetMean()) < 0.0001) {
00122                   if (TMath::Abs(h2rms->GetVal() - h2->GetRMS()) < 0.0001) {
00123                      fStat->Fill(3.);
00124                   }
00125                }
00126             } else {
00127                Info("SlaveBegin", "%d: info 'h2avg' or 'h2rms' not found!", fTestType);
00128             }
00129          } else {
00130             Info("SlaveBegin", "%d: input histo 'h2data' not found!", fTestType);
00131          }
00132       } else {
00133          Info("SlaveBegin", "%d: input list 'h2list' not found!", fTestType);
00134       }
00135 
00136       TNamed *iob = dynamic_cast<TNamed*>(fInput->FindObject("InputObject"));
00137       if (iob) {
00138          fStat->Fill(4.);
00139       } else {
00140          Info("SlaveBegin", "%d: input histo 'InputObject' not found!", fTestType);
00141       }
00142    } else if (fTestType == 1) {
00143       // We should find in the input list the name of a test variable which should exist
00144       // at this point in the gEnv table
00145       TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
00146       if (nm) {
00147          if (gEnv->Lookup(nm->GetTitle())) fStat->Fill(2.);
00148       } else {
00149          Info("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
00150       }
00151    } else if (fTestType == 2) {
00152       // We should find in the input list the list of names of test variables which should exist
00153       // at this point in the gEnv table
00154       TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
00155       if (nm) {
00156          TString nms(nm->GetTitle()), nam;
00157          Int_t from = 0;
00158          while (nms.Tokenize(nam, from, ",")) {
00159             if (gEnv->Lookup(nam)) {
00160                Double_t xx = gEnv->GetValue(nam, -1.);
00161                if (xx > 1.) fStat->Fill(xx);
00162             }
00163          }
00164       } else {
00165          Info("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
00166       }
00167    }
00168 }
00169 
00170 //_____________________________________________________________________________
00171 Bool_t ProofTests::Process(Long64_t)
00172 {
00173    // The Process() function is called for each entry in the tree (or possibly
00174    // keyed object in the case of PROOF) to be processed. The entry argument
00175    // specifies which entry in the currently loaded tree is to be processed.
00176    // It can be passed to either ProofTests::GetEntry() or TBranch::GetEntry()
00177    // to read either all or the required parts of the data. When processing
00178    // keyed objects with PROOF, the object is already loaded and is available
00179    // via the fObject pointer.
00180    //
00181    // This function should contain the "body" of the analysis. It can contain
00182    // simple or elaborate selection criteria, run algorithms on the data
00183    // of the event and typically fill histograms.
00184    //
00185    // The processing can be stopped by calling Abort().
00186    //
00187    // Use fStatus to set the return value of TTree::Process().
00188    //
00189    // The return value is currently not used.
00190 
00191    return kTRUE;
00192 }
00193 
00194 //_____________________________________________________________________________
00195 void ProofTests::SlaveTerminate()
00196 {
00197    // The SlaveTerminate() function is called after all entries or objects
00198    // have been processed. When running with PROOF SlaveTerminate() is called
00199    // on each slave server.
00200 
00201 }
00202 
00203 //_____________________________________________________________________________
00204 void ProofTests::Terminate()
00205 {
00206    // The Terminate() function is the last function to be called during
00207    // a query. It always runs on the client, it can be used to present
00208    // the results graphically or save the results to file.
00209 
00210 }

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