g4tools  5.4.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::aida::base_looper< T > Class Template Referenceabstract
Inheritance diagram for tools::aida::base_looper< T >:
Inheritance graph
[legend]
Collaboration diagram for tools::aida::base_looper< T >:
Collaboration graph
[legend]

Public Member Functions

 base_looper (base_ntu &a_ntu, const base_col &a_col)
 
virtual ~base_looper ()
 
 base_looper (const base_looper &a_from)
 
base_looperoperator= (const base_looper &)
 
bool process ()
 

Static Public Member Functions

static const std::string & s_class ()
 

Protected Member Functions

virtual bool action (const T &a_value)=0
 
bool _looper (base_ntu &a_sub, const std::vector< unsigned int > &a_is, unsigned int a_depth, bool &a_stop)
 

Static Protected Member Functions

static bool find_is (const base_ntu &a_ntu, const base_col *a_col, std::vector< unsigned int > &a_is, bool &a_found)
 

Protected Attributes

base_ntum_ntu
 
const base_colm_col
 

Detailed Description

template<class T>
class tools::aida::base_looper< T >

Definition at line 1129 of file aida_ntuple.

Constructor & Destructor Documentation

◆ base_looper() [1/2]

template<class T >
tools::aida::base_looper< T >::base_looper ( base_ntu a_ntu,
const base_col a_col 
)
inline

Definition at line 1138 of file aida_ntuple.

1139  :m_ntu(a_ntu),m_col(a_col){
1140 #ifdef TOOLS_MEM
1141  mem::increment(s_class().c_str());
1142 #endif
1143  }

◆ ~base_looper()

template<class T >
virtual tools::aida::base_looper< T >::~base_looper ( )
inlinevirtual

Definition at line 1144 of file aida_ntuple.

1144  {
1145 #ifdef TOOLS_MEM
1146  mem::decrement(s_class().c_str());
1147 #endif
1148  }

◆ base_looper() [2/2]

template<class T >
tools::aida::base_looper< T >::base_looper ( const base_looper< T > &  a_from)
inline

Definition at line 1150 of file aida_ntuple.

1151  :m_ntu(a_from.m_ntu),m_col(a_from.m_col){
1152 #ifdef TOOLS_MEM
1153  mem::increment(s_class().c_str());
1154 #endif
1155  }

Member Function Documentation

◆ _looper()

template<class T >
bool tools::aida::base_looper< T >::_looper ( base_ntu a_sub,
const std::vector< unsigned int > &  a_is,
unsigned int  a_depth,
bool &  a_stop 
)
inlineprotected

Definition at line 1227 of file aida_ntuple.

1230  {
1231  if(a_depth>=a_is.size()) return false;
1232 
1233  unsigned int coli = a_is[a_depth];
1234  const std::vector<base_col*>& cols = a_sub.columns();
1235  if(coli>=cols.size()) return false;
1236 
1237  if(a_depth==(a_is.size()-1)) { //we reach the leaf.
1238  aida_col<T>* col = safe_cast<base_col, aida_col<T> >(*(cols[coli]));
1239  if(!col) return false;
1240  a_sub.start();
1241  while(a_sub.next()) {
1242  T v;
1243  if(!col->get_entry(v)) return false;
1244  if(!action(v)) {a_stop = true;break;}
1245  }
1246  } else {
1247  aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(cols[coli]));
1248  if(!col) return false;
1249  a_sub.start();
1250  while(a_sub.next()) {
1251  base_ntu* ntu = col->get_entry(); //not const.
1252  if(!ntu) return false;
1253  ntu->start();
1254  while(ntu->next()) {
1255  if(!_looper(*ntu,a_is,a_depth+1,a_stop)) return false;
1256  if(a_stop) break;
1257  }
1258  }
1259  }
1260  return true;
1261  }

◆ action()

template<class T >
virtual bool tools::aida::base_looper< T >::action ( const T &  a_value)
protectedpure virtual

◆ find_is()

template<class T >
static bool tools::aida::base_looper< T >::find_is ( const base_ntu a_ntu,
const base_col a_col,
std::vector< unsigned int > &  a_is,
bool &  a_found 
)
inlinestaticprotected

Definition at line 1190 of file aida_ntuple.

