CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Attributes | Private Attributes | Friends
PhysicsTools::TreeReader Class Reference

#include <TreeReader.h>

Classes

struct  Bool
 
class  Value
 

Public Member Functions

void addBranch (const std::string &expression, AtomicId name=AtomicId(), bool opt=true)
 
void addBranch (TBranch *branch, AtomicId name=AtomicId(), bool opt=true)
 
template<typename T >
void addMulti (AtomicId name, const std::vector< T > *value)
 
template<typename T >
void addSingle (AtomicId name, const T *value, bool opt=false)
 
void addTypeMulti (AtomicId name, const void *value, char type)
 
void addTypeSingle (AtomicId name, const void *value, char type, bool opt)
 
void automaticAdd (bool skipTarget=false, bool skipWeight=false)
 
double fill (const MVAComputer *mva)
 
Variable::ValueList fill ()
 
uint64_t loop (const MVAComputer *mva)
 
TreeReaderoperator= (const TreeReader &orig)
 
void reset ()
 
void setOptional (AtomicId name, bool opt, double optVal=kOptVal)
 
void setTree (TTree *tree)
 
 TreeReader ()
 
 TreeReader (const TreeReader &orig)
 
 TreeReader (TTree *tree, bool skipTarget=false, bool skipWeight=false)
 
void update ()
 
std::vector< AtomicIdvariables () const
 
virtual ~TreeReader ()
 

Static Public Attributes

static const double kOptVal = -999.0
 

Private Attributes

std::vector< std::pair< void
*, std::vector< Bool_t > > > 
multiBool
 
std::vector< std::pair< void
*, std::vector< Double_t > > > 
multiDouble
 
std::vector< std::pair< void
*, std::vector< Float_t > > > 
multiFloat
 
std::vector< std::pair< void
*, std::vector< Int_t > > > 
multiInt
 
std::vector< BoolsingleBool
 
std::vector< Double_t > singleDouble
 
std::vector< Float_t > singleFloat
 
std::vector< Int_t > singleInt
 
TTree * tree
 
bool upToDate
 
std::map< AtomicId, ValuevalueMap
 
Variable::ValueList values
 

Friends

class Value
 

Detailed Description

Definition at line 19 of file TreeReader.h.

Constructor & Destructor Documentation

PhysicsTools::TreeReader::TreeReader ( )

Definition at line 25 of file TreeReader.cc.

25  :
26  tree(0), upToDate(false)
27 {
28 }
PhysicsTools::TreeReader::TreeReader ( const TreeReader orig)

Definition at line 30 of file TreeReader.cc.

References operator=().

31 {
32  this->operator = (orig);
33 }
TreeReader & operator=(const TreeReader &orig)
Definition: TreeReader.cc:45
PhysicsTools::TreeReader::TreeReader ( TTree *  tree,
bool  skipTarget = false,
bool  skipWeight = false 
)

Definition at line 35 of file TreeReader.cc.

References automaticAdd().

35  :
36  tree(tree), upToDate(false)
37 {
38  automaticAdd(skipTarget, skipWeight);
39 }
void automaticAdd(bool skipTarget=false, bool skipWeight=false)
Definition: TreeReader.cc:241
PhysicsTools::TreeReader::~TreeReader ( )
virtual

Definition at line 41 of file TreeReader.cc.

42 {
43 }

Member Function Documentation

void PhysicsTools::TreeReader::addBranch ( const std::string &  expression,
AtomicId  name = AtomicId(),
bool  opt = true 
)

Definition at line 72 of file TreeReader.cc.

References edm::hlt::Exception, and tree.

Referenced by automaticAdd().

74 {
75  if (!tree)
76  throw cms::Exception("NoTreeAvailable")
77  << "No TTree set in TreeReader::addBranch."
78  << std::endl;
79 
80  TBranch *branch = tree->GetBranch(expression.c_str());
81  if (!branch)
82  throw cms::Exception("BranchMissing")
83  << "Tree branch \"" << expression << "\" missing."
84  << std::endl;
85 
86  addBranch(branch, name, opt);
87 }
void addBranch(const std::string &expression, AtomicId name=AtomicId(), bool opt=true)
Definition: TreeReader.cc:72
void PhysicsTools::TreeReader::addBranch ( TBranch *  branch,
AtomicId  name = AtomicId(),
bool  opt = true 
)

