From $ROOTSYS/tutorials/proof/ProofTests.C

#define ProofTests_cxx

//////////////////////////////////////////////////////////
//
// Auxilliary TSelector used to test PROOF functionality
//
//////////////////////////////////////////////////////////

#include "ProofTests.h"
#include <TEnv.h>
#include <TH1F.h>
#include <TH1I.h>
#include <TMath.h>
#include <TString.h>
#include <TSystem.h>
#include <TParameter.h>

//_____________________________________________________________________________
ProofTests::ProofTests()
{
   // Constructor

   fTestType = 0;
   fStat = 0;
}

//_____________________________________________________________________________
ProofTests::~ProofTests()
{
   // Destructor

}

//_____________________________________________________________________________
void ProofTests::ParseInput()
{
   // This function sets some control member variables based on the input list
   // content. Called by Begin and SlaveBegin.

   // Determine the test type
   TNamed *ntype = dynamic_cast<TNamed*>(fInput->FindObject("ProofTests_Type"));
   if (ntype) {
      if (!strcmp(ntype->GetTitle(), "InputData")) {
         fTestType = 0;
      } else if (!strcmp(ntype->GetTitle(), "PackTest1")) {
         fTestType = 1;
      } else if (!strcmp(ntype->GetTitle(), "PackTest2")) {
         fTestType = 2;
      } else {
         Warning("ParseInput", "unknown type: '%s'", ntype->GetTitle());
      }
   }
   Info("ParseInput", "test type: %d (from '%s')", fTestType, ntype ? ntype->GetTitle() : "undef");
}

//_____________________________________________________________________________
void ProofTests::Begin(TTree * /*tree*/)
{
   // The Begin() function is called at the start of the query.
   // When running with PROOF Begin() is only called on the client.
   // The tree argument is deprecated (on PROOF 0 is passed).
}

