Logo ROOT   6.18/05
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
35private:
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
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
61public:
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
70bool RunSimpleAnalysis(const char* configurationFile);
71
72#endif
bool RunSimpleAnalysis(const char *configurationFile)
Function that allows to create the TSimpleAnalysis object and execute its Configure and Analyze funct...
A TSimpleAnalysis object creates histograms from a TChain.
std::string fConfigFile
Name of the configuration file.
std::vector< std::string > fInputFiles
.root input files
std::string GetLine(int &numbLine)
Skip subsequent empty lines read from fIn and returns the next not empty line.
@ kReadingInput
Reading the name of the .root input files.
@ kReadingOutput
Reading the name of the output file.
@ kReadingTreeName
Reading the name of the tree.
@ kReadingExpressions
Reading the expressions.
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...
std::ifstream fIn
Stream for the input file.
TSimpleAnalysis(const std::string &file)
bool Run()
Execute all the TChain::Draw() as configured and stores the output histograms.
std::string fOutputFile
Output file in which are stored the histograms.
bool HandleInputFileNameConfig(const std::string &line)
Returns false if not a tree name, otherwise sets the name of the tree.
bool SetTreeName()
Disambiguate tree name from first input file and set up fTreeName if it is empty.
bool Configure()
This function has the aim of setting the arguments read from the input file.
std::map< std::string, std::pair< std::string, std::string > > fHists
std::string fTreeName
Name of the input tree.
TLine * line
Definition: file.py:1
static void output(int code)
Definition: gifencode.c:226