Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:34:24

0001 void CopyDir(TDirectory *source) {
0002    //copy all objects and subdirs of directory source as a subdir of the current directory   
0003    source->ls();
0004    TDirectory *savdir = gDirectory;
0005    TDirectory *adir = savdir->mkdir(source->GetName());
0006    adir->cd();
0007    //loop on all entries of this directory
0008    TKey *key;
0009    TIter nextkey(source->GetListOfKeys());
0010    while ((key = (TKey*)nextkey())) {
0011       const char *classname = key->GetClassName();
0012       TClass *cl = gROOT->GetClass(classname);
0013       if (!cl) continue;
0014       if (cl->InheritsFrom("TDirectory")) {
0015          source->cd(key->GetName());
0016          TDirectory *subdir = gDirectory;
0017          adir->cd();
0018          CopyDir(subdir);
0019          adir->cd();
0020       } else if (cl->InheritsFrom("TTree")) {
0021          TTree *T = (TTree*)source->Get(key->GetName());
0022          adir->cd();
0023          TTree *newT = T->CloneTree(-1,"fast");
0024          newT->Write();
0025       } else {
0026          source->cd();
0027          TObject *obj = key->ReadObj();
0028          adir->cd();
0029          obj->Write();
0030          delete obj;
0031      }
0032   }
0033   adir->SaveSelf(kTRUE);
0034   savdir->cd();
0035 }
0036 
0037 //void CopySubdir(const char * oldfile, const char * newfile, const char * dirname, const char * type="Track"){
0038 void CopySubdir(const char* oldfile, const char* newfile) {
0039 
0040   TFile *oldf = TFile::Open(oldfile);
0041   //bool success=oldf->cd(Form("DQMData/Run 1/Vertexing/V0V/Run summary/%s",type));
0042   bool success = oldf->cd("DQMData/Run 1/Vertexing/V0V/Run summary/EffFakes");
0043   //  cerr<<success<<endl;
0044   //cerr<<Form("DQMData/RecoTrackV/%s",type)<<endl;
0045   //if(!success)success=oldf->cd(Form("DQMData/RecoTrackV/%s",type));
0046   if(!success) success = oldf->cd("DQMData/Vertexing/V0V/EffFakes");
0047   //  cerr<<success<<endl;
0048   gDirectory->ls();
0049   TDirectory *dirold=gDirectory;
0050   //dirold->cd(dirname);
0051   //dirold=gDirectory;
0052   TFile *newf =new TFile(newfile,"RECREATE");
0053   TDirectory *dirnew=newf->mkdir("DQMData");
0054   dirnew=dirnew->mkdir("Run 1");
0055   dirnew=dirnew->mkdir("Vertexing");
0056   dirnew=dirnew->mkdir("V0V");
0057   dirnew=dirnew->mkdir("Run summary");
0058   //dirnew = dirnew->mkdir("EffFakes");
0059   //dirnew=dirnew->mkdir(type);
0060   gDirectory=dirnew;
0061   //  dirold->ls();
0062   CopyDir(dirold);
0063 
0064   gDirectory = dirold;
0065 
0066   success = oldf->cd("DQMData/Run 1/Vertexing/V0V/Run summary/Other");
0067   if(!success) success = oldf->cd("DQMData/Vertexing/V0V/Other");
0068   TDirectory *dirold2 = gDirectory;
0069   //bool success1 = newf->cd("DQMData/Run 1/Vertexing/V0V/Run summary");
0070   //TDirectory* dirnew2 = newf->mkdir("Other");
0071   gDirectory = dirnew;
0072   CopyDir(dirold2);
0073 
0074   
0075 }