Logo ROOT   6.14/05
Reference Guide
ProofTests.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_ProofTests
3 ///
4 /// Auxilliary selector used to test PROOF functionality
5 ///
6 /// \macro_code
7 ///
8 /// \author Gerardo Ganis (gerardo.ganis@cern.ch)
9 
10 #define ProofTests_cxx
11 
12 #include "ProofTests.h"
13 #include <TEnv.h>
14 #include <TH1F.h>
15 #include <TH1I.h>
16 #include <TMath.h>
17 #include <TString.h>
18 #include <TSystem.h>
19 #include <TParameter.h>
20 
21 //_____________________________________________________________________________
22 ProofTests::ProofTests()
23 {
24  // Constructor
25 
26  fTestType = 0;
27  fStat = 0;
28 }
29 
30 //_____________________________________________________________________________
31 ProofTests::~ProofTests()
32 {
33  // Destructor
34 
35 }
36 
37 //_____________________________________________________________________________
38 void ProofTests::ParseInput()
39 {
40  // This function sets some control member variables based on the input list
41  // content. Called by Begin and SlaveBegin.
42 
43  // Determine the test type
44  TNamed *ntype = dynamic_cast<TNamed*>(fInput->FindObject("ProofTests_Type"));
45  if (ntype) {
46  if (!strcmp(ntype->GetTitle(), "InputData")) {
47  fTestType = 0;
48  } else if (!strcmp(ntype->GetTitle(), "PackTest1")) {
49  fTestType = 1;
50  } else if (!strcmp(ntype->GetTitle(), "PackTest2")) {
51  fTestType = 2;
52  } else {
53  Warning("ParseInput", "unknown type: '%s'", ntype->GetTitle());
54  }
55  }
56  Info("ParseInput", "test type: %d (from '%s')", fTestType, ntype ? ntype->GetTitle() : "undef");
57 }
58 
59 //_____________________________________________________________________________
60 void ProofTests::Begin(TTree * /*tree*/)
61 {
62  // The Begin() function is called at the start of the query.
63  // When running with PROOF Begin() is only called on the client.
64  // The tree argument is deprecated (on PROOF 0 is passed).
65 }
66 
67 //_____________________________________________________________________________
68 void ProofTests::SlaveBegin(TTree * /*tree*/)
69 {
70  // The SlaveBegin() function is called after the Begin() function.
71  // When running with PROOF SlaveBegin() is called on each slave server.
72  // The tree argument is deprecated (on PROOF 0 is passed).
73 
74  TString option = GetOption();
75 
76  // Fill relevant members
77  ParseInput();
78 
79  // Output histo
80  fStat = new TH1I("TestStat", "Test results", 20, .5, 20.5);
81  fOutput->Add(fStat);
82 
83  // We were started
84  fStat->Fill(1.);
85 
86  // Depends on the test
87  if (fTestType == 0) {
88  // Retrieve objects from the input list and copy them to the output
89  // H1
90  TList *h1list = dynamic_cast<TList*>(fInput->FindObject("h1list"));
91  if (h1list) {
92  // Retrieve objects from the input list and copy them to the output
93  TH1F *h1 = dynamic_cast<TH1F*>(h1list->FindObject("h1data"));
94  if (h1) {
95  TParameter<Double_t> *h1avg = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1avg"));
96  TParameter<Double_t> *h1rms = dynamic_cast<TParameter<Double_t>*>(h1list->FindObject("h1rms"));
97  if (h1avg && h1rms) {
98  if (TMath::Abs(h1avg->GetVal() - h1->GetMean()) < 0.0001) {
99  if (TMath::Abs(h1rms->GetVal() - h1->GetRMS()) < 0.0001) {
100  fStat->Fill(2.);
101  }
102  }
103  } else {
104  Warning("SlaveBegin", "%d: info 'h1avg' or 'h1rms' not found!", fTestType);
105  }
106  } else {
107  Warning("SlaveBegin", "%d: input histo 'h1data' not found!", fTestType);
108  }
109  } else {
110  Warning("SlaveBegin", "%d: input list 'h1list' not found!", fTestType);
111  }
112  // H2
113  TList *h2list = dynamic_cast<TList*>(fInput->FindObject("h2list"));
114  if (h2list) {
115  // Retrieve objects from the input list and copy them to the output
116  TH1F *h2 = dynamic_cast<TH1F*>(h2list->FindObject("h2data"));
117  if (h2) {
118  TParameter<Double_t> *h2avg = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2avg"));
119  TParameter<Double_t> *h2rms = dynamic_cast<TParameter<Double_t>*>(h2list->FindObject("h2rms"));
120  if (h2avg && h2rms) {
121  if (TMath::Abs(h2avg->GetVal() - h2->GetMean()) < 0.0001) {
122  if (TMath::Abs(h2rms->GetVal() - h2->GetRMS()) < 0.0001) {
123  fStat->Fill(3.);
124  }
125  }
126  } else {
127  Warning("SlaveBegin", "%d: info 'h2avg' or 'h2rms' not found!", fTestType);
128  }
129  } else {
130  Warning("SlaveBegin", "%d: input histo 'h2data' not found!", fTestType);
131  }
132  } else {
133  Warning("SlaveBegin", "%d: input list 'h2list' not found!", fTestType);
134  }
135 
136  TNamed *iob = dynamic_cast<TNamed*>(fInput->FindObject("InputObject"));
137  if (iob) {
138  fStat->Fill(4.);
139  } else {
140  Warning("SlaveBegin", "%d: input histo 'InputObject' not found!", fTestType);
141  }
142  } else if (fTestType == 1) {
143  // We should find in the input list the name of a test variable which should exist
144  // at this point in the gEnv table
145  TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
146  if (nm) {
147  if (gEnv->Lookup(nm->GetTitle())) {
148  fStat->Fill(2.);
149  } else {
150  Warning("SlaveBegin", "%d: lookup for '%s' failed!", fTestType, nm->GetTitle());
151  gEnv->Print();
152  }
153  } else {
154  Warning("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
155  }
156  } else if (fTestType == 2) {
157  // We should find in the input list the list of names of test variables which should exist
158  // at this point in the gEnv table
159  TNamed *nm = dynamic_cast<TNamed*>(fInput->FindObject("testenv"));
160  if (nm) {
161  TString nms(nm->GetTitle()), nam;
162  Int_t from = 0;
163  while (nms.Tokenize(nam, from, ",")) {
164  if (gEnv->Lookup(nam)) {
165  Double_t xx = gEnv->GetValue(nam, -1.);
166  if (xx > 1.) fStat->Fill(xx);
167  } else {
168  Warning("SlaveBegin", "RC-env '%s' not found!", nam.Data());
169  }
170  }
171  } else {
172  Warning("SlaveBegin", "%d: TNamed with the test env info not found!", fTestType);
173  }
174  }
175 }
176 
177 //_____________________________________________________________________________
178 Bool_t ProofTests::Process(Long64_t)
179 {
180  // The Process() function is called for each entry in the tree (or possibly
181  // keyed object in the case of PROOF) to be processed. The entry argument
182  // specifies which entry in the currently loaded tree is to be processed.
183  // It can be passed to either ProofTests::GetEntry() or TBranch::GetEntry()
184  // to read either all or the required parts of the data. When processing
185  // keyed objects with PROOF, the object is already loaded and is available
186  // via the fObject pointer.
187  //
188  // This function should contain the "body" of the analysis. It can contain
189  // simple or elaborate selection criteria, run algorithms on the data
190  // of the event and typically fill histograms.
191  //
192  // The processing can be stopped by calling Abort().
193  //
194  // Use fStatus to set the return value of TTree::Process().
195  //
196  // The return value is currently not used.
197 
198  return kTRUE;
199 }
200 
201 //_____________________________________________________________________________
202 void ProofTests::SlaveTerminate()
203 {
204  // The SlaveTerminate() function is called after all entries or objects
205  // have been processed. When running with PROOF SlaveTerminate() is called
206  // on each slave server.
207 
208 }
209 
210 //_____________________________________________________________________________
211 void ProofTests::Terminate()
212 {
213  // The Terminate() function is the last function to be called during
214  // a query. It always runs on the client, it can be used to present
215  // the results graphically or save the results to file.
216 
217 }
void Begin(Int_t type)
THist< 1, int, THistStatContent > TH1I
Definition: THist.hxx:287
long long Long64_t
Definition: RtypesCore.h:69
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition: TH1.cxx:6930
Basic string class.
Definition: TString.h:131
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t GetRMS(Int_t axis=1) const
Definition: TH1.h:310
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
Definition: TList.cxx:574
Auxilliary selector used to test PROOF functionality.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual TEnvRec * Lookup(const char *n) const
Loop over all resource records and return the one with name.
Definition: TEnv.cxx:547
void Info(const char *location, const char *msgfmt,...)
TH1F * h1
Definition: legend1.C:5
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
Definition: TEnv.cxx:556
A doubly linked list.
Definition: TList.h:44
Named parameter, streamable and storable.
Definition: TParameter.h:37
void Warning(const char *location, const char *msgfmt,...)
static constexpr double nm
double Double_t
Definition: RtypesCore.h:55
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
A TTree object has a header with a name and a title.
Definition: TTree.h:70
const AParamType & GetVal() const
Definition: TParameter.h:69
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48