#include "RootIOSvc/RootInputFile.h"
#include "RootIOSvc/RootIOBaseObject.h"
#include "RootIOSvc/RootIOUserData.h"
#include "RootIOSvc/RootIOUserDataProxy.h"
#include "TFile.h"
#include "TTree.h"
#include "TLeaf.h"
#include "TDirectory.h"
#include "TKey.h"
#include "TIterator.h"
#include <string>
#include <vector>
Include dependency graph for RootInputFile.cc:
Go to the source code of this file.
Functions | |
static void | handle_user_data (TTree *tree, const std::string &path) |
static void | process_directory (TDirectory *dir, std::vector< std::string > &ret) |
static int | find_uniq (TBranch *branch) |
static void handle_user_data | ( | TTree * | tree, | |
const std::string & | path | |||
) | [static] |
Definition at line 17 of file RootInputFile.cc.
00018 { 00019 TObjArray* branches = tree->GetListOfBranches(); 00020 size_t nbranches = branches->GetEntries(); 00021 00022 Dyb::MsgStreamMember log("RootInputFile::handle_user_data"); 00023 log << MSG::DEBUG << "Found Tree (nBranches=" << nbranches 00024 << ") at path: " << path << endreq; 00025 00026 // Check the tree for branches besides ones made from a 00027 // RootIOBaseObject 00028 std::vector<TBranch*> known_unknowns, unknown_unknowns; 00029 for (size_t ind=0; ind<nbranches; ++ind) { 00030 00031 TBranch* branch = static_cast<TBranch*>(branches->At(ind)); 00032 TLeaf* leaf = static_cast<TLeaf*>(branch->GetListOfLeaves()->At(0)); 00033 00034 log << MSG::DEBUG << "\tCheckingName: " 00035 << branch->GetName() 00036 << " (" << leaf->GetTypeName() << ")" 00037 << endreq; 00038 00039 // Let's do a little dance. It's called, "find who we know". 00040 std::string type = leaf->GetTypeName(); 00041 if (type == "Int_t" || type == "Float_t") { 00042 log << MSG::DEBUG << "\t\tlikely branch: \"" 00043 << branch->GetName() << "\"" << endreq; 00044 unknown_unknowns.push_back(branch); // Outlander! 00045 } 00046 else { 00047 TClass c(type.c_str()); 00048 if (c.InheritsFrom("RootIOBaseObject")) { 00049 known_unknowns.push_back(branch); // I know you! 00050 } 00051 else { 00052 log << MSG::DEBUG << "\t\tlikely branch: \"" 00053 << branch->GetName() << "\"" << endreq; 00054 unknown_unknowns.push_back(branch); // Outlander! 00055 } 00056 } 00057 } 00058 00059 RootIOUserData ud; // get proxies for given stream 00060 RootIOUserData::ProxyCollection& proxies = ud.input(path); 00061 00062 for (size_t ind=0; ind<unknown_unknowns.size(); ++ind) { 00063 TBranch* branch = unknown_unknowns[ind]; 00064 00065 std::string className = branch->ClassName(); // eg "TBranch" 00066 TLeaf* leaf = static_cast<TLeaf*>(branch->GetListOfLeaves()->At(0)); 00067 00068 char* addr = 0; 00069 if (className == "TBranchElement") { 00070 addr = *((char**)(branch->GetAddress())); 00071 } 00072 else { 00073 addr = (char*)(leaf->GetValuePointer()); 00074 } 00075 00076 std::string branchName = branch->GetName(); // eg "count" 00077 00078 RootIOUserDataProxy* udp = proxies[branchName]; 00079 if (!udp) { 00080 std::string branchType = leaf->GetTypeName(); // eg "Int_t" 00081 udp = new RootIOUserDataProxy(branchName,branchType,addr); 00082 proxies[branchName] = udp; 00083 } 00084 else { 00085 udp->resetAddress(addr); 00086 } 00087 00088 } // loop over unknown unknowns 00089 00090 } // handle_user_data()
static void process_directory | ( | TDirectory * | dir, | |
std::vector< std::string > & | ret | |||
) | [static] |
Definition at line 93 of file RootInputFile.cc.
00094 { 00095 Dyb::MsgStreamMember log("RootInputFile::TreePaths"); 00096 00097 TList* keys = dir->GetListOfKeys(); 00098 TIter root_sucks(keys); 00099 TKey* key=0; 00100 while ((key = (TKey*)root_sucks())) { // infinite loop? ROOT does suck a lot! 00101 std::string dirpath = dir->GetPath(); 00102 dirpath = dirpath.substr(dirpath.rfind(":")+1); 00103 00104 TObject* obj = key->ReadObj(); 00105 00106 TDirectory* isDir = dynamic_cast<TDirectory*>(obj); 00107 if (isDir) { 00108 process_directory(isDir,ret); 00109 continue; 00110 } 00111 TTree* isTree = dynamic_cast<TTree*>(obj); 00112 if (isTree) { 00113 std::string path = "/"; 00114 // Catch trees in root directory 00115 if(dirpath != "/") 00116 path = dirpath + "/"; 00117 path += isTree->GetName(); 00118 ret.push_back(path); 00119 continue; 00120 } 00121 00122 log << MSG::WARNING 00123 << "unexpected object " << obj->GetName() 00124 << " of type " << obj->ClassName() 00125 << " found in directory " << dirpath << endreq; 00126 } 00127 }
static int find_uniq | ( | TBranch * | branch | ) | [static] |
Definition at line 149 of file RootInputFile.cc.
00150 { 00151 static std::string name("RootIOBaseObject"); 00152 00153 //cerr << "Checking branch " << branch->GetName() << std::endl; 00154 00155 if (branch->GetName() == name) { 00156 TBranch* brID = branch->FindBranch("clID"); 00157 RootIOBaseObject riobo; 00158 brID->SetAddress(&riobo); 00159 brID->GetEntry(0); 00160 return riobo.clID; 00161 } 00162 00163 TObjArray* branches = branch->GetListOfBranches(); 00164 TIter root_sucks(branches); 00165 branch=0; 00166 while ((branch = (TBranch*)root_sucks())) { 00167 int ret = find_uniq(branch); 00168 if (ret) return ret; 00169 } 00170 return 0; 00171 }