Definition at line 89 of file TreeReader.cc.

References addTypeMulti(), addTypeSingle(), edm::hlt::Exception, python.Node::leaf, trackerHitRTTI::multi, mergeVDriftHistosByStation::name, and valueMap.

90 {
91  TString branchName = branch->GetName();
92  if (!name)
93  name = (const char*)branchName;
94 
95  TLeaf *leaf = dynamic_cast<TLeaf*>(branch->GetLeaf(branchName));
96  if (!leaf)
97  throw cms::Exception("InvalidBranch")
98  << "Tree branch \"" << branchName << "\" has no leaf."
99  << std::endl;
100 
101  TString typeName = leaf->GetTypeName();
102  char typeId = 0;
103  bool multi = false;
104  if (typeName == "Double_t" || typeName == "double")
105  typeId = 'D';
106  else if (typeName == "Float_t" || typeName == "float")
107  typeId = 'F';
108  else if (typeName == "Int_t" || typeName == "int")
109  typeId = 'I';
110  else if (typeName == "Bool_t" || typeName == "bool")
111  typeId = 'B';
112  else {
113  multi = true;
114  if (typeName == "vector<double>" ||
115  typeName == "Vector<Double_t>")
116  typeId = 'D';
117  else if (typeName == "vector<float>" ||
118  typeName == "Vector<Float_t>")
119  typeId = 'F';
120  else if (typeName == "vector<int>" ||
121  typeName == "Vector<Int_t>")
122  typeId = 'I';
123  else if (typeName == "vector<bool>" ||
124  typeName == "Vector<Bool_t>")
125  typeId = 'B';
126  }
127 
128  if (!typeId)
129  throw cms::Exception("InvalidBranch")
130  << "Tree branch \"" << branchName << "\" is of "
131  "unsupported type \"" << typeName << "\"."
132  << std::endl;
133 
134  if (multi)
135  addTypeMulti(name, 0, typeId);
136  else
137  addTypeSingle(name, 0, typeId, opt);
138 
139  valueMap[name].setBranchName(branch->GetName());
140 }
tuple leaf
Definition: Node.py:62
void addTypeSingle(AtomicId name, const void *value, char type, bool opt)
Definition: TreeReader.cc:153
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
void addTypeMulti(AtomicId name, const void *value, char type)
Definition: TreeReader.cc:199
template<typename T >
void PhysicsTools::TreeReader::addMulti ( AtomicId  name,
const std::vector< T > *  value 
)
template<typename T >
void PhysicsTools::TreeReader::addSingle ( AtomicId  name,
const T value,
bool  opt = false 
)
void PhysicsTools::TreeReader::addTypeMulti ( AtomicId  name,
const void *  value,
char  type 
)

Definition at line 199 of file TreeReader.cc.

References edm::hlt::Exception, getHLTprescales::index, multiBool, multiDouble, multiFloat, multiInt, mergeVDriftHistosByStation::name, pos, upToDate, Value, and valueMap.

Referenced by addBranch().

200 {
201  std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name);
202  if (pos != valueMap.end())
203  throw cms::Exception("DuplicateVariable")
204  << "Duplicate Variable \"" << name << "\"."
205  << std::endl;
206 
207  if (type != 'D' && type != 'F' && type != 'I' && type != 'B')
208  throw cms::Exception("InvalidType")
209  << "Unsupported type '" << type << "' in call to"
210  "TreeReader::addTypeMulti." << std::endl;
211 
212  int index = -1;
213  if (!value) {
214  switch(type) {
215  case 'D':
216  index = (int)multiDouble.size();
217  multiDouble.push_back(makeMulti<Double_t>());
218  break;
219  case 'F':
220  index = (int)multiFloat.size();
221  multiFloat.push_back(makeMulti<Float_t>());
222  break;
223  case 'I':
224  index = (int)multiInt.size();
225  multiInt.push_back(makeMulti<Int_t>());
226  break;
227  case 'B':
228  index = (int)multiBool.size();
229  multiBool.push_back(makeMulti<Bool_t>());
230  break;
231  }
232  }
233 
234  valueMap[name] = Value(index, true, false, type);
235  if (value)
236  valueMap[name].setPtr(value);
237 
238  upToDate = false;
239 }
type
Definition: HCALResponse.h:22
std::vector< std::pair< void *, std::vector< Bool_t > > > multiBool
Definition: TreeReader.h:71
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
std::vector< std::pair< void *, std::vector< Int_t > > > multiInt
Definition: TreeReader.h:70
std::vector< std::pair< void *, std::vector< Double_t > > > multiDouble
Definition: TreeReader.h:68
std::vector< std::pair< void *, std::vector< Float_t > > > multiFloat
Definition: TreeReader.h:69
void PhysicsTools::TreeReader::addTypeSingle ( AtomicId  name,
const void *  value,
char  type,
bool  opt 
)