//_____________________________________________________________________________
void ProofTests::SlaveBegin(TTree * /*tree*/)
{
   // The SlaveBegin() function is called after the Begin() function.
   // When running with PROOF SlaveBegin() is called on each slave server.
   // The tree argument is deprecated (on PROOF 0 is passed).

   TString option = GetOption();

   // Fill relevant members
   ParseInput();

   // Output histo
   fStat = new TH1I("TestStat", "Test results", 20, .5, 20.5);
   fOutput->Add(fStat);

   // We were started
   fStat->Fill(1.);

   // Depends on the test
   if (fTestType == 0) {
      // Retrieve objects from the input list and copy them to the output
      // H1
      TList *h1list = dynamic_cast<TList*>(fInput->FindObject("h1list"));
      if (h1list) {
         // Retrieve objects from the input list and copy them to the output
         TH1F *h1 = dynamic_cast<TH1F*>(h1list->FindObject("h1data"));
         if (h1) {
            TParameter<Double_t> *h1avg = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1avg"));
            TParameter<Double_t> *h1rms = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1rms"));
            if (h1avg && h1rms) {
               if (TMath::Abs(h1avg->GetVal() - h1->GetMean()) < 0.0001) {
                  if (TMath::Abs(h1rms->GetVal() - h1->GetRMS()) < 0.0001) {
                     fStat->Fill(2.);
                  }
               }
            } else {
               Warning("SlaveBegin", "%d: info 'h1avg' or 'h1rms' not found!", fTestType);
            }
         } else {
            Warning("SlaveBegin", "%d: input histo 'h1data' not found!", fTestType);
         }
      } else {
         Warning("SlaveBegin", "%d: input list 'h1list' not found!", fTestType);
      }
      // H2
      TList *h2list = dynamic_cast<TList*>(fInput->FindObject("h2list"));
      if (h2list) {
         // Retrieve objects from the input list and copy them to the output
         TH1F *h2 = dynamic_cast<TH1F*>(h2list->FindObject("h2data"));
         if (h2) {
            TParameter<Double_t> *h2avg = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2avg"));
            TParameter<Double_t> *h2rms = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2rms"));
            if (h2avg && h2rms) {
               if (TMath::Abs(h2avg->GetVal() - h2->GetMean()) < 0.0001) {
                  if (TMath::Abs(h2rms->GetVal() - h2->GetRMS()) < 0.0001) {
                     fStat->Fill(3.);
                  }
               }
            } else {
               Warning("SlaveBegin", "%d: info 'h2avg' or 'h2rms' not found!", fTestType);
            }
         } else {
            Warning("SlaveBegin", "%d: input histo 'h2data' not found!", fTestType);
         }
      } else {
         Warning("SlaveBegin", "%d: input list 'h2list' not found!", fTestType);
      }

      TNamed *iob = dynamic_cast<TNamed*>(fInput->FindObject("InputObject"));
      if (iob) {
         fStat->Fill(4.);
      } else {
         Warning("SlaveBegin", "%d: input histo 'InputObject' not found!", fTestType);
      }
   } else if (fTestType == 1) {
      // We should find in the input list the name of a test variable which should exist
      // at this point in the gEnv table
      TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
      if (nm) {
         if (gEnv->Lookup(nm->GetTitle())) {
            fStat->Fill(2.);
         } else {
            Warning("SlaveBegin", "%d: lookup for '%s' failed!", fTestType, nm->GetTitle());
            gEnv->Print();
         }
      } else {
         Warning("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
      }
   } else if (fTestType == 2) {
      // We should find in the input list the list of names of test variables which should exist
      // at this point in the gEnv table
      TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
      if (nm) {
         TString nms(nm->GetTitle()), nam;
         Int_t from = 0;
         while (nms.Tokenize(nam, from, ",")) {
            if (gEnv->Lookup(nam)) {
               Double_t xx = gEnv->GetValue(nam, -1.);
               if (xx > 1.) fStat->Fill(xx);
            } else {
               Warning("SlaveBegin", "RC-env '%s' not found!", nam.Data());
            }
         }
      } else {
         Warning("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
      }
   }
}

//_____________________________________________________________________________
Bool_t ProofTests::Process(Long64_t)
{
   // The Process() function is called for each entry in the tree (or possibly
   // keyed object in the case of PROOF) to be processed. The entry argument
   // specifies which entry in the currently loaded tree is to be processed.
   // It can be passed to either ProofTests::GetEntry() or TBranch::GetEntry()
   // to read either all or the required parts of the data. When processing
   // keyed objects with PROOF, the object is already loaded and is available
   // via the fObject pointer.
   //
   // This function should contain the "body" of the analysis. It can contain
   // simple or elaborate selection criteria, run algorithms on the data
   // of the event and typically fill histograms.
   //
   // The processing can be stopped by calling Abort().
   //
   // Use fStatus to set the return value of TTree::Process().
   //
   // The return value is currently not used.

   return kTRUE;
}

//_____________________________________________________________________________
void ProofTests::SlaveTerminate()
{
   // The SlaveTerminate() function is called after all entries or objects
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.

}

//_____________________________________________________________________________
void ProofTests::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.

}
 ProofTests.C:1
 ProofTests.C:2
 ProofTests.C:3
 ProofTests.C:4
 ProofTests.C:5
 ProofTests.C:6
 ProofTests.C:7
 ProofTests.C:8
 ProofTests.C:9
 ProofTests.C:10
 ProofTests.C:11
 ProofTests.C:12
 ProofTests.C:13
 ProofTests.C:14
 ProofTests.C:15
 ProofTests.C:16
 ProofTests.C:17
 ProofTests.C:18
 ProofTests.C:19
 ProofTests.C:20
 ProofTests.C:21
 ProofTests.C:22
 ProofTests.C:23
 ProofTests.C:24
 ProofTests.C:25
 ProofTests.C:26
 ProofTests.C:27
 ProofTests.C:28
 ProofTests.C:29
 ProofTests.C:30
 ProofTests.C:31
 ProofTests.C:32
 ProofTests.C:33
 ProofTests.C:34
 ProofTests.C:35
 ProofTests.C:36
 ProofTests.C:37
 ProofTests.C:38
 ProofTests.C:39
 ProofTests.C:40
 ProofTests.C:41
 ProofTests.C:42
 ProofTests.C:43
 ProofTests.C:44
 ProofTests.C:45
 ProofTests.C:46
 ProofTests.C:47
 ProofTests.C:48
 ProofTests.C:49
 ProofTests.C:50
 ProofTests.C:51
 ProofTests.C:52
 ProofTests.C:53
 ProofTests.C:54
 ProofTests.C:55
 ProofTests.C:56
 ProofTests.C:57
 ProofTests.C:58
 ProofTests.C:59
 ProofTests.C:60
 ProofTests.C:61
 ProofTests.C:62
 ProofTests.C:63
 ProofTests.C:64
 ProofTests.C:65
 ProofTests.C:66
 ProofTests.C:67
 ProofTests.C:68
 ProofTests.C:69
 ProofTests.C:70
 ProofTests.C:71
 ProofTests.C:72
 ProofTests.C:73
 ProofTests.C:74
 ProofTests.C:75
 ProofTests.C:76
 ProofTests.C:77
 ProofTests.C:78
 ProofTests.C:79
 ProofTests.C:80
 ProofTests.C:81
 ProofTests.C:82
 ProofTests.C:83
 ProofTests.C:84
 ProofTests.C:85
 ProofTests.C:86
 ProofTests.C:87
 ProofTests.C:88
 ProofTests.C:89
 ProofTests.C:90
 ProofTests.C:91
 ProofTests.C:92
 ProofTests.C:93
 ProofTests.C:94
 ProofTests.C:95
 ProofTests.C:96
 ProofTests.C:97
 ProofTests.C:98
 ProofTests.C:99
 ProofTests.C:100
 ProofTests.C:101
 ProofTests.C:102
 ProofTests.C:103
 ProofTests.C:104
 ProofTests.C:105
 ProofTests.C:106
 ProofTests.C:107
 ProofTests.C:108
 ProofTests.C:109
 ProofTests.C:110
 ProofTests.C:111
 ProofTests.C:112
 ProofTests.C:113
 ProofTests.C:114
 ProofTests.C:115
 ProofTests.C:116
 ProofTests.C:117
 ProofTests.C:118
 ProofTests.C:119
 ProofTests.C:120
 ProofTests.C:121
 ProofTests.C:122
 ProofTests.C:123
 ProofTests.C:124
 ProofTests.C:125
 ProofTests.C:126
 ProofTests.C:127
 ProofTests.C:128
 ProofTests.C:129
 ProofTests.C:130
 ProofTests.C:131
 ProofTests.C:132
 ProofTests.C:133
 ProofTests.C:134
 ProofTests.C:135
 ProofTests.C:136
 ProofTests.C:137
 ProofTests.C:138
 ProofTests.C:139
 ProofTests.C:140
 ProofTests.C:141
 ProofTests.C:142
 ProofTests.C:143
 ProofTests.C:144
 ProofTests.C:145
 ProofTests.C:146
 ProofTests.C:147
 ProofTests.C:148
 ProofTests.C:149
 ProofTests.C:150
 ProofTests.C:151
 ProofTests.C:152
 ProofTests.C:153
 ProofTests.C:154
 ProofTests.C:155
 ProofTests.C:156
 ProofTests.C:157
 ProofTests.C:158
 ProofTests.C:159
 ProofTests.C:160
 ProofTests.C:161
 ProofTests.C:162
 ProofTests.C:163
 ProofTests.C:164
 ProofTests.C:165
 ProofTests.C:166
 ProofTests.C:167
 ProofTests.C:168
 ProofTests.C:169
 ProofTests.C:170
 ProofTests.C:171
 ProofTests.C:172
 ProofTests.C:173
 ProofTests.C:174
 ProofTests.C:175
 ProofTests.C:176
 ProofTests.C:177
 ProofTests.C:178
 ProofTests.C:179
 ProofTests.C:180
 ProofTests.C:181
 ProofTests.C:182
 ProofTests.C:183
 ProofTests.C:184
 ProofTests.C:185
 ProofTests.C:186
 ProofTests.C:187
 ProofTests.C:188
 ProofTests.C:189
 ProofTests.C:190
 ProofTests.C:191
 ProofTests.C:192
 ProofTests.C:193
 ProofTests.C:194
 ProofTests.C:195
 ProofTests.C:196
 ProofTests.C:197
 ProofTests.C:198
 ProofTests.C:199
 ProofTests.C:200
 ProofTests.C:201
 ProofTests.C:202
 ProofTests.C:203
 ProofTests.C:204
 ProofTests.C:205
 ProofTests.C:206
 ProofTests.C:207
 ProofTests.C:208
 ProofTests.C:209
 ProofTests.C:210
 ProofTests.C:211
 ProofTests.C:212
 ProofTests.C:213
 ProofTests.C:214
 ProofTests.C:215