#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) |
Variable::ValueList | fill () |
double | fill (const MVAComputer *mva) |
uint64_t | loop (const MVAComputer *mva) |
TreeReader & | operator= (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< AtomicId > | variables () 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< Bool > | singleBool |
std::vector< Double_t > | singleDouble |
std::vector< Float_t > | singleFloat |
std::vector< Int_t > | singleInt |
TTree * | tree |
bool | upToDate |
std::map< AtomicId, Value > | valueMap |
Variable::ValueList | values |
Friends | |
class | Value |
Definition at line 19 of file TreeReader.h.
PhysicsTools::TreeReader::TreeReader | ( | ) |
Definition at line 25 of file TreeReader.cc.
PhysicsTools::TreeReader::TreeReader | ( | const TreeReader & | orig | ) |
PhysicsTools::TreeReader::TreeReader | ( | TTree * | tree, |
bool | skipTarget = false , |
||
bool | skipWeight = false |
||
) |
Definition at line 35 of file TreeReader.cc.
References automaticAdd().
: tree(tree), upToDate(false) { automaticAdd(skipTarget, skipWeight); }
PhysicsTools::TreeReader::~TreeReader | ( | ) | [virtual] |
Definition at line 41 of file TreeReader.cc.
{ }
void PhysicsTools::TreeReader::addBranch | ( | const std::string & | expression, |
AtomicId | name = AtomicId() , |
||
bool | opt = true |
||
) |
Definition at line 72 of file TreeReader.cc.
References Exception, and tree.
Referenced by automaticAdd().
{ if (!tree) throw cms::Exception("NoTreeAvailable") << "No TTree set in TreeReader::addBranch." << std::endl; TBranch *branch = tree->GetBranch(expression.c_str()); if (!branch) throw cms::Exception("BranchMissing") << "Tree branch \"" << expression << "\" missing." << std::endl; addBranch(branch, name, opt); }
void PhysicsTools::TreeReader::addBranch | ( | TBranch * | branch, |
AtomicId | name = AtomicId() , |
||
bool | opt = true |
||
) |
Definition at line 89 of file TreeReader.cc.
References addTypeMulti(), addTypeSingle(), Exception, python::Node::leaf, trackerHitRTTI::multi, mergeVDriftHistosByStation::name, and valueMap.
{ TString branchName = branch->GetName(); if (!name) name = (const char*)branchName; TLeaf *leaf = dynamic_cast<TLeaf*>(branch->GetLeaf(branchName)); if (!leaf) throw cms::Exception("InvalidBranch") << "Tree branch \"" << branchName << "\" has no leaf." << std::endl; TString typeName = leaf->GetTypeName(); char typeId = 0; bool multi = false; if (typeName == "Double_t" || typeName == "double") typeId = 'D'; else if (typeName == "Float_t" || typeName == "float") typeId = 'F'; else if (typeName == "Int_t" || typeName == "int") typeId = 'I'; else if (typeName == "Bool_t" || typeName == "bool") typeId = 'B'; else { multi = true; if (typeName == "vector<double>" || typeName == "Vector<Double_t>") typeId = 'D'; else if (typeName == "vector<float>" || typeName == "Vector<Float_t>") typeId = 'F'; else if (typeName == "vector<int>" || typeName == "Vector<Int_t>") typeId = 'I'; else if (typeName == "vector<bool>" || typeName == "Vector<Bool_t>") typeId = 'B'; } if (!typeId) throw cms::Exception("InvalidBranch") << "Tree branch \"" << branchName << "\" is of " "unsupported type \"" << typeName << "\"." << std::endl; if (multi) addTypeMulti(name, 0, typeId); else addTypeSingle(name, 0, typeId, opt); valueMap[name].setBranchName(branch->GetName()); }
void PhysicsTools::TreeReader::addMulti | ( | AtomicId | name, |
const std::vector< T > * | value | ||
) |
void PhysicsTools::TreeReader::addSingle | ( | AtomicId | name, |
const T * | value, | ||
bool | opt = false |
||
) |
Referenced by PhysicsTools::TreeTrainer::addTree().
void PhysicsTools::TreeReader::addTypeMulti | ( | AtomicId | name, |
const void * | value, | ||
char | type | ||
) |
Definition at line 199 of file TreeReader.cc.
References Exception, getHLTprescales::index, multiBool, multiDouble, multiFloat, multiInt, mergeVDriftHistosByStation::name, pos, upToDate, Value, and valueMap.
Referenced by addBranch().
{ std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name); if (pos != valueMap.end()) throw cms::Exception("DuplicateVariable") << "Duplicate Variable \"" << name << "\"." << std::endl; if (type != 'D' && type != 'F' && type != 'I' && type != 'B') throw cms::Exception("InvalidType") << "Unsupported type '" << type << "' in call to" "TreeReader::addTypeMulti." << std::endl; int index = -1; if (!value) { switch(type) { case 'D': index = (int)multiDouble.size(); multiDouble.push_back(makeMulti<Double_t>()); break; case 'F': index = (int)multiFloat.size(); multiFloat.push_back(makeMulti<Float_t>()); break; case 'I': index = (int)multiInt.size(); multiInt.push_back(makeMulti<Int_t>()); break; case 'B': index = (int)multiBool.size(); multiBool.push_back(makeMulti<Bool_t>()); break; } } valueMap[name] = Value(index, true, false, type); if (value) valueMap[name].setPtr(value); upToDate = false; }
void PhysicsTools::TreeReader::addTypeSingle | ( | AtomicId | name, |
const void * | value, | ||
char | type, | ||
bool | opt | ||
) |
Definition at line 153 of file TreeReader.cc.
References Exception, getHLTprescales::index, mergeVDriftHistosByStation::name, pos, singleBool, singleDouble, singleFloat, singleInt, upToDate, Value, and valueMap.
Referenced by addBranch().
{ std::map<AtomicId, Value>::const_iterator pos = valueMap.find(name); if (pos != valueMap.end()) throw cms::Exception("DuplicateVariable") << "Duplicate Variable \"" << name << "\"." << std::endl; if (type != 'D' && type != 'F' && type != 'I' && type != 'B') throw cms::Exception("InvalidType") << "Unsupported type '" << type << "' in call to" "TreeReader::addTypeSingle." << std::endl; int index = -1; if (!value) { switch(type) { case 'D': index = (int)singleDouble.size(); singleDouble.push_back(Double_t()); break; case 'F': index = (int)singleFloat.size(); singleFloat.push_back(Float_t()); break; case 'I': index = (int)singleInt.size(); singleInt.push_back(Int_t()); break; case 'B': index = (int)singleBool.size(); singleBool.push_back(Bool()); break; } } valueMap[name] = Value(index, false, opt, type); if (value) valueMap[name].setPtr(value); upToDate = false; }
void PhysicsTools::TreeReader::automaticAdd | ( | bool | skipTarget = false , |
bool | skipWeight = false |
||
) |
Definition at line 241 of file TreeReader.cc.
References addBranch(), Exception, VarParsing::obj, and tree.
Referenced by TreeReader().
{ if (!tree) throw cms::Exception("NoTreeAvailable") << "No TTree set in TreeReader::automaticAdd." << std::endl; TIter iter(tree->GetListOfBranches()); TObject *obj; while((obj = iter())) { TBranch *branch = dynamic_cast<TBranch*>(obj); if (!branch) continue; if (skipTarget && !std::strcmp(branch->GetName(), "__TARGET__")) continue; if (skipWeight && !std::strcmp(branch->GetName(), "__WEIGHT__")) continue; addBranch(branch); } }
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().
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.
uint64_t PhysicsTools::TreeReader::loop | ( | const MVAComputer * | mva | ) |
Definition at line 298 of file TreeReader.cc.
References python::tagInventory::entries, Exception, fill(), tree, update(), and upToDate.
Referenced by PhysicsTools::TreeTrainer::iteration().
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().
{ reset(); tree = orig.tree; multiDouble.resize(orig.multiDouble.size()); multiFloat.resize(orig.multiFloat.size()); multiInt.resize(orig.multiInt.size()); multiBool.resize(orig.multiBool.size()); singleDouble.resize(orig.singleDouble.size()); singleFloat.resize(orig.singleFloat.size()); singleInt.resize(orig.singleInt.size()); singleBool.resize(orig.singleBool.size()); valueMap = orig.valueMap; return *this; }
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=().
{ multiDouble.clear(); multiFloat.clear(); multiInt.clear(); multiBool.clear(); singleDouble.clear(); singleFloat.clear(); singleInt.clear(); singleBool.clear(); valueMap.clear(); upToDate = false; }
Definition at line 142 of file TreeReader.cc.
void PhysicsTools::TreeReader::setTree | ( | TTree * | tree | ) |
void PhysicsTools::TreeReader::update | ( | void | ) |
Definition at line 284 of file TreeReader.cc.
References Exception, tree, upToDate, and valueMap.
Referenced by loop().
{ if (!tree) throw cms::Exception("NoTreeAvailable") << "No TTree set in TreeReader::automaticAdd." << std::endl; for(std::map<AtomicId, Value>::iterator iter = valueMap.begin(); iter != valueMap.end(); iter++) iter->second.update(this); upToDate = true; }
std::vector< AtomicId > PhysicsTools::TreeReader::variables | ( | ) | const |
Definition at line 342 of file TreeReader.cc.
References query::result, and valueMap.
friend class Value [friend] |
Definition at line 106 of file TreeReader.h.
Referenced by addTypeMulti(), and addTypeSingle().
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] |
Definition at line 71 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Double_t> > > PhysicsTools::TreeReader::multiDouble [private] |
Definition at line 68 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Float_t> > > PhysicsTools::TreeReader::multiFloat [private] |
Definition at line 69 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<std::pair<void*, std::vector<Int_t> > > PhysicsTools::TreeReader::multiInt [private] |
Definition at line 70 of file TreeReader.h.
Referenced by addTypeMulti(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Bool> PhysicsTools::TreeReader::singleBool [private] |
Definition at line 76 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Double_t> PhysicsTools::TreeReader::singleDouble [private] |
Definition at line 73 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Float_t> PhysicsTools::TreeReader::singleFloat [private] |
Definition at line 74 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
std::vector<Int_t> PhysicsTools::TreeReader::singleInt [private] |
Definition at line 75 of file TreeReader.h.
Referenced by addTypeSingle(), PhysicsTools::TreeReader::Value::fill(), operator=(), reset(), and PhysicsTools::TreeReader::Value::update().
TTree* PhysicsTools::TreeReader::tree [private] |
Definition at line 60 of file TreeReader.h.
Referenced by addBranch(), automaticAdd(), loop(), operator=(), setTree(), update(), and PhysicsTools::TreeReader::Value::update().
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] |
Definition at line 108 of file TreeReader.h.
Referenced by addBranch(), addTypeMulti(), addTypeSingle(), fill(), operator=(), reset(), setOptional(), update(), and variables().
Definition at line 109 of file TreeReader.h.
Referenced by fill(), and PhysicsTools::TreeReader::Value::fill().