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  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::lookup" );
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  MultiIndexDataTrie* leaf = trie->m_children[indexes[i-1]];
88  if(0==leaf->m_data.size()){
89  throwException( "No Data for the specified index combination.",
90  "MultiIndexDataTrie::lookupAndClear" );
91  }
92  rec.swap(leaf->m_data);
93  delete leaf;
94  trie->m_children[indexes[i-1]] = 0;
95 }
96 
98  return m_children.size();
99 }
100 
102  for(std::vector<MultiIndexDataTrie*>::iterator iT = m_children.begin();
103  iT != m_children.end(); iT++){
104  if(*iT) delete *iT;
105  }
106  m_children.clear();
107  Record tmp; tmp.swap(m_data);
108 }
109 
110 size_t ora::MultiIndexDataTrie::branchSize( const std::vector<int>& indexes, size_t depth ) const{
111  if( depth > indexes.size() ) depth = indexes.size();
112  const MultiIndexDataTrie* trie = this;
113  for( size_t i=0;i<depth;i++){
114  if( trie->m_children.size()==0 || indexes[i] > (int)(trie->m_children.size()-1)){
115  std::stringstream mess;
116  mess << "Index["<<i<<"] is out of bound.";
117  throwException( mess.str(),"MultiIndexDataTrie::lookup" );
118  }
119  trie = trie->m_children[indexes[i]];
120  if( !trie ){
121  std::stringstream mess;
122  mess << "Slot for index["<<i<<"] is empty.";
123  throwException( mess.str(),"MultiIndexDataTrie::branchSize" );
124  }
125  }
126  return trie->m_children.size();
127 }
128 
130  size_t sz = 0;
131  for(std::vector<MultiIndexDataTrie*>::const_iterator iT = m_children.begin();
132  iT != m_children.end(); iT++){
133  sz++;
134  if(*iT) sz += (*iT)->totalSize();
135  }
136  return sz;
137 }
138 
139 
int i
Definition: DBlmapReader.cc:9
size_t push(const std::vector< int > &indexes, Record &data)
void lookupAndClear(const std::vector< int > &indexes, Record &rec)
void swap(Record &lh)
Definition: Record.cc:81
std::vector< MultiIndexDataTrie * > m_children
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
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
size_t size() const
Definition: Record.h:40
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
string s
Definition: asciidump.py:422