/[PAMELA software]/PadmeAmidala/src/RunGlue.cpp
ViewVC logotype

Diff of /PadmeAmidala/src/RunGlue.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by mocchiut, Thu Dec 7 11:53:26 2006 UTC revision 1.5 by mocchiut, Tue Jan 9 10:19:54 2007 UTC
# Line 11  Line 11 
11  #include <TFile.h>  #include <TFile.h>
12  #include <TTree.h>  #include <TTree.h>
13  #include <TTimeStamp.h>  #include <TTimeStamp.h>
14    #include <TTreeCloner.h>
15  #include <RunGlue.h>  #include <RunGlue.h>
16  //  //
17  ClassImp(RunGlue);  ClassImp(RunGlue);
# Line 391  Bool_t RunGlue::OpenFile(){ Line 392  Bool_t RunGlue::OpenFile(){
392      //      //
393      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
394      //      //
395      Long64_t maxsize = 10000000000LL;        Long64_t maxsize = 99900000000LL;  
396      //      //
397      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
398      //fastMethod = kTRUE;      //fastMethod = kTRUE;
# Line 404  Bool_t RunGlue::OpenFile(){ Line 405  Bool_t RunGlue::OpenFile(){
405      }      }
406      //      //
407      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
408        Target->SetCompressionLevel(2);
409      //      //
410      fOpen = true;      fOpen = true;
411      return(true);      return(true);
# Line 546  void RunGlue::MergeRootfile(TList *sourc Line 548  void RunGlue::MergeRootfile(TList *sourc
548      //      //
549      TChain *globChain = 0;      TChain *globChain = 0;
550      TIter nextkey( current_sourcedir->GetListOfKeys() );      TIter nextkey( current_sourcedir->GetListOfKeys() );
551      TKey *key, *oldkey=0;      TKey *key = 0;
552        TKey *oldkey = 0;
553      TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory      TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory
554      //      //
555      while ( (key = (TKey*)nextkey()) ) {      while ( (key = (TKey*)nextkey()) ) {
556        //        //
557          //      printf(" target ls \n");
558          //      Target->ls();
559          //
560        if ( current_sourcedir == target ) break;        if ( current_sourcedir == target ) break;
561        //        //
562        if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue; //keep only the highest cycle number for each key        if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
563        //        //
564        if (allNames.FindObject(key->GetName())) continue;        if ( allNames.FindObject(key->GetName()) ) continue;
565        //        //
566        if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());        if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
567        //        //
# Line 643  void RunGlue::MergeRootfile(TList *sourc Line 649  void RunGlue::MergeRootfile(TList *sourc
649            nextsource = (TFile*)sourcelist->After(nextsource);            nextsource = (TFile*)sourcelist->After(nextsource);
650          };          };
651          //          //
652            delete nextsource;
653            //
654        } else {        } else {
655          //          //
656          // object is of no type that we know or can handle          // object is of no type that we know or can handle
# Line 662  void RunGlue::MergeRootfile(TList *sourc Line 670  void RunGlue::MergeRootfile(TList *sourc
670          //          //
671          if( obj->IsA()->InheritsFrom("TTree") ) {          if( obj->IsA()->InheritsFrom("TTree") ) {
672            //            //
673            //            Long64_t nfiles = 0;
674            if ( fastMethod ){            if ( fastMethod ){
675              globChain->Merge(target->GetFile(),0,"keep fast");              //      globChain->Merge(target->GetFile(),0,"C keep fast");
676                nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");
677            } else {            } else {
678              globChain->Merge(target->GetFile(),0,"keep");              //globChain->Merge(target->GetFile(),0,"C keep");
679                nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");
680            };            };
681            //            //
682            merged = true;            merged = true;
683            //            //
684            if ( DebugMode() ) globChain->ls();            if ( DebugMode() ){
685                printf(" Merged %i files\n",(int)nfiles);
686                globChain->ls();
687              };
688            //            //
689            delete globChain;            delete globChain;
690              //      return;
691            //            //
692          } else {          } else {
693            //            //
# Line 681  void RunGlue::MergeRootfile(TList *sourc Line 695  void RunGlue::MergeRootfile(TList *sourc
695            //            //
696          };          };
697        };        };
698          delete obj;
699        oldkey = key;        oldkey = key;
700      };      };
701      //      //
# Line 688  void RunGlue::MergeRootfile(TList *sourc Line 703  void RunGlue::MergeRootfile(TList *sourc
703      //      //
704    };    };
705    // save modifications to target file    // save modifications to target file
706      //
707    target->SaveSelf(kTRUE);    target->SaveSelf(kTRUE);
708    //    //
709    };
710    
711    
712    Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){
713       // We must have been passed a file, we will use it
714       // later to reset the compression level of the branches.
715       if (!file) {
716          // FIXME: We need an error message here.
717         return 0;
718       }
719    
720       // Options
721       Bool_t fastClone = kFALSE;
722       TString opt = option;
723       opt.ToLower();
724       if (opt.Contains("fast")) {
725          fastClone = kTRUE;
726       }
727    
728       // The chain tree must have a list of branches
729       // because we may try to change their basket
730       // size later.
731       TObjArray* lbranches = mychain->GetListOfBranches();
732       if (!lbranches) {
733          // FIXME: We need an error message here.
734          return 0;
735       }
736    
737       // The chain must have a current tree because
738       // that is the one we will clone.
739       //   if (!fTree) {
740          // -- LoadTree() has not yet been called, no current tree.
741          // FIXME: We need an error message here.
742       //      return 0;
743       //   }
744    
745       // Copy the chain's current tree without
746       // copying any entries, we will do that later.
747       TTree* newTree = mychain->CloneTree(0);
748       if (!newTree) {
749          // FIXME: We need an error message here.
750          return 0;
751       }
752    
753       // Strip out the (potential) directory name.
754       // FIXME: The merged chain may or may not have the
755       //        same name as the original chain.  This is
756       //        bad because the chain name determines the
757       //        names of the trees in the chain by default.
758       newTree->SetName(gSystem->BaseName(mychain->GetName()));
759    
760       // FIXME: Why do we do this?
761       //   newTree->SetAutoSave(-1);
762       newTree->SetAutoSave(900000000000000LL);
763    
764       // Circularity is incompatible with merging, it may
765       // force us to throw away entries, which is not what
766       // we are supposed to do.
767       newTree->SetCircular(0);
768    
769       // Reset the compression level of the branches.
770       if (opt.Contains("c")) {
771          TBranch* branch = 0;
772          TIter nextb(newTree->GetListOfBranches());
773          while ((branch = (TBranch*) nextb())) {
774             branch->SetCompressionLevel(file->GetCompressionLevel());
775          }
776       }
777    
778       // Reset the basket size of the branches.
779       if (basketsize > 1000) {
780          TBranch* branch = 0;
781          TIter nextb(newTree->GetListOfBranches());
782          while ((branch = (TBranch*) nextb())) {
783             branch->SetBasketSize(basketsize);
784          }
785       }
786    
787       Long64_t nentries = mychain->GetEntriesFast();
788    
789       // Copy the entries.
790       if (fastClone) {
791          // For each tree in the chain.
792          for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
793             if (mychain->LoadTree(i) < 0) {
794                break;
795             }
796             TTreeCloner cloner(mychain->GetTree(), newTree, option);
797             if (cloner.IsValid()) {
798                newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
799                cloner.Exec();
800             } else {
801                if (mychain->GetFile()) {
802                  printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
803                   //            } else {
804                   //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
805                }
806             }
807          }
808       } else {
809          for (Long64_t i = 0; i < nentries; i++) {
810             if (mychain->GetEntry(i) <= 0) {
811                break;
812             }
813             newTree->Fill();
814          }
815       }
816    
817       // Write the new tree header.
818       newTree->Write();
819    
820       // Get our return value.
821       Int_t nfiles = newTree->GetFileNumber() + 1;
822    
823       // Close and delete the current file of the new tree.
824       if (!opt.Contains("keep")) {
825          // FIXME: What happens to fDirectory in newTree here?
826          delete newTree->GetCurrentFile();
827       }
828       return nfiles;
829  }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.23