CMS 3D CMS Logo

ForestHelper.h
Go to the documentation of this file.
1 #ifndef l1t_ForestHelper_h_
2 #define l1t_ForestHelper_h_
3 
4 #include <cassert>
5 #include <vector>
6 #include <map>
7 
10 
11 // If you want to create a new object that you can read and write, use this constructor:
12 //
13 // l1t::ForestHelper x(new L1TPrescalesVetors());
14 //
15 // If you wish to read the table from the EventSetup, and will only read, use this:
16 //
17 // const ForestHelper * x = ForestHelper::readFromEventSetup(...)
18 // //...
19 // delete x;
20 //
21 // If you wish to read the table from the EventSetup, but then be able to edit the values locally, use this:
22 //
23 // ForestHelper * x = ForestHelper::readAndWriteFromEventSetup(...)
24 // //...
26 //
27 // but there's a performance penalty as a copy is made.
28 
29 
30 //
31 // This class does not take over responsibility for deleting the pointers it is
32 // initialized with. That is responsibility of the calling code.
33 //
34 
35 #include "TXMLEngine.h"
36 
37 namespace l1t {
38 
39  class ForestHelper {
40  public:
41  enum {VERSION = 1};
42 
48 
49  ~ForestHelper();
50 
51  //ctor if creating a new table (e.g. from XML or python file)
53  //create for reading only, from the EventSetup:
54  static const ForestHelper * readFromEventSetup(const L1TMuonEndCapForest * es);
55  // create for reading and writing, starting from the EventSetup:
57 
58  void initializeFromXML(const char * dirname, const std::vector<int> & modes, int ntrees);
59 
60  double evaluate(int mode, const std::vector<double> & data) const;
61 
62  // print all the L1 GT parameters
63  void print(std::ostream&) const;
64 
65  // access to underlying pointers, mainly for ESProducer:
66  const L1TMuonEndCapForest * getReadInstance() const {return read_;}
68 
69  private:
71  void useCopy();
72  void check_write() { assert(write_); }
73  // separating read from write allows for a high-performance read-only mode (as no copy is made):
74  const L1TMuonEndCapForest * read_; // when reading/getting, use this.
75  L1TMuonEndCapForest * write_; // when writing/setting, use this.
77 
78 
79 
80  void loadTreeFromXMLRecursive(TXMLEngine* xml, XMLNodePointer_t xnode, DTree & tree, unsigned index);
81  double evalTreeRecursive(const std::vector<double> & data, const DTree & tree, int index) const;
82  };
83 
84 }
85 #endif
L1TMuonEndCapForest::DTreeNode DTreeNode
Definition: ForestHelper.h:43
void loadTreeFromXMLRecursive(TXMLEngine *xml, XMLNodePointer_t xnode, DTree &tree, unsigned index)
static ForestHelper * readAndWriteFromEventSetup(const L1TMuonEndCapForest *es)
Definition: ForestHelper.cc:14
const double w
Definition: UKUtility.cc:23
L1TMuonEndCapForest * getWriteInstance()
Definition: ForestHelper.h:67
L1TMuonEndCapForest::DForestMap DForestMap
Definition: ForestHelper.h:47
delete x;
Definition: CaloConfig.h:22
const L1TMuonEndCapForest * getReadInstance() const
Definition: ForestHelper.h:66
std::map< int, int > DForestMap
void initializeFromXML(const char *dirname, const std::vector< int > &modes, int ntrees)
Definition: ForestHelper.cc:72
std::vector< DForest > DForestColl
L1TMuonEndCapForest::DTree DTree
Definition: ForestHelper.h:44
ForestHelper(L1TMuonEndCapForest *w)
Definition: ForestHelper.cc:20
const L1TMuonEndCapForest * read_
Definition: ForestHelper.h:74
std::vector< DTree > DForest
void print(std::ostream &) const
Definition: ForestHelper.cc:42
L1TMuonEndCapForest::DForest DForest
Definition: ForestHelper.h:45
std::vector< DTreeNode > DTree
double evalTreeRecursive(const std::vector< double > &data, const DTree &tree, int index) const
L1TMuonEndCapForest * write_
Definition: ForestHelper.h:75
L1TMuonEndCapForest::DForestColl DForestColl
Definition: ForestHelper.h:46
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double evaluate(int mode, const std::vector< double > &data) const
Definition: tree.py:1
static const ForestHelper * readFromEventSetup(const L1TMuonEndCapForest *es)
Definition: ForestHelper.cc:10