/search.css" rel="stylesheet" type="text/css"/> /search.js">
#include "RootIOSvc/RootInputFile.h"
#include "RootIOSvc/RootIOBaseObject.h"
#include "RootIOSvc/RootIOUserData.h"
#include "RootIOSvc/RootIOUserDataProxy.h"
#include "TFile.h"
#include "TTree.h"
#include "TBranchElement.h"
#include "TLeaf.h"
#include "TDirectory.h"
#include "TKey.h"
#include "TIterator.h"
#include <string>
#include <vector>
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 18 of file RootInputFile.cc.
{ TObjArray* branches = tree->GetListOfBranches(); size_t nbranches = branches->GetEntries(); Dyb::MsgStreamMember log("RootInputFile::handle_user_data"); log << MSG::DEBUG << "Found Tree (nBranches=" << nbranches << ") at path: " << path << endreq; // Check the tree for branches besides ones made from a // RootIOBaseObject std::vector<TBranch*> known_unknowns, unknown_unknowns; for (size_t ind=0; ind<nbranches; ++ind) { TBranch* branch = static_cast<TBranch*>(branches->At(ind)); TLeaf* leaf = static_cast<TLeaf*>(branch->GetListOfLeaves()->At(0)); log << MSG::DEBUG << "\tCheckingName: " << branch->GetName() << " (" << leaf->GetTypeName() << ")" << endreq; // Let's do a little dance. It's called, "find who we know". std::string type = leaf->GetTypeName(); if (type == "Int_t" || type == "Float_t") { log << MSG::DEBUG << "\t\tlikely branch (known scalar): \"" << branch->GetName() << "\"" << endreq; unknown_unknowns.push_back(branch); // Outlander! } else { TClass c(type.c_str()); if (c.InheritsFrom("RootIOBaseObject")) { known_unknowns.push_back(branch); // I know you! } else { log << MSG::DEBUG << "\t\tlikely branch (something): \"" << branch->GetName() << "\"" << endreq; unknown_unknowns.push_back(branch); // Outlander! } } } RootIOUserData ud; // get proxies for given stream RootIOUserData::ProxyCollection& proxies = ud.input(path); for (size_t ind=0; ind<unknown_unknowns.size(); ++ind) { TBranch* branch = unknown_unknowns[ind]; std::string className = branch->ClassName(); // eg "TBranch" TLeaf* leaf = static_cast<TLeaf*>(branch->GetListOfLeaves()->At(0)); std::string branchName = branch->GetName(); // eg "count" std::string branchType = leaf->GetTypeName(); // eg "Int_t", "vector<int>" log << MSG::DEBUG << "\t\t" << ind << ": got className: \"" << className << "\"" << " branchName: \"" << branchName << "\"" << " branchType: \"" << branchType << "\"" << endreq; char* addr = 0; if (className == "TBranchElement") { // not a simple scalar TBranchElement *be = dynamic_cast<TBranchElement*>(branch); addr = be->GetObject(); if (!addr) { be->SetAddress(0); // let ROOT memory manage addr = be->GetObject(); } } else { // simple scalar addr = (char*)(leaf->GetValuePointer()); } if (!addr) { log << MSG::ERROR << "Failed to get branch adddress for variable \"" << branchName << "\" at path \"" << path << "\". I will be crashing now, thank you." << endreq; assert (0); } RootIOUserDataProxy* udp = proxies[branchName]; if (!udp) { udp = new RootIOUserDataProxy(branchName,branchType,addr); proxies[branchName] = udp; } else { udp->resetAddress(addr); } } // loop over unknown unknowns } // handle_user_data()
static void process_directory | ( | TDirectory * | dir, |
std::vector< std::string > & | ret | ||
) | [static] |
Definition at line 112 of file RootInputFile.cc.
{ Dyb::MsgStreamMember log("RootInputFile::TreePaths"); TList* keys = dir->GetListOfKeys(); TIter root_sucks(keys); TKey* key=0; while ((key = (TKey*)root_sucks())) { // infinite loop? ROOT does suck a lot! std::string dirpath = dir->GetPath(); dirpath = dirpath.substr(dirpath.rfind(":")+1); TObject* obj = key->ReadObj(); TDirectory* isDir = dynamic_cast<TDirectory*>(obj); if (isDir) { process_directory(isDir,ret); continue; } TTree* isTree = dynamic_cast<TTree*>(obj); if (isTree) { std::string path = "/"; // Catch trees in root directory if(dirpath != "/") path = dirpath + "/"; path += isTree->GetName(); ret.push_back(path); continue; } log << MSG::WARNING << "unexpected object " << obj->GetName() << " of type " << obj->ClassName() << " found in directory " << dirpath << endreq; } }
static int find_uniq | ( | TBranch * | branch | ) | [static] |
Definition at line 168 of file RootInputFile.cc.
{ static std::string name("RootIOBaseObject"); //cerr << "Checking branch " << branch->GetName() << std::endl; if (branch->GetName() == name) { TBranch* brID = branch->FindBranch("clID"); RootIOBaseObject riobo; brID->SetAddress(&riobo); brID->GetEntry(0); return riobo.clID; } TObjArray* branches = branch->GetListOfBranches(); TIter root_sucks(branches); branch=0; while ((branch = (TBranch*)root_sucks())) { int ret = find_uniq(branch); if (ret) return ret; } return 0; }