Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
33 class TSimpleAnalysis {
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