Definition at line 153 of file TreeReader.cc.

References edm::hlt::Exception, getHLTprescales::index, mergeVDriftHistosByStation::name, pos, singleBool, singleDouble, singleFloat, singleInt, upToDate, Value, and valueMap.

Referenced by addBranch().

154 {
155  std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name);
156  if (pos != valueMap.end())
157  throw cms::Exception("DuplicateVariable")
158  << "Duplicate Variable \"" << name << "\"."
159  << std::endl;
160 
161  if (type != 'D' && type != 'F' && type != 'I' && type != 'B')
162  throw cms::Exception("InvalidType")
163  << "Unsupported type '" << type << "' in call to"
164  "TreeReader::addTypeSingle." << std::endl;
165 
166  int index = -1;
167  if (!value) {
168  switch(type) {
169  case 'D':
170  index = (int)singleDouble.size();
171  singleDouble.push_back(Double_t());
172  break;
173  case 'F':
174  index = (int)singleFloat.size();
175  singleFloat.push_back(Float_t());
176  break;
177  case 'I':
178  index = (int)singleInt.size();
179  singleInt.push_back(Int_t());
180  break;
181  case 'B':
182  index = (int)singleBool.size();
183  singleBool.push_back(Bool());
184  break;
185  }
186  }
187 
188  valueMap[name] = Value(index, false, opt, type);
189  if (value)
190  valueMap[name].setPtr(value);
191 
192  upToDate = false;
193 }
type
Definition: HCALResponse.h:22
int Bool
Definition: Types.h:95
std::vector< Bool > singleBool
Definition: TreeReader.h:76
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
std::vector< Double_t > singleDouble
Definition: TreeReader.h:73
std::vector< Float_t > singleFloat
Definition: TreeReader.h:74
std::vector< Int_t > singleInt
Definition: TreeReader.h:75
void PhysicsTools::TreeReader::automaticAdd ( bool  skipTarget = false,
bool  skipWeight = false 
)

Definition at line 241 of file TreeReader.cc.

References addBranch(), edm::hlt::Exception, getGTfromDQMFile::obj, and tree.

Referenced by TreeReader().

242 {
243  if (!tree)
244  throw cms::Exception("NoTreeAvailable")
245  << "No TTree set in TreeReader::automaticAdd."
246  << std::endl;
247 
248  TIter iter(tree->GetListOfBranches());
249  TObject *obj;
250  while((obj = iter())) {
251  TBranch *branch = dynamic_cast<TBranch*>(obj);
252  if (!branch)
253  continue;
254 
255  if (skipTarget &&
256  !std::strcmp(branch->GetName(), "__TARGET__"))
257  continue;
258 
259  if (skipWeight &&
260  !std::strcmp(branch->GetName(), "__WEIGHT__"))
261  continue;
262 
263  addBranch(branch);
264  }
265 }
void addBranch(const std::string &expression, AtomicId name=AtomicId(), bool opt=true)
Definition: TreeReader.cc:72
double PhysicsTools::TreeReader::fill ( const MVAComputer mva)

Definition at line 318 of file TreeReader.cc.

References PhysicsTools::Variable::ValueList::clear(), PhysicsTools::MVAComputer::eval(), query::result, valueMap, and values.

