| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64util/namedFileIterator.hh" | ||
| 2 | |||
| 3 | #if defined(ROOT_FOUND) && ROOT_FOUND | ||
| 4 | |||
| 5 | #include <TROOT.h> | ||
| 6 | #include <TKey.h> | ||
| 7 | |||
| 8 | #include <iostream> | ||
| 9 | |||
| 10 | namespace na64dp { | ||
| 11 | namespace util { | ||
| 12 | |||
| 13 | ✗ | NamedFileIterator::NamedFileIterator( TFile * file | |
| 14 | , const char * clName | ||
| 15 | , const char * regex | ||
| 16 | , std::ostream * debugLogPtr | ||
| 17 | ✗ | ) | |
| 18 | ✗ | : _file(file), _className(clName), _rx(regex), _debugLogPtr(debugLogPtr) { | |
| 19 | //assert( _rx.IsValid() ); // always false; what this method is intended for?! | ||
| 20 | ✗ | _dirStack.push( StackEntry(TIter(file->GetListOfKeys()), _file) ); | |
| 21 | } | ||
| 22 | |||
| 23 | TObject * | ||
| 24 | ✗ | NamedFileIterator::get_match(TObjArray ** subs) { | |
| 25 | ✗ | if( _dirStack.empty() ) return nullptr; | |
| 26 | TKey * key; | ||
| 27 | ✗ | while((key = (TKey*) _dirStack.top().first.Next())) { | |
| 28 | ✗ | TClass * cl = ROOT::GetROOT()->GetClass(key->GetClassName()); | |
| 29 | // if current is dir | ||
| 30 | ✗ | if( cl->InheritsFrom("TDirectory") ) { | |
| 31 | ✗ | TDirectory * dir = (TDirectory*) key->ReadObj(); | |
| 32 | ✗ | assert(dir); | |
| 33 | ✗ | _dirStack.push(StackEntry(TIter(dir->GetListOfKeys()), dir)); | |
| 34 | ✗ | return get_match(subs); // recursive forwarding here | |
| 35 | } | ||
| 36 | // if current is look-up target | ||
| 37 | bool hasMatch; | ||
| 38 | ✗ | if(subs) { | |
| 39 | ✗ | *subs = _rx.MatchS(key->GetName()); | |
| 40 | ✗ | hasMatch = (*subs)->At(0); | |
| 41 | } else { | ||
| 42 | ✗ | hasMatch = _rx.Match(key->GetName()); | |
| 43 | } | ||
| 44 | ✗ | if(_debugLogPtr) { | |
| 45 | ✗ | *_debugLogPtr << "Name \"" << key->GetName() << | |
| 46 | (hasMatch ? "\"" : "\" does not") | ||
| 47 | ✗ | << " match name-lookup regexp \"" << _rx.GetPattern() << "\"" << std::endl; | |
| 48 | } | ||
| 49 | ✗ | if( cl->InheritsFrom(_className) && hasMatch ) { | |
| 50 | // TODO: check here name vs regex match | ||
| 51 | ✗ | TObject * res = key->ReadObj(); | |
| 52 | ✗ | if(_debugLogPtr) *_debugLogPtr << "...class matches." << std::endl; | |
| 53 | ✗ | return res; | |
| 54 | ✗ | } else if(subs) { | |
| 55 | ✗ | if(_debugLogPtr) *_debugLogPtr << "...class does not match." << std::endl; | |
| 56 | ✗ | delete *subs; | |
| 57 | ✗ | *subs = nullptr; | |
| 58 | } | ||
| 59 | } | ||
| 60 | ✗ | _dirStack.pop(); | |
| 61 | ✗ | return get_match(subs); // recursive forwarding here | |
| 62 | } | ||
| 63 | |||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | #endif // defined(ROOT_FOUND) && ROOT_FOUND | ||
| 68 |