Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:21

0001 #include "Fireworks/Core/interface/TEveElementIter.h"
0002 #include "Fireworks/Core/interface/fwLog.h"
0003 #include "TEveElement.h"
0004 #include "TNamed.h"
0005 #include <iostream>
0006 #include <stack>
0007 TEveElementIter::TEveElementIter(TEveElement* element, const char* regular_expression /* = 0 */) {
0008   if (regular_expression)
0009     regexp = TPRegexp(regular_expression);
0010   std::stack<std::pair<TEveElement*, TEveElement::List_i> > parents;
0011   parents.push(std::pair<TEveElement*, TEveElement::List_i>(element, element->BeginChildren()));
0012 
0013   unsigned int index = 0;  // index number to prevent endless loops
0014   unsigned int indexLimit = 1000000;
0015   while (!parents.empty() && ++index < indexLimit) {
0016     // take care of finished loop
0017     if (parents.top().second == parents.top().first->EndChildren()) {
0018       addElement(parents.top().first);
0019       parents.pop();
0020       if (!parents.empty())
0021         ++(parents.top().second);
0022       continue;
0023     }
0024 
0025     // find element without children
0026     if ((*parents.top().second)->NumChildren() > 0) {
0027       parents.push(std::pair<TEveElement*, TEveElement::List_i>(*(parents.top().second),
0028                                                                 (*parents.top().second)->BeginChildren()));
0029       continue;
0030     }
0031 
0032     // we have a leaf element (no children) to process
0033     addElement(*(parents.top().second));
0034     ++(parents.top().second);
0035   }
0036   if (index >= indexLimit) {
0037     fwLog(fwlog::kError) << " tree loop limit is reached!\n"
0038                          << "You either have a tree with loops or navigation logic is broken." << std::endl;
0039     elements.clear();
0040   }
0041   iter = elements.begin();
0042 }
0043 
0044 TEveElement* TEveElementIter::next() {
0045   if (iter == elements.end())
0046     return nullptr;
0047   ++iter;
0048   return current();
0049 }
0050 
0051 TEveElement* TEveElementIter::current() {
0052   if (iter == elements.end())
0053     return nullptr;
0054   else
0055     return *iter;
0056 }
0057 
0058 TEveElement* TEveElementIter::reset() {
0059   iter = elements.begin();
0060   return current();
0061 }
0062 
0063 void TEveElementIter::addElement(TEveElement* element) {
0064   if (!element)
0065     return;
0066   TNamed* named = dynamic_cast<TNamed*>(element);
0067   if (named && !regexp.MatchB(named->GetName()))
0068     return;
0069   elements.push_back(element);
0070 }