25 void CopyDir(TDirectory *source) {
28 TDirectory *savdir = gDirectory;
29 TDirectory *adir = savdir->mkdir(source->GetName());
35 TIter nextkey(source->GetListOfKeys(),kIterBackward);
36 while ((key = (TKey*)nextkey())) {
37 const char *classname = key->GetClassName();
38 TClass *cl = gROOT->GetClass(classname);
40 if (cl->InheritsFrom(TDirectory::Class())) {
41 source->cd(key->GetName());
42 TDirectory *subdir = gDirectory;
46 }
else if (cl->InheritsFrom(TTree::Class())) {
47 TTree *T = (TTree*)source->Get(key->GetName());
51 if (!adir->FindObject(key->GetName())) {
53 TTree *newT = T->CloneTree(-1,
"fast");
58 TObject *obj = key->ReadObj();
64 adir->SaveSelf(kTRUE);
67 void CopyFile(
const char *fname) {
69 TDirectory *target = gDirectory;
70 TFile *f = TFile::Open(fname);
71 if (!f || f->IsZombie()) {
72 printf(
"Cannot copy file: %s\n",fname);
83 if(gSystem->AccessPathName(
"tot100.root")) {
84 gSystem->CopyFile(
"hsimple.root",
"tot100.root");
85 gSystem->CopyFile(
"hsimple.root",
"hs1.root");
86 gSystem->CopyFile(
"hsimple.root",
"hs2.root");
89 TFile *f =
new TFile(
"result.root",
"recreate");
90 CopyFile(
"tot100.root");
91 CopyFile(
"hsimple.root");