319 {
320  for(std::map<AtomicId, Value>::const_iterator iter = valueMap.begin();
321  iter != valueMap.end(); iter++)
322  iter->second.fill(iter->first, this);
323 
324  double result = mva->eval(values);
325  values.clear();
326 
327  return result;
328 }
Variable::ValueList values
Definition: TreeReader.h:109
tuple result
Definition: query.py:137
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
Variable::ValueList PhysicsTools::TreeReader::fill ( void  )

Definition at line 330 of file TreeReader.cc.

References PhysicsTools::Variable::ValueList::clear(), query::result, valueMap, and values.

Referenced by loop().

331 {
332  for(std::map<AtomicId, Value>::const_iterator iter = valueMap.begin();
333  iter != valueMap.end(); iter++)
334  iter->second.fill(iter->first, this);
335 
336  Variable::ValueList result = values;
337  values.clear();
338 
339  return result;
340 }
Variable::ValueList values
Definition: TreeReader.h:109
tuple result
Definition: query.py:137
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
uint64_t PhysicsTools::TreeReader::loop ( const MVAComputer mva)

Definition at line 298 of file TreeReader.cc.

References python.tagInventory::entries, edm::hlt::Exception, fill(), tree, update(), and upToDate.

Referenced by PhysicsTools::TreeTrainer::iteration().

299 {
300  if (!tree)
301  throw cms::Exception("NoTreeAvailable")
302  << "No TTree set in TreeReader::automaticAdd."
303  << std::endl;
304 
305  if (!upToDate)
306  update();
307 
308  Long64_t entries = tree->GetEntries();
309  for(Long64_t entry = 0; entry < entries; entry++)
310  {
311  tree->GetEntry(entry);
312  fill(mva);
313  }
314 
315  return entries;
316 }
Variable::ValueList fill()
Definition: TreeReader.cc:330
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
TreeReader & PhysicsTools::TreeReader::operator= ( const TreeReader orig)

Definition at line 45 of file TreeReader.cc.

References multiBool, multiDouble, multiFloat, multiInt, reset(), singleBool, singleDouble, singleFloat, singleInt, tree, and valueMap.

Referenced by TreeReader().

46 {
47  reset();
48 
49  tree = orig.tree;
50 
51  multiDouble.resize(orig.multiDouble.size());
52  multiFloat.resize(orig.multiFloat.size());
53  multiInt.resize(orig.multiInt.size());
54  multiBool.resize(orig.multiBool.size());
55 
56  singleDouble.resize(orig.singleDouble.size());
57  singleFloat.resize(orig.singleFloat.size());
58  singleInt.resize(orig.singleInt.size());
59  singleBool.resize(orig.singleBool.size());
60 
61  valueMap = orig.valueMap;
62 
63  return *this;
64 }
std::vector< Bool > singleBool
Definition: TreeReader.h:76
std::vector< std::pair< void *, std::vector< Bool_t > > > multiBool
Definition: TreeReader.h:71
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
std::vector< std::pair< void *, std::vector< Int_t > > > multiInt
Definition: TreeReader.h:70
std::vector< Double_t > singleDouble
Definition: TreeReader.h:73
std::vector< Float_t > singleFloat
Definition: TreeReader.h:74
std::vector< std::pair< void *, std::vector< Double_t > > > multiDouble
Definition: TreeReader.h:68
std::vector< Int_t > singleInt
Definition: TreeReader.h:75
std::vector< std::pair< void *, std::vector< Float_t > > > multiFloat
Definition: TreeReader.h:69
void PhysicsTools::TreeReader::reset ( void  )

Definition at line 267 of file TreeReader.cc.

References multiBool, multiDouble, multiFloat, multiInt, singleBool, singleDouble, singleFloat, singleInt, upToDate, and valueMap.

Referenced by operator=().

