/[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.13 by mocchiut, Thu Dec 11 10:41:11 2008 UTC revision 1.15 by mocchiut, Fri Jan 30 09:37:18 2009 UTC
# Line 394  Bool_t RunGlue::OpenFile(){ Line 394  Bool_t RunGlue::OpenFile(){
394      return(false);      return(false);
395    } else {    } else {
396      //      //
397        //    Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
398        Target = TFile::Open((this->GetFilename()).Data(), "NEW" );    
399        //    
400      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
401      //      //
402      Long64_t maxsize = 99900000000LL;        Long64_t maxsize = 99900000000LL;  
403      //      //
404      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      if ( !Target || Target->IsZombie()) {
405          printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data());
406          //      exit(1);
407          return(false);
408        }
409        //
410        Target->Write();
411        //
412      //fastMethod = kTRUE;      //fastMethod = kTRUE;
413      fastMethod = kFALSE;      fastMethod = kFALSE;
414      //          //    
     //      
     if ( !Target || Target->IsZombie()) {  
       printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());  
       exit(1);  
     }  
415      //      //
416      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
417      //    Target->SetCompressionLevel(2);      //    Target->SetCompressionLevel(2);
# Line 534  void RunGlue::MergeRootfile(TList *sourc Line 539  void RunGlue::MergeRootfile(TList *sourc
539    //    //
540    if ( li ) li->Delete();    if ( li ) li->Delete();
541    li = new PamLevel2(wd,sourcelist,fDList);    li = new PamLevel2(wd,sourcelist,fDList);
542      li->SetSELLI(2);
543    //    //
544    Target->cd();    Target->cd();
545    //    //
# Line 550  void RunGlue::MergeRootfile(TList *sourc Line 556  void RunGlue::MergeRootfile(TList *sourc
556    li->WriteCloneTrees();    li->WriteCloneTrees();
557    printf("Written file %s \n",Target->GetName());    printf("Written file %s \n",Target->GetName());
558    //  Target->Write();    //  Target->Write();
559    TTree *slist = (TTree*)Target->Get("SelectionList");    //  TTree *slist = (TTree*)Target->Get("SelectionList");
560    slist->Delete("all");    //  slist->Delete("all");
561    Target->Close();    Target->Close();
562    
563  //   //  //   //
# Line 755  void RunGlue::MergeRootfile(TList *sourc Line 761  void RunGlue::MergeRootfile(TList *sourc
761  };  };
762    
763    
764  Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){  // Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){
765     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
766     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
767     if (!file) {  //    if (!file) {
768        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
769       printf(" 19 \n");  //      printf(" 19 \n");
770       return 0;  //      return 0;
771     }  //    }
772     printf(" 20 \n");  //    printf(" 20 \n");
773    
774     // Options  //    // Options
775     Bool_t fastClone = kFALSE;  //    Bool_t fastClone = kFALSE;
776     TString opt = option;  //    TString opt = option;
777     opt.ToLower();  //    opt.ToLower();
778     if (opt.Contains("fast")) {  //    if (opt.Contains("fast")) {
779        fastClone = kTRUE;  //       fastClone = kTRUE;
780        printf(" 21 \n");  //       printf(" 21 \n");
781     }  //    }
782     // The chain tree must have a list of branches  //    // The chain tree must have a list of branches
783     // because we may try to change their basket  //    // because we may try to change their basket
784     // size later.  //    // size later.
785     TObjArray* lbranches = mychain->GetListOfBranches();  //    TObjArray* lbranches = mychain->GetListOfBranches();
786     if (!lbranches) {  //    if (!lbranches) {
787        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
788       printf(" 22 \n");  //      printf(" 22 \n");
789        return 0;  //       return 0;
790     }  //    }
791    
792     //   file->cd();  //    //   file->cd();
793     // The chain must have a current tree because  //    // The chain must have a current tree because
794     // that is the one we will clone.  //    // that is the one we will clone.
795     //   if (!fTree) {  //    //   if (!fTree) {
796        // -- LoadTree() has not yet been called, no current tree.  //       // -- LoadTree() has not yet been called, no current tree.
797        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
798     //      return 0;  //    //      return 0;
799     //   }  //    //   }
800    
801     // Copy the chain's current tree without  //    // Copy the chain's current tree without
802     // copying any entries, we will do that later.  //    // copying any entries, we will do that later.
803     printf(" 23 \n");  //    printf(" 23 \n");
804     TTree* newTree = mychain->CloneTree(0);  //    TTree* newTree = mychain->CloneTree(0);
805     if (!newTree) {  //    if (!newTree) {
806        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
807       printf(" 24 \n");  //      printf(" 24 \n");
808        return 0;  //       return 0;
809     }  //    }
810     printf(" 25 \n");  //    printf(" 25 \n");
811    
812    
813     // Strip out the (potential) directory name.  //    // Strip out the (potential) directory name.
814     // FIXME: The merged chain may or may not have the  //    // FIXME: The merged chain may or may not have the
815     //        same name as the original chain.  This is  //    //        same name as the original chain.  This is
816     //        bad because the chain name determines the  //    //        bad because the chain name determines the
817     //        names of the trees in the chain by default.  //    //        names of the trees in the chain by default.
818     printf(" 26 \n");  //    printf(" 26 \n");
819     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
820     printf(" 27 \n");  //    printf(" 27 \n");
821    
822     // FIXME: Why do we do this?  //    // FIXME: Why do we do this?
823     //   newTree->SetAutoSave(-1);  //    //   newTree->SetAutoSave(-1);
824     newTree->SetAutoSave(900000000000000LL);  //    newTree->SetAutoSave(900000000000000LL);
825    
826     printf(" 28 \n");  //    printf(" 28 \n");
827     // Circularity is incompatible with merging, it may  //    // Circularity is incompatible with merging, it may
828     // force us to throw away entries, which is not what  //    // force us to throw away entries, which is not what
829     // we are supposed to do.  //    // we are supposed to do.
830     newTree->SetCircular(0);  //    newTree->SetCircular(0);
831    
832     // Reset the compression level of the branches.  //    // Reset the compression level of the branches.
833     if (opt.Contains("c")) {  //    if (opt.Contains("c")) {
834        TBranch* branch = 0;  //       TBranch* branch = 0;
835        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
836        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
837          printf(" 29 \n");  //      printf(" 29 \n");
838           branch->SetCompressionLevel(file->GetCompressionLevel());  //          branch->SetCompressionLevel(file->GetCompressionLevel());
839        }  //       }
840     }  //    }
841    
842     printf(" 30 \n");  //    printf(" 30 \n");
843     // Reset the basket size of the branches.  //    // Reset the basket size of the branches.
844     if (basketsize > 1000) {  //    if (basketsize > 1000) {
845        TBranch* branch = 0;  //       TBranch* branch = 0;
846        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
847        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
848          printf(" 31 \n");  //      printf(" 31 \n");
849           branch->SetBasketSize(basketsize);  //          branch->SetBasketSize(basketsize);
850        }  //       }
851     }  //    }
852    
853     printf(" 32 \n");  //    printf(" 32 \n");
854     Long64_t nentries = mychain->GetEntriesFast();  //    Long64_t nentries = mychain->GetEntriesFast();
855     //Long64_t nentries = mychain->GetEntries();  //    //Long64_t nentries = mychain->GetEntries();
856    
857     // Copy the entries.  //    // Copy the entries.
858     if (fastClone) {  //    if (fastClone) {
859        // For each tree in the chain.  //       // For each tree in the chain.
860        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
861           if (mychain->LoadTree(i) < 0) {  //          if (mychain->LoadTree(i) < 0) {
862              break;  //             break;
863           }  //          }
864           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
865           if (cloner.IsValid()) {  //          if (cloner.IsValid()) {
866              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
867              cloner.Exec();  //             cloner.Exec();
868           } else {  //          } else {
869              if (mychain->GetFile()) {  //             if (mychain->GetFile()) {
870                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
871                 //            } else {  //             //            } else {
872                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
873              }  //             }
874           }  //          }
875        }  //       }
876     } else {  //    } else {
877       printf(" 33 %llu \n",nentries);  //      printf(" 33 %llu \n",nentries);
878       mychain->Print();  //      mychain->Print();
879       for (Long64_t i = 0; i < nentries; i++) {  //      for (Long64_t i = 0; i < nentries; i++) {
880         printf(" i %llu \n",i);  //        printf(" i %llu \n",i);
881         // for (Long64_t i = 0; i < 1; i++) {  //        // for (Long64_t i = 0; i < 1; i++) {
882           if (mychain->GetEntry(i) <= 0) {  //          if (mychain->GetEntry(i) <= 0) {
883              break;  //             break;
884           }  //          }
885           newTree->Fill();  //          newTree->Fill();
886        }  //       }
887        printf(" 34 \n");  //       printf(" 34 \n");
888     }  //    }
889    
890     // Write the new tree header.  //    // Write the new tree header.
891     printf(" 35 \n");  //    printf(" 35 \n");
892     newTree->Write();  //    newTree->Write();
893    
894     printf(" 36 \n");  //    printf(" 36 \n");
895     // Get our return value.  //    // Get our return value.
896     Int_t nfiles = newTree->GetFileNumber() + 1;  //    Int_t nfiles = newTree->GetFileNumber() + 1;
897    
898     // Close and delete the current file of the new tree.  //    // Close and delete the current file of the new tree.
899     if (!opt.Contains("keep")) {  //    if (!opt.Contains("keep")) {
900        // FIXME: What happens to fDirectory in newTree here?  //       // FIXME: What happens to fDirectory in newTree here?
901        delete newTree->GetCurrentFile();  //       delete newTree->GetCurrentFile();
902     }  //    }
903     return nfiles;  //    return nfiles;
904  }  // }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23