CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiIndexDataTrie.cc
Go to the documentation of this file.
2 #include "MultiIndexDataTrie.h"
3 //
4 #include <sstream>
5 // externals
6 #include "CoralBase/AttributeList.h"
7 
9  m_children(),
10  m_data(){
11 
12 }
13 
15  clear();
16 }
17 
18 size_t ora::MultiIndexDataTrie::push( const std::vector<int>& indexes,
19  Record & data ){
20  size_t s=0;
21  MultiIndexDataTrie* trie = this;
22  for( size_t i=0;i<indexes.size();i++){
23  size_t ts = trie->m_children.size();
25  if( ts == 0 || indexes[i] > (int)(ts-1) ){
26  for(size_t j=0;j<indexes[i]-ts+1;j++){
27  ++s;
28  nt = new MultiIndexDataTrie;
29  trie->m_children.push_back(nt);
30  }
31  } else {
32  nt = trie->m_children[indexes[i]];
33  if( !nt ){
34  std::stringstream mess;
35  mess << "Slot for index["<<i<<"] is empty.";
36  throwException( mess.str(),"MultiIndexDataTrie::push" );
37  }
38  }
39  trie = nt;
40  }
41  if( trie ) trie->m_data.swap(data);
42  return s;
43 }
44 
69 void ora::MultiIndexDataTrie::lookupAndClear( const std::vector<int>& indexes, Record & rec ) {
70  MultiIndexDataTrie* branch = this;
71  MultiIndexDataTrie* trie = 0;
72  size_t i=0;
73  for( ;i<indexes.size();i++){
74  if( branch->m_children.size()==0 || indexes[i] > (int)(branch->m_children.size()-1)){
75  std::stringstream mess;
76  mess << "Index["<<i<<"] is out of bound.";
77  throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );
78  }
79  trie = branch;
80  branch = branch->m_children[indexes[i]];
81  if( !branch ){
82  std::stringstream mess;
83  mess << "Slot for index["<<i<<"] is empty.";
84  throwException( mess.str(),"MultiIndexDataTrie::lookupAndClear" );
85  }
86  }
87  if( trie ){
88  MultiIndexDataTrie* leaf = trie->m_children[indexes[i-1]];
89  if(0==leaf->m_data.size()){
90  throwException( "No Data for the specified index combination.",
91  "MultiIndexDataTrie::lookupAndClear" );
92  }
93  rec.swap(leaf->m_data);
94  delete leaf;
95  trie->m_children[indexes[i-1]] = 0;
96  }
97 }
98 
100  return m_children.size();
101 }
102 
104  for(std::vector<MultiIndexDataTrie*>::iterator iT = m_children.begin();
105  iT != m_children.end(); iT++){
106  if(*iT) delete *iT;
107  }
108  m_children.clear();
109  Record tmp; tmp.swap(m_data);
110 }
111 
112 size_t ora::MultiIndexDataTrie::branchSize( const std::vector<int>& indexes, size_t depth ) const{
113  if( depth > indexes.size() ) depth = indexes.size();
114  const MultiIndexDataTrie* trie = this;
115  for( size_t i=0;i<depth;i++){
116  if( indexes[i]+1 > (int)(trie->m_children.size())){
117  // empty leaf
118  if( i+2>=indexes.size()) return 0;
119  // empty branches are not expected!
120  std::stringstream mess;
121  mess << "1 Index["<<i<<"] is out of bound.";
122  throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
123  }
124  trie = trie->m_children[indexes[i]];
125  if( !trie ){
126  std::stringstream mess;
127  mess << "Slot for index["<<i<<"] is empty.";
128  throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
129  }
130  }
131  return trie->m_children.size();
132 }
133 
135  size_t sz = 0;
136  for(std::vector<MultiIndexDataTrie*>::const_iterator iT = m_children.begin();
137  iT != m_children.end(); iT++){
138  sz++;
139  if(*iT) sz += (*iT)->totalSize();
140  }
141  return sz;
142 }
143 
144 
int i
Definition: DBlmapReader.cc:9
size_t push(const std::vector< int > &indexes, Record &data)
size_t size() const
Definition: Record.cc:85
void lookupAndClear(const std::vector< int > &indexes, Record &rec)
void swap(Record &lh)
Definition: Record.cc:79
std::vector< MultiIndexDataTrie * > m_children
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
tuple leaf
Definition: Node.py:62
int j
Definition: DBlmapReader.cc:9
size_t branchSize(const std::vector< int > &indexes, size_t depth=0) const
int nt
Definition: AMPTWrapper.h:32
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82