268 {
269  multiDouble.clear();
270  multiFloat.clear();
271  multiInt.clear();
272  multiBool.clear();
273 
274  singleDouble.clear();
275  singleFloat.clear();
276  singleInt.clear();
277  singleBool.clear();
278 
279  valueMap.clear();
280 
281  upToDate = false;
282 }
std::vector< Bool > singleBool
Definition: TreeReader.h:76
std::vector< std::pair< void *, std::vector< Bool_t > > > multiBool
Definition: TreeReader.h:71
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
std::vector< std::pair< void *, std::vector< Int_t > > > multiInt
Definition: TreeReader.h:70
std::vector< Double_t > singleDouble
Definition: TreeReader.h:73
std::vector< Float_t > singleFloat
Definition: TreeReader.h:74
std::vector< std::pair< void *, std::vector< Double_t > > > multiDouble
Definition: TreeReader.h:68
std::vector< Int_t > singleInt
Definition: TreeReader.h:75
std::vector< std::pair< void *, std::vector< Float_t > > > multiFloat
Definition: TreeReader.h:69
void PhysicsTools::TreeReader::setOptional ( AtomicId  name,
bool  opt,
double  optVal = kOptVal 
)

Definition at line 142 of file TreeReader.cc.

References pos, and valueMap.

143 {
144  std::map<AtomicId, Value>::iterator pos = valueMap.find(name);
145  if (pos == valueMap.end())
146  throw cms::Exception("UnknownVariable")
147  << "Variable \"" <<name << "\" is not known to the "
148  "TreeReader." << std::endl;
149 
150  pos->second.setOpt(opt, optVal);
151 }
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
void PhysicsTools::TreeReader::setTree ( TTree *  tree)

Definition at line 66 of file TreeReader.cc.

References tree, and upToDate.

67 {
68  this->tree = tree;
69  upToDate = false;
70 }
void PhysicsTools::TreeReader::update ( void  )

Definition at line 284 of file TreeReader.cc.

References edm::hlt::Exception, tree, upToDate, and valueMap.

Referenced by progressbar.ProgressBar::__next__(), relval_steps.Matrix::__setitem__(), relval_steps.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), loop(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), relval_steps.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

285 {
286  if (!tree)
287  throw cms::Exception("NoTreeAvailable")
288  << "No TTree set in TreeReader::automaticAdd."
289  << std::endl;
290 
291  for(std::map<AtomicId, Value>::iterator iter = valueMap.begin();
292  iter != valueMap.end(); iter++)
293  iter->second.update(this);
294 
295  upToDate = true;
296 }
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108
std::vector< AtomicId > PhysicsTools::TreeReader::variables ( ) const

Definition at line 342 of file TreeReader.cc.

References query::result, and valueMap.

343 {
344  std::vector<AtomicId> result;
345  for(std::map<AtomicId, Value>::const_iterator iter = valueMap.begin();
346  iter != valueMap.end(); iter++)
347  result.push_back(iter->first);
348 
349  return result;
350 }
tuple result
Definition: query.py:137
std::map< AtomicId, Value > valueMap
Definition: TreeReader.h:108

Friends And Related Function Documentation

friend class Value
friend

Definition at line 106 of file TreeReader.h.

Referenced by addTypeMulti(), and addTypeSingle().

Member Data Documentation

const double PhysicsTools::TreeReader::kOptVal = -999.0
static

Definition at line 57 of file TreeReader.h.

std::vector<std::pair<void*, std::vector<Bool_t> > > PhysicsTools::TreeReader::multiBool
private
std::vector<std::pair<void*, std::vector<Double_t> > > PhysicsTools::TreeReader::multiDouble
private
std::vector<std::pair<void*, std::vector<Float_t> > > PhysicsTools::TreeReader::multiFloat
private
std::vector<std::pair<void*, std::vector<Int_t> > > PhysicsTools::TreeReader::multiInt
private
std::vector<Bool> PhysicsTools::TreeReader::singleBool
private
std::vector<Double_t> PhysicsTools::TreeReader::singleDouble
private
std::vector<Float_t> PhysicsTools::TreeReader::singleFloat
private
std::vector<Int_t> PhysicsTools::TreeReader::singleInt
private
TTree* PhysicsTools::TreeReader::tree
private
bool PhysicsTools::TreeReader::upToDate
private

Definition at line 110 of file TreeReader.h.

Referenced by addTypeMulti(), addTypeSingle(), loop(), reset(), setTree(), and update().

std::map<AtomicId, Value> PhysicsTools::TreeReader::valueMap
private
Variable::ValueList PhysicsTools::TreeReader::values
private