ATLAS Offline Software
Loading...
Searching...
No Matches
VectorNtupleBranch.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <TTree.h>
7#include <TString.h>
8
9namespace Trk {
10 bool VectorNtupleBranch::initForWrite(TTree& tree, const std::string& varname, int nrow, const std::string& prefix ) {
11 if( nrow >= ROWMAX ) return false;
12 m_nrows = nrow;
13 for( int i=0;i<nrow;++i ){
14 TString bname = prefix.c_str();
15 bname += varname;
16 bname += i;
17 tree.Branch(bname,&m_vector[i]);
18 }
19 return true;
20 }
21
22 bool VectorNtupleBranch::initForRead(TTree& tree, const std::string& varname, int nrow, const std::string& prefix ) {
23 if( nrow >= ROWMAX ) return false;
24 m_nrows = nrow;
25 for( int i=0;i<nrow;++i ){
26 TString bname = prefix.c_str();
27 bname += varname;
28 bname += i;
29 tree.SetBranchAddress(bname,&m_vector[i]);
30 }
31 return true;
32 }
33
35 if( m_nrows == -1 ) return false;
36 if( vector.rows() > m_nrows ) return false;
37
38 for( int i=0;i<m_nrows;++i ){
39 if( i < vector.rows() ) m_vector[i] = vector[i];
40 else m_vector[i] = 0.;
41 }
42 return true;
43 }
44
45 bool VectorNtupleBranch::fill( const CLHEP::HepVector& vector ) {
46 if( m_nrows == -1 ) return false;
47 if( vector.num_row() > m_nrows ) return false;
48 for( int i=0;i<m_nrows;++i ){
49 if( i < vector.num_row() ) m_vector[i] = vector[i];
50 else m_vector[i] = 0.;
51 }
52 return true;
53 }
54
55 bool VectorNtupleBranch::fill( const HepGeom::Point3D<double>& vector ) {
56 if( m_nrows == -1 ) return false;
57 if( m_nrows != 3 ) return false;
58 for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
59 return true;
60 }
61
62 bool VectorNtupleBranch::fill( const CLHEP::Hep3Vector& vector ) {
63 if( m_nrows == -1 ) return false;
64 if( m_nrows != 3 ) return false;
65 for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
66 return true;
67 }
68
69 bool VectorNtupleBranch::fill( const HepGeom::Vector3D<double>& vector ) {
70 if( m_nrows == -1 ) return false;
71 if( m_nrows != 3 ) return false;
72 for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
73 return true;
74 }
75
76}
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
static const int ROWMAX
maximum size of the vector
bool initForWrite(TTree &tree, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for writing
bool fill(const Amg::VectorX &matrix)
fill a vector
bool initForRead(TTree &tree, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for reading
TChain * tree