本文整理汇总了C++中TDirectory::GetMotherDir方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectory::GetMotherDir方法的具体用法?C++ TDirectory::GetMotherDir怎么用?C++ TDirectory::GetMotherDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDirectory
的用法示例。
在下文中一共展示了TDirectory::GetMotherDir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MergeComplexHistogramFile
//________________________________________________________________________________
void MergeComplexHistogramFile( const Char_t *TargetName=0, const Char_t *inputFilesPattern=0)
{
if (TargetName && TargetName[0] && inputFilesPattern && inputFilesPattern[0] ) {
printf(" An experimental version of macro.\n");
TStopwatch time;
Int_t fileCounter = 0;
Int_t dirCounter = 0;
Int_t treeCounter = 0;
Int_t histogramCounter = 0;
// Create the output file
TFile *outFile = TFile::Open(TargetName,"RECREATE");
TDirectory *outDir = outFile;
TDirIter listOfFiles(inputFilesPattern);
const char *fileName = 0;
while ( (fileName = listOfFiles.NextFile() ) ) {
Int_t currentDirDepth = 0;
printf(".");
fileCounter++;
StFileIter file(fileName);
TObject *obj = 0;
while ( (obj = *file) ) {
Int_t depth = file.GetDepth();
while (depth < currentDirDepth) {
outDir = outDir->GetMotherDir();
currentDirDepth--;
}
if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
// descendant of TH1 -> merge it
// printf("Merging histogram: %s\n",obj->GetName() );
// std::cout << "Merging histogram " << obj->GetName() << std::endl;
TH1 *h1 = (TH1*)obj;
TH1 *dstHistogram = 0;
// Check whether we found the new histogram
if ( (dstHistogram = (TH1 *)outDir->FindObject(h1->GetName()))) {
// Accumulate the histogram
dstHistogram->Add(h1);
delete h1; // Optional, to reduce the memory consumption
printf("h");
} else {
// First time - move the histogram
h1->SetDirectory(outDir);
printf(" The new Histogram found: %s \n", h1->GetName() );
histogramCounter++;
}
} else if ( obj->IsA()->InheritsFrom(TTree::Class()) ) {
// descendant of TTree -> merge it
// printf("Merging Tree %p:%s\n",obj, obj->GetName() );
TTree *tree = (TTree*)obj;
TTree *dstTree = 0;
// Check whether we found the new histogram
if ( (dstTree = (TTree *)outDir->FindObject(tree->GetName()))) {
// printf("Merging %p:%s with the existing Tree %p:%s\n"
// ,tree,tree->GetName(),dstTree, dstTree->GetName() );
// Merge the tree
TList *nextTree = new TList(); nextTree->Add(tree);
dstTree->Merge(nextTree);
delete tree; // Optional, to reduce the memory consumption
delete nextTree;
printf("t");
} else {
// First time - move the TTree
TDirectory *saveDir = 0;
if (outDir != gDirectory) {
saveDir = gDirectory;
outDir->cd();
}
TList *nextTree = new TList(); nextTree->Add(tree);
dstTree = TTree::MergeTrees(nextTree);
if (saveDir) saveDir->cd();
// printf(" The new TTree found: %p:%s \n",tree, tree->GetName() );
// printf(" Create the destination Tree %p:%s\n\n",dstTree, dstTree->GetName() );
delete tree; // Optional, to reduce the memory consumption
delete nextTree;
treeCounter++;
}
} else if ( obj->IsA()->InheritsFrom(TDirectory::Class()) ) {
printf("The input sub-TDirectory object: %s depth=%d\n",obj->GetName(), depth);
TDirectory *d = (TDirectory *)outDir->FindObject(obj->GetName());
if (!d) {
d = outDir->mkdir(obj->GetName());
dirCounter++;
printf("The new TDirectory object: %s depth=%d\n",d->GetPathStatic(), depth);
}
if (d) {
outDir = d;
printf("The output sub-TDirectory object: %s depth=%d\n",outDir->GetPathStatic(), depth);
}
} else {
printf("I have no idea how to merge the %s objects of the %s class. Skipping .... \n",obj->GetName(), obj->ClassName() );
}
++file;
}
}
printf("\n Finishing . . . \n");
outFile->Write(); // this creates a second copy of the TTree ???
outFile->Close();
delete outFile;
//.........这里部分代码省略.........