All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
Flatten.cc File Reference
#include "Flatten.h"
#include "SetEvent.h"
#include "TClassTable.h"
#include "TClass.h"
#include "TDictionary.h"
#include "TDictAttributeMap.h"
#include "TProtoClass.h"
#include "TSystem.h"
#include "TParameter.h"
#include "../NumuReco/TrackAlgo.h"

Go to the source code of this file.

Functions

std::vector< std::string > ProcessClass (TClass *tclass, const std::string &prefix)
 
std::string ClasstoNTupleName (const std::string &classname, const std::string &prefix)
 
 DECLARE_SBN_POSTPROCESSOR (ana::SBNOsc::Flatten)
 

Function Documentation

std::string ClasstoNTupleName ( const std::string &  classname,
const std::string &  prefix 
)

Definition at line 71 of file Flatten.cc.

71  {
72  DictFuncPtr_t classdict = gClassTable->GetDict(classname.c_str());
73  std::vector<std::string> var_names = ProcessClass(classdict(), prefix);
74  std::string ret;
75  for (unsigned i = 0; i < var_names.size(); i++) {
76  ret += var_names[i];
77  if (i < var_names.size() -1) ret += ":";
78  }
79  return ret;
80 }
std::vector< std::string > ProcessClass(TClass *tclass, const std::string &prefix)
Definition: Flatten.cc:14
DECLARE_SBN_POSTPROCESSOR ( ana::SBNOsc::Flatten  )
std::vector<std::string> ProcessClass ( TClass *  tclass,
const std::string &  prefix 
)

Definition at line 14 of file Flatten.cc.

14  {
15  std::vector<std::string> ret;
16  TList *members = tclass->GetListOfDataMembers();
17  TIterator *m_iterator = members->MakeIterator();
18  TObject *obj;
19  while ((obj = m_iterator->Next()) != NULL) {
20  TDataMember *member = (TDataMember *)obj;
21  TDataType *basic_type = member->GetDataType();
22  if (basic_type != NULL) {
23  // only accept floats
24  assert(basic_type->GetType() == kFloat_t);
25  // check if array
26  if (member->GetArrayDim() == 0) {
27  // not array -- just add
28  ret.push_back(prefix + "." + std::string(obj->GetName()));
29  }
30  else {
31  // sort through array
32  unsigned max_ind = 1;
33  for (unsigned i = 0; i < member->GetArrayDim(); i++) {
34  max_ind = max_ind * member->GetMaxIndex(i);
35  }
36  for (unsigned i = 0; i < max_ind; i++) {
37  std::vector<unsigned> each_ind(member->GetArrayDim(), 0);
38  unsigned ind = i;
39  for (int j = member->GetArrayDim()-1; j >= 0; j--) {
40  unsigned this_i = ind % member->GetMaxIndex(j);
41  each_ind[j] = this_i;
42  ind = ind / member->GetMaxIndex(j);
43  }
44  std::string base = prefix + "." + std::string(obj->GetName());
45  for (unsigned ind: each_ind) base += ("." + std::to_string(ind));
46  ret.push_back(base);
47  }
48  }
49 
50  }
51  // no enums in TNtuple
52  assert(!member->IsEnum());
53  // no pointers in TNtuple
54  assert(!member->IsaPointer());
55  // no containers in TNtuple
56  assert(!member->IsSTLContainer());
57  // if not basic -- descend
58  if (!member->IsBasic()) {
59  DictFuncPtr_t next = gClassTable->GetDict(member->GetTypeName());
60  if (next == NULL) {
61  std::cout << "Missing dictionary for class type: " << member->GetTypeName() << std::endl;
62  assert(next != NULL);
63  }
64  std::vector<std::string> this_ret = ProcessClass(next(), prefix + "." + std::string(obj->GetName()));
65  ret.insert(ret.end(), this_ret.begin(), this_ret.end());
66  }
67  }
68  return ret;
69 }
std::string to_string(WindowPattern const &pattern)
std::vector< std::string > ProcessClass(TClass *tclass, const std::string &prefix)
Definition: Flatten.cc:14
BEGIN_PROLOG could also be cout