本文整理汇总了C++中TDirectoryFile::ClassName方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectoryFile::ClassName方法的具体用法?C++ TDirectoryFile::ClassName怎么用?C++ TDirectoryFile::ClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDirectoryFile
的用法示例。
在下文中一共展示了TDirectoryFile::ClassName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mergeForest
void mergeForest(TString fname = "/data/jisun/temp/*.root",
TString outfile="/data/jisun/pp_2015_HeavyFlavor_AOD_tkpt1_D0pt1_eta2p5_D3d1_Prob0p05_1202.root",
bool failOnError = true)
{
// First, find on of the files within 'fname' and use it to make a
// list of trees. Unfortunately we have to know in advance at least
// one of the tree names. hiEvtAnalyzer/HiTree is a safe choice for
// HiForests. We also assume that every TTree is inside a
// TDirectoryFile which is in the top level of the root file.
TChain *dummyChain = new TChain("hltanalysis/HltTree");
dummyChain->Add(fname);
TFile *testFile = dummyChain->GetFile();
TList *topKeyList = testFile->GetListOfKeys();
std::vector<TString> trees;
std::vector<TString> dir;
for(int i = 0; i < topKeyList->GetEntries(); ++i)
{
TDirectoryFile *dFile = (TDirectoryFile*)testFile->Get(topKeyList->At(i)->GetName());
if(strcmp(dFile->ClassName(), "TDirectoryFile") != 0) continue;
TList *bottomKeyList = dFile->GetListOfKeys();
for(int j = 0; j < bottomKeyList->GetEntries(); ++j)
{
TString treeName = dFile->GetName();
treeName += "/";
treeName += bottomKeyList->At(j)->GetName();
TTree* tree = (TTree*)testFile->Get(treeName);
if(strcmp(tree->ClassName(), "TTree") != 0 && strcmp(tree->ClassName(), "TNtuple") != 0) continue;
trees.push_back(treeName);
dir.push_back(dFile->GetName());
}
}
testFile->Close();
delete dummyChain;
// Now use the list of tree names to make a new root file, filling
// it with the trees from 'fname'.
const int Ntrees = trees.size();
TChain* ch[Ntrees];
Long64_t nentries = 0;
for(int i = 0; i < Ntrees; ++i){
ch[i] = new TChain(trees[i]);
ch[i]->Add(fname);
std::cout << "Tree loaded : " << trees[i] << std::endl;
std::cout << "Entries : " << ch[i]->GetEntries() << std::endl;
// If the number of entries in this tree is different from other
// trees there is a problem. Quit and inform the user without
// producing output.
if(failOnError)
{
if(strcmp(trees[i],"HiForest/HiForestVersion") == 0) continue;
if(i == 0) nentries = ch[i]->GetEntries();
else if (nentries != ch[i]->GetEntries())
{
std::cout << "ERROR: number of entries in this tree does not match." << std::endl;
std::cout << "First inconsistent file: " <<ch[i]->GetFile()->GetName()<<std::endl;
std::cout << "Exiting. Please check input." << std::endl;
return;
}
}
else
{
std::cout << "WARN: error checking disabled" << std::endl;
}
}
TFile* file = new TFile(outfile, "RECREATE");
for(int i = 0; i < Ntrees; ++i)
{
file->cd();
std::cout << trees[i] << std::endl;
if (i==0)
{
file->mkdir(dir[i])->cd();
}
else
{
if ( dir[i] != dir[i-1] )
file->mkdir(dir[i])->cd();
else
file->cd(dir[i]);
}
ch[i]->Merge(file,0,"keep");
delete ch[i];
}
//file->Write();
file->Close();
std::cout << "Done. Output: " << outfile << std::endl;
}