Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:41

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){
0038 
0039   TFile *oldf = TFile::Open(oldfile);
0040   oldf->cd("DQMData/Run 1/Tracking");
0041   TDirectory *dirtracking=gDirectory;
0042   oldf->cd("DQMData/Run 1/TrackerHitsV");
0043   TDirectory *dirsimhit=gDirectory;
0044   oldf->cd("DQMData/Run 1/TrackerRecHitsV");
0045   TDirectory *dirrechits=gDirectory;
0046   oldf->cd("DQMData/Run 1/TrackerDigisV");
0047   TDirectory *dirdigis=gDirectory;
0048   oldf->cd("DQMData/Run 1/Tracking");
0049   TDirectory *dirTP=gDirectory;
0050   TFile *newf =new TFile(newfile,"RECREATE");
0051   TDirectory *dirnew=newf->mkdir("DQMData");
0052   dirnew=dirnew->mkdir("Run 1");
0053   dirnew->cd();
0054   CopyDir(dirtracking);
0055   CopyDir(dirsimhit);
0056   CopyDir(dirrechits);
0057   CopyDir(dirdigis);
0058   CopyDir(dirTP);
0059   TList* new_list = oldf->GetListOfKeys() ;
0060   newf->cd();
0061   TIter     newkey_iter( new_list) ;
0062   TKey*     new_key ;
0063   TObject*  new_obj ;
0064   while ( new_key = (TKey*) newkey_iter() ) {
0065     new_obj = new_key->ReadObj() ;
0066     if (strcmp(new_obj->IsA()->GetName(),"TObjString")==0) {
0067       TObjString * cversion = (TObjString*) new_obj;
0068       if(cversion->GetString().Contains("CMSSW")){
0069     cversion->Write();
0070     break;
0071       }
0072     }
0073   }
0074 }