Logo ROOT  
Reference Guide
TSimpleAnalysis.h
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Luca Giommi 22/08/16
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TSimpleAnalysis
13 #define ROOT_TSimpleAnalysis
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TSimpleAnalysis //
18 // //
19 // A TSimpleAnalysis object creates histograms from a TChain. These //
20 // histograms are stored to an output file. The histogrammed //
21 // (TTreeFormula) expressions, their cuts, the input and output files //
22 // are configured through a simple config file that allows comments //
23 // starting with '#'. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 
28 #include <string>
29 #include <fstream>
30 #include <vector>
31 #include <map>
32 
34 
35 private:
36  std::string fConfigFile; ///< Name of the configuration file
37  std::vector<std::string> fInputFiles; ///< .root input files
38  std::string fOutputFile; ///< Output file in which are stored the histograms
39  std::string fTreeName; ///< Name of the input tree
40  std::ifstream fIn; ///< Stream for the input file
41 
42  //The map contains in the first part the names of the histograms written in the output file, in the
43  //second part the pair of what is shown in the histograms and the cut applied on the variables
44  std::map<std::string, std::pair<std::string, std::string>> fHists;
45 
46  //The elements of the enumeration refer to the different types of elements
47  //that are in the input file
48  enum EReadingWhat {
49  kReadingOutput, ///< Reading the name of the output file
50  kReadingTreeName, ///< Reading the name of the tree
51  kReadingInput, ///< Reading the name of the .root input files
52  kReadingExpressions ///< Reading the expressions
53  };
54 
55  std::string HandleExpressionConfig(const std::string& line);
56  std::string GetLine(int& numbLine);
57  bool HandleInputFileNameConfig(const std::string& line);
58  bool SetTreeName();
59 
60 
61 public:
62  TSimpleAnalysis(const std::string& file): fConfigFile (file) {}
63  TSimpleAnalysis(const std::string& output, const std::vector<std::string>& inputFiles,
64  const std::vector<std::string>& expressions, const std::string& treeName);
65  bool Run();
66  bool Configure();
67 
68 };
69 
70 bool RunSimpleAnalysis(const char* configurationFile);
71 
72 #endif
TSimpleAnalysis::kReadingInput
@ kReadingInput
Reading the name of the .root input files.
Definition: TSimpleAnalysis.h:51
TSimpleAnalysis::fTreeName
std::string fTreeName
Name of the input tree.
Definition: TSimpleAnalysis.h:39
output
static void output(int code)
Definition: gifencode.c:226
TSimpleAnalysis
A TSimpleAnalysis object creates histograms from a TChain.
Definition: TSimpleAnalysis.h:33
TSimpleAnalysis::HandleExpressionConfig
std::string HandleExpressionConfig(const std::string &line)
Handle the expression lines of the input file in order to pass the elements to the members of the obj...
Definition: TSimpleAnalysis.cxx:98
TSimpleAnalysis::Run
bool Run()
Execute all the TChain::Draw() as configured and stores the output histograms.
Definition: TSimpleAnalysis.cxx:264
TSimpleAnalysis::fIn
std::ifstream fIn
Stream for the input file.
Definition: TSimpleAnalysis.h:40
RunSimpleAnalysis
bool RunSimpleAnalysis(const char *configurationFile)
Function that allows to create the TSimpleAnalysis object and execute its Configure and Analyze funct...
Definition: TSimpleAnalysis.cxx:478
TSimpleAnalysis::Configure
bool Configure()
This function has the aim of setting the arguments read from the input file.
Definition: TSimpleAnalysis.cxx:414
TSimpleAnalysis::fInputFiles
std::vector< std::string > fInputFiles
.root input files
Definition: TSimpleAnalysis.h:37
TSimpleAnalysis::fOutputFile
std::string fOutputFile
Output file in which are stored the histograms.
Definition: TSimpleAnalysis.h:38
TSimpleAnalysis::EReadingWhat
EReadingWhat
Definition: TSimpleAnalysis.h:48
TSimpleAnalysis::GetLine
std::string GetLine(int &numbLine)
Skip subsequent empty lines read from fIn and returns the next not empty line.
Definition: TSimpleAnalysis.cxx:398
TSimpleAnalysis::TSimpleAnalysis
TSimpleAnalysis(const std::string &file)
Definition: TSimpleAnalysis.h:62
line
TLine * line
Definition: entrylistblock_figure1.C:235
TSimpleAnalysis::kReadingTreeName
@ kReadingTreeName
Reading the name of the tree.
Definition: TSimpleAnalysis.h:50
TSimpleAnalysis::kReadingOutput
@ kReadingOutput
Reading the name of the output file.
Definition: TSimpleAnalysis.h:49
file
Definition: file.py:1
TSimpleAnalysis::fConfigFile
std::string fConfigFile
Name of the configuration file.
Definition: TSimpleAnalysis.h:36
TSimpleAnalysis::SetTreeName
bool SetTreeName()
Disambiguate tree name from first input file and set up fTreeName if it is empty.
Definition: TSimpleAnalysis.cxx:234
TSimpleAnalysis::fHists
std::map< std::string, std::pair< std::string, std::string > > fHists
Definition: TSimpleAnalysis.h:44
TSimpleAnalysis::kReadingExpressions
@ kReadingExpressions
Reading the expressions.
Definition: TSimpleAnalysis.h:52
TSimpleAnalysis::HandleInputFileNameConfig
bool HandleInputFileNameConfig(const std::string &line)
Returns false if not a tree name, otherwise sets the name of the tree.
Definition: TSimpleAnalysis.cxx:384