1 #ifndef FastSimulation_Tracking_SeedingTree_h 2 #define FastSimulation_Tracking_SeedingTree_h 7 #include <unordered_set> 25 _index(allNodes.
size()),
26 _parentIndex(parentIndex)
28 allNodes.push_back(
this);
47 _parentIndex=parentIndex;
48 _index=allNodes.size();
53 allNodes.push_back(
this);
54 for (
unsigned int ichild=0; ichild<_children.size();++ichild)
56 _allNodes[_children[ichild]]->sort(allNodes,_index);
62 if (_depth+1>=dataList.size())
66 for (
unsigned int ichild=0; ichild<_children.size();++ichild)
68 if (allNodes[_children[ichild]]->
getData()==dataList[_depth+1])
70 return allNodes[_children[ichild]]->insert(dataList,allNodes);
74 if (node->
getDepth()+1>=dataList.size())
78 return node->
insert(dataList,allNodes);
88 if (_index+1<_allNodes.size())
90 return _allNodes[_index+1];
97 if (_children.size()>0)
99 return _allNodes[_children[0]];
120 return _children.size();
125 return _allNodes[_children[ichild]];
141 printf(
"index=%3i, depth=%2i, childIndex=%2i: ",_index,_depth,_childIndex);
146 printf(
"[%s, %s] \r\n",_data.toString().c_str(),_data.toIdString().c_str());
152 for (
unsigned int ichild=0; ichild<_children.size(); ++ichild)
154 _allNodes[_children[ichild]]->printRecursive();
163 typedef std::unordered_set<DATA,typename DATA:: hashfct, typename DATA:: eqfct>
SingleSet;
172 bool insert(
const std::vector<DATA>& dataList)
174 for (
unsigned int i = 0;
i< dataList.size(); ++
i)
176 _singleSet.insert(dataList[
i]);
179 if (dataList.size()==0)
183 for (
unsigned int iroot=0; iroot<_roots.size();++iroot)
185 if (_roots[iroot]->
getData()==dataList[0])
187 return _roots[iroot]->insert(dataList,_allNodes);
191 _roots.push_back(node);
192 return node->
insert(dataList,_allNodes);
203 std::vector<SeedingNode<DATA>*> allNodes;
204 for (
unsigned int iroot=0; iroot<_roots.size();++iroot)
206 _roots[iroot]->sort(allNodes,-1);
215 return _roots.size();
220 return _allNodes.size();
234 std::cout<<
"SeedingTree: n="<<_allNodes.size()<<
" [recursive]"<<std::endl;
235 for (
unsigned int iroot=0; iroot<_roots.size();++iroot)
237 _roots[iroot]->printRecursive();
242 std::cout<<
"SeedingTree: n="<<_allNodes.size()<<
" [ordered]"<<std::endl;
243 for (
unsigned int inode=0; inode<_allNodes.size();++inode)
245 _allNodes[inode]->print();
251 std::cout<<
"SeedingTree: n="<<_allNodes.size()<<std::endl;
252 for (
unsigned int inode=0; inode<_allNodes.size();++inode)
254 _allNodes[inode]->print();
260 for (
unsigned int iroot=0; iroot<_roots.size();++iroot)
262 delete _roots[iroot];
const SeedingNode< DATA > * next() const
const SingleSet & getSingleSet() const
void printRecursive() const
const SeedingNode< DATA > * firstChild() const
SeedingNode(const DATA &data, std::vector< SeedingNode * > &allNodes, int parentIndex=-1)
const DATA & getData() const
unsigned int getChildrenSize() const
unsigned int getDepth() const
const SeedingNode * getParent() const
std::vector< SeedingNode< DATA > * > _roots
bool insert(const std::vector< DATA > &dataList)
unsigned int numberOfNodes() const
unsigned int numberOfRoots() const
std::unordered_set< DATA, typename DATA::hashfct, typename DATA::eqfct > SingleSet
void sort(std::vector< SeedingNode< DATA > * > &allNodes, unsigned int parentIndex)
void printRecursive() const
bool insert(const std::vector< DATA > &dataList, std::vector< SeedingNode< DATA > * > &allNodes)
std::vector< unsigned int > _children
std::vector< SeedingNode< DATA > * > _allNodes
const SeedingNode< DATA > * getRoot(unsigned int i) const
char data[epos_bytes_allocation]
void printOrdered() const
const std::vector< SeedingNode< DATA > * > & _allNodes
unsigned int getIndex() const
unsigned int getChildIndex() const
const SeedingNode< DATA > * getChild(unsigned int ichild) const