1192  {
1193  // search the indices to reach the sub leaf a_col from the main a_ntu.
1194  // Note : it is assumed that a_is is empty and a_found = false before
1195  // calling with function.
1196 
1197  const std::vector<base_col*>& cols = a_ntu.columns();
1198 
1199  // look if a_col is a leaf col of a_ntu :
1200  {unsigned int index = 0;
1201  tools_vforcit(base_col*,cols,it) {
1202  if(*it==a_col) {
1203  a_is.push_back(index); //leaf index is the last one in a_is.
1204  a_found = true;
1205  return true;
1206  }
1207  index++;
1208  }}
1209 
1210  // go down sub ntu :
1211  {unsigned int index = 0;
1212  tools_vforcit(base_col*,cols,it) {
1213  aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
1214  if(col) {
1215  base_ntu* sub = col->get_to_fill(); //it holds the "sub" cols schema.
1216  if(!sub) {a_is.clear();return false;}
1217  a_is.push_back(index);
1218  if(!find_is(*sub,a_col,a_is,a_found)) {a_is.clear();return false;}
1219  if(a_found) return true;
1220  a_is.pop_back();
1221  }
1222  index++;
1223  }}
1224  return true;
1225  }

◆ operator=()

template<class T >
base_looper& tools::aida::base_looper< T >::operator= ( const base_looper< T > &  )
inline

Definition at line 1156 of file aida_ntuple.

1156 {return *this;}

◆ process()

template<class T >
bool tools::aida::base_looper< T >::process ( )
inline

Definition at line 1158 of file aida_ntuple.

1158  {
1159  std::vector<unsigned int> is;
1160  bool found = false;
1161  if(!find_is(m_ntu,&m_col,is,found)) {
1162  m_ntu.out() << s_class() << "::process :"
1163  << " find_is failed."
1164  << std::endl;
1165  return false;
1166  }
1167  if(!found) {
1168  m_ntu.out() << s_class() << "::process :"
1169  << " find_is : col not found."
1170  << std::endl;
1171  return false;
1172  }
1173  if(is.empty()) {
1174  m_ntu.out() << s_class() << "::process :"
1175  << " is vec empty."
1176  << std::endl;
1177  return false;
1178  }
1179 
1180  bool stop = false;
1181  if(!_looper(m_ntu,is,0,stop)) {
1182  m_ntu.out() << s_class() << "::process :"
1183  << " _looper failed."
1184  << std::endl;
1185  return false;
1186  }
1187  return true;
1188  }

◆ s_class()

template<class T >
static const std::string& tools::aida::base_looper< T >::s_class ( )
inlinestatic

Definition at line 1131 of file aida_ntuple.

1131  {
1132  static const std::string s_v("tools::aida::base_looper<"+stype(T())+">");
1133  return s_v;
1134  }

Member Data Documentation

◆ m_col

template<class T >
const base_col& tools::aida::base_looper< T >::m_col
protected

Definition at line 1264 of file aida_ntuple.

◆ m_ntu

template<class T >
base_ntu& tools::aida::base_looper< T >::m_ntu
protected

Definition at line 1263 of file aida_ntuple.


The documentation for this class was generated from the following file:
tools::jpeg::is
bool is(const std::string &a_file)
Definition: jpeg:216
tools::sub
bool sub(std::vector< T > &a_vec, const std::vector< T > &a_v)
Definition: vmanip:283
tools::aida::base_looper::find_is
static bool find_is(const base_ntu &a_ntu, const base_col *a_col, std::vector< unsigned int > &a_is, bool &a_found)
Definition: aida_ntuple:1190
tools::aida::base_looper::m_ntu
base_ntu & m_ntu
Definition: aida_ntuple:1263
tools::aida::base_looper::action
virtual bool action(const T &a_value)=0
tools::aida::base_looper::_looper
bool _looper(base_ntu &a_sub, const std::vector< unsigned int > &a_is, unsigned int a_depth, bool &a_stop)
Definition: aida_ntuple:1227
tools::aida::base_looper::s_class
static const std::string & s_class()
Definition: aida_ntuple:1131
tools::aida::base_ntu::out
std::ostream & out() const
Definition: aida_ntuple:152
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::aida::base_looper::m_col
const base_col & m_col
Definition: aida_ntuple:1264
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73