/[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.10 by mocchiut, Fri Sep 7 13:26:11 2007 UTC revision 1.15 by mocchiut, Fri Jan 30 09:37:18 2009 UTC
# Line 5  Line 5 
5   * The file contains implementation of the methods to query the DB.   * The file contains implementation of the methods to query the DB.
6   */   */
7  //  //
8    #include <sstream>
9    #include <iostream>
10    //
11    #include <TFile.h>
12    #include <TTree.h>
13    #include <TTimeStamp.h>
14    #include <TTreeCloner.h>
15  #include <RunGlue.h>  #include <RunGlue.h>
16  //  //
17  ClassImp(RunGlue);  ClassImp(RunGlue);
# Line 15  RunGlue::RunGlue() { Line 22  RunGlue::RunGlue() {
22    this->Clear();    this->Clear();
23  }  }
24    
25  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi, Bool_t fcas) {  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) {
26    fDBG = false;    fDBG = false;
   castor = fcas;  
27    li = new PamLevel2();    li = new PamLevel2();
28      //  li = 0;
29    this->Clear();    this->Clear();
30    dbc = da;    dbc = da;
31    run = ru;    run = ru;
32    dir = di;    dir = di;
33    //    //
34    TString wd = gSystem->WorkingDirectory();      wd = gSystem->WorkingDirectory();  
35    //    //
36    outdir = wrkdi;    outdir = wrkdi;
37    if ( !strcmp(outdir.Data(),"") ) outdir = wd;    if ( !strcmp(outdir.Data(),"") ) outdir = wd;
# Line 40  RunGlue::RunGlue(TSQLServer *da, UInt_t Line 47  RunGlue::RunGlue(TSQLServer *da, UInt_t
47    //    //
48  };  };
49    
   
50  void RunGlue::Clear() {  void RunGlue::Clear() {
51    fEnd = false;    fEnd = false;
52    run = 0;    run = 0;
# Line 69  void RunGlue::SetDList(TString list) { Line 75  void RunGlue::SetDList(TString list) {
75    if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true;    if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true;
76    //    //
77    fDList = list;    fDList = list;
78    li->SetWhichTrees(fDList);    //  li->SetWhichTrees(fDList);
79    //    //
80    if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data());    if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data());
81    //    //
82  };  };
83    
84  TList *RunGlue::GetRunList(){  TList *RunGlue::GetRunList(){
85    //    //  
86    lList = new TList();    lList = new TList();
87    lList->Clear();    lList->Clear();
88    TString thisrun;    TString thisrun;
   //  TFile *su;  
89    TFile *su;    TFile *su;
90    //    //
91    TSQLResult *pResult;    TSQLResult *pResult;
# Line 164  TList *RunGlue::GetRunList(){ Line 169  TList *RunGlue::GetRunList(){
169        //        //
170        if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());        if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
171        //        //
       //su = TFile::Open(thisrun);  
172        su = TFile::Open(thisrun);        su = TFile::Open(thisrun);
173        if ( li->CheckLevel2File(thisrun) ){        if ( li->CheckLevel2File(thisrun) ){
174          lList->Add(su);          lList->Add(su);
175        } else {        } else {
176          if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));                  if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
177        };        };
178        //        //
179      };      };
# Line 208  TList *RunGlue::GetRunList(){ Line 212  TList *RunGlue::GetRunList(){
212            if ( DebugMode() ) printf(" fullpath = %s     name %s \n",fullpath.Data(),name.Data());            if ( DebugMode() ) printf(" fullpath = %s     name %s \n",fullpath.Data(),name.Data());
213            //            //
214            //            //
           //su = TFile::Open(fullpath);  
215            su = TFile::Open(fullpath);            su = TFile::Open(fullpath);
216            if ( li->CheckLevel2File((TString)fullpath) ){            if ( li->CheckLevel2File((TString)fullpath) ){
217              fList->Add(su);              fList->Add(su);
# Line 332  TList *RunGlue::GetRunList(){ Line 335  TList *RunGlue::GetRunList(){
335        //        //
336        su = TFile::Open(thisrun);        su = TFile::Open(thisrun);
337        if ( su ){        if ( su ){
         //      TFile *su0 = TFile::Open(thisrun);  
338          TFile *su0 = TFile::Open(thisrun);          TFile *su0 = TFile::Open(thisrun);
339          fDoneList->Add(su0);          fDoneList->Add(su0);
340          fNlistdone++;          fNlistdone++;
# Line 378  TList *RunGlue::GetRunList(){ Line 380  TList *RunGlue::GetRunList(){
380    
381  Bool_t RunGlue::OpenFile(){  Bool_t RunGlue::OpenFile(){
382    //    //
   ifstream myfile;  
   TString thename;  
   //  
   Bool_t exi = false;  
383    fOpen = false;    fOpen = false;
384    thename = Form("rfio://%s",(this->GetFilename()).Data());    printf(" Check if output file already exists \n");
385    Target = 0;    ifstream myfile;
386    if ( castor ){    myfile.open((this->GetFilename()).Data());
387      Target = new TRFIOFile(thename.Data(),"READ","",1);    if ( myfile ){
     if ( !Target->IsZombie()) exi = true;  
   } else {  
     //    thename = Form("rfio://%s",(this->GetFilename()).Data());  
     printf(" Check if output file already exists \n");  
     myfile.open((this->GetFilename()).Data());  
     if ( myfile ) exi = true;  
   };  
   if ( exi ){  
388      //  Target = TFile::Open((this->GetFilename()).Data(), "READ" );      //  Target = TFile::Open((this->GetFilename()).Data(), "READ" );
389      //      //
390      //  if ( Target ){      //  if ( Target ){
391      //    Target->Close();      //    Target->Close();
392      if ( myfile ) myfile.close();      myfile.close();
393      //      printf("Error opening target file, %s  already exist!\n",(this->GetFilename()).Data());
     if ( Target ) Target->Close();  
     //  
     printf("Error opening target file, %s  already exist!\n",thename.Data());  
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 = new TRFIOFile(thename.Data(), "RECREATE", "", 2 );      if ( !Target || Target->IsZombie()) {
405      //      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );        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",thename.Data());  
       exit(1);  
     }  
415      //      //
416      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
417      Target->SetCompressionLevel(2);      //    Target->SetCompressionLevel(2);
418        Target->SetCompressionLevel(3);
419        //Target->SetCompressionLevel(5);
420      //      //
421      fOpen = true;      fOpen = true;
422      return(true);      return(true);
# Line 544  void RunGlue::UpdateDB(TList *dlist){ Line 535  void RunGlue::UpdateDB(TList *dlist){
535  //  //
536  void RunGlue::MergeRootfile(TList *sourcelist) {  void RunGlue::MergeRootfile(TList *sourcelist) {
537    //    //
538    merged = false;    merged = true;
   //  
   TDirectory *target = Target;  
   //  
   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());  
   //  
   TString path;  
   //if ( castor ){  
     path = TString(":/");  
     //  } else {  
     //    path = TString( (char*)strstr( target->GetPath(), ":" ) );  
     //  };  
   path.Remove(0,2);  
   if ( DebugMode() ) printf("path is %s \n",path.Data());  
   //  
   TDirectory *first_source = (TDirectory*)sourcelist->First();  
   THashList allNames;  
   //  
   while ( first_source ){  
     //  
     TDirectory *current_sourcedir = first_source->GetDirectory(path);  
     //  
     if ( !current_sourcedir ){  
       first_source = (TDirectory*)sourcelist->After(first_source);  
       continue;  
     }  
     //  
     // loop over all keys in this directory  
     //  
     TChain *globChain = 0;      
     TIter nextkey( current_sourcedir->GetListOfKeys() );  
     TKey *key = 0;  
     TKey *oldkey = 0;  
     TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory  
     //  
     while ( (key = (TKey*)nextkey()) ) {  
       //  
       //      printf(" target ls \n");  
       //      Target->ls();  
       //  
       if ( current_sourcedir == target ) break;  
       //  
       if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key  
       //  
       if ( allNames.FindObject(key->GetName()) ) continue;  
       //  
       if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());  
       //  
       //  
       //  
       if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;  
       //  
       if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;  
       //  
       if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){  
         if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());  
         continue;  
       };  
       //  
       allNames.Add(new TObjString(key->GetName()));  
       //  
       // read object from first source file  
       //  
       current_sourcedir->cd();  
       TObject *obj = key->ReadObj();  
       //  
       if ( obj->IsA()->InheritsFrom("TTree") ){  
         //  
         // loop over all source files create a chain of Trees "globChain"  
         //  
         TString obj_name;  
         //  
         if ( path.Length() ) {  
           obj_name = path + "/" + obj->GetName();  
         } else {  
           obj_name = obj->GetName();  
         };  
         //  
         globChain = new TChain(obj_name);  
         //  
         globChain->SetCacheSize(0);  
         //  
         globChain->Add(first_source->GetName());  
         //  
         //      TFile *nextsource = (TFile*)sourcelist->After( first_source );  
         TFile *nextsource = (TFile*)sourcelist->After( first_source );  
         //  
         while ( nextsource ) {              
           //  
           //do not add to the list a file that does not contain this Tree  
           //  
           TFile *curf = TFile::Open(nextsource->GetName());  
           //      TFile *curf = TFile::Open(nextsource->GetName());  
           //  
           if ( curf ) {  
             //  
             Bool_t mustAdd = kFALSE;  
             //  
             if (curf->FindKey(obj_name)) {  
               //  
               mustAdd = kTRUE;  
               //  
             } else {  
               //  
               //we could be more clever here. No need to import the object  
               //we are missing a function in TDirectory  
               //  
               TObject *aobj = curf->Get(obj_name);  
               //  
               if ( aobj ){  
                 mustAdd = kTRUE;  
                 delete aobj;  
               };  
             };  
             if (mustAdd) {  
               globChain->Add(nextsource->GetName());  
             };  
           };  
           delete curf;  
           nextsource = (TFile*)sourcelist->After(nextsource);  
         };  
         //  
         delete nextsource;  
         //  
       } else {  
         //  
         // object is of no type that we know or can handle  
         //  
         if ( DebugMode() ) cout << "Unknown object type, name: "  
              << obj->GetName() << " title: " << obj->GetTitle() << endl;  
       };  
       //  
       // now write the merged histogram (which is "in" obj) to the target file  
       // note that this will just store obj in the current directory level,  
       // which is not persistent until the complete directory itself is stored  
       // by "target->Write()" below  
       //  
       if ( obj ){  
         //  
         target->cd();  
         //  
         if( obj->IsA()->InheritsFrom("TTree") ) {  
           //  
           Long64_t nfiles = 0;  
           if ( fastMethod ){  
             //      globChain->Merge(target->GetFile(),0,"C keep fast");  
             nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");  
           } else {  
             //globChain->Merge(target->GetFile(),0,"C keep");  
             nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");  
           };  
           //  
           merged = true;  
           //  
           if ( DebugMode() ){  
             printf(" Merged %i files\n",(int)nfiles);  
             globChain->ls();  
           };  
           //  
           delete globChain;  
           //      return;  
           //  
         } else {  
           //  
           //      obj->Write( key->GetName() ); // <==================================================================================  
           //  
         };  
       };  
       delete obj;  
       oldkey = key;  
     };  
     //  
     first_source = (TDirectory*)sourcelist->After(first_source);  
     //  
   };  
   // save modifications to target file  
   //  
   target->SaveSelf(kTRUE);  
539    //    //
540      if ( li ) li->Delete();
541      li = new PamLevel2(wd,sourcelist,fDList);
542      li->SetSELLI(2);
543      //
544      Target->cd();
545      //
546      li->CreateCloneTrees(Target);
547      ULong64_t nevents = li->GetEntries();
548      printf(" NEVENTS %llu \n",nevents);
549      for(ULong64_t iev=0; iev<nevents; iev++){
550        li->Clear();
551        if( li->GetEntry(iev) ){
552          li->FillCloneTrees();
553        };
554      };
555      Target->cd();
556      li->WriteCloneTrees();
557      printf("Written file %s \n",Target->GetName());
558      //  Target->Write();
559      //  TTree *slist = (TTree*)Target->Get("SelectionList");
560      //  slist->Delete("all");
561      Target->Close();
562    
563    //   //
564    //   TDirectory *target = Target;
565    //   //
566    //   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
567    //   //
568    //   TString path( (char*)strstr( target->GetPath(), ":" ) );
569    //   path.Remove(0,2);
570    //   //
571    //   TDirectory *first_source = (TDirectory*)sourcelist->First();
572    //   THashList allNames;
573    //   //
574    //   while ( first_source ){
575    //     //
576    //     TDirectory *current_sourcedir = first_source->GetDirectory(path);
577    //     //
578    //     if ( !current_sourcedir ){
579    //       first_source = (TDirectory*)sourcelist->After(first_source);
580    //       continue;
581    //     }
582    //     //
583    //     // loop over all keys in this directory
584    //     //
585    //     TChain *globChain = 0;    
586    //     TIter nextkey( current_sourcedir->GetListOfKeys() );
587    //     TKey *key = 0;
588    //     TKey *oldkey = 0;
589    //     TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory
590    //     //
591    //     while ( (key = (TKey*)nextkey()) ) {
592    //       //
593    //       //      printf(" target ls \n");
594    //       //      Target->ls();
595    //       //
596    //       if ( current_sourcedir == target ) break;
597    //       //
598    //       if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
599    //       //
600    //       if ( allNames.FindObject(key->GetName()) ) continue;
601    //       //
602    //       if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
603    //       //
604    //       //
605    //       //
606    //       if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
607    //       //
608    //       if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
609    //       //
610    //       if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
611    //       //
612    //       if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
613    //       //
614    //       if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
615    //       //
616    //       if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
617    //       //
618    //       if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
619    //       //
620    //       if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
621    //       //
622    //       if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
623    //       //
624    //       if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){
625    //      if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());
626    //      continue;
627    //       };
628    //       //
629    //       printf(" 1 \n");
630    //       allNames.Add(new TObjString(key->GetName()));
631    //       printf(" 2 \n");
632    //       //
633    //       // read object from first source file
634    //       //
635    //       current_sourcedir->cd();
636    //       TObject *obj = key->ReadObj();
637    //       printf(" 3 \n");
638    //       //
639    //       if ( obj->IsA()->InheritsFrom("TTree") ){
640    //      //
641    //              // loop over all source files create a chain of Trees "globChain"
642    //      //
643    //      TString obj_name;
644    //      printf(" 4 \n");
645    //      //
646    //      if ( path.Length() ) {
647    //        obj_name = path + "/" + obj->GetName();
648    //      } else {
649    //        obj_name = obj->GetName();
650    //      };
651    //      //
652    //      globChain = new TChain(obj_name);
653    //      //
654    //      globChain->SetCacheSize(0);
655    //      //
656    //      printf(" 5 \n");
657    //      globChain->Add(first_source->GetName());
658    //      printf(" 6 \n");
659    //      //
660    //      TFile *nextsource = (TFile*)sourcelist->After( first_source );
661    //      //
662    //      while ( nextsource ) {            
663    //        //
664    //        //do not add to the list a file that does not contain this Tree
665    //        //
666    //        printf(" 7 \n");
667    //        TFile *curf = TFile::Open(nextsource->GetName());
668    //        //
669    //        if ( curf ) {
670    //          //
671    //          Bool_t mustAdd = kFALSE;
672    //          //
673    //          if (curf->FindKey(obj_name)) {
674    //            //
675    //            mustAdd = kTRUE;
676    //            //
677    //          } else {
678    //            //
679    //            //we could be more clever here. No need to import the object
680    //            //we are missing a function in TDirectory
681    //            //
682    //            TObject *aobj = curf->Get(obj_name);
683    //            //
684    //            if ( aobj ){
685    //              mustAdd = kTRUE;
686    //              delete aobj;
687    //            };
688    //          };
689    //          if (mustAdd) {
690    //            printf(" 8 \n");
691    //            globChain->Add(nextsource->GetName());
692    //            printf(" 9 \n");
693    //          };
694    //        };
695    //        delete curf;
696    //        nextsource = (TFile*)sourcelist->After(nextsource);
697    //      };
698    //      //
699    //      printf(" 10 \n");      
700    //      delete nextsource;
701    //      printf(" 11 \n");
702    //      //
703    //       } else {
704    //      //
705    //      // object is of no type that we know or can handle
706    //      //
707    //      if ( DebugMode() ) cout << "Unknown object type, name: "
708    //           << obj->GetName() << " title: " << obj->GetTitle() << endl;
709    //       };
710    //       //
711    //       // now write the merged histogram (which is "in" obj) to the target file
712    //       // note that this will just store obj in the current directory level,
713    //       // which is not persistent until the complete directory itself is stored
714    //       // by "target->Write()" below
715    //       //
716    //       printf(" 12 \n");
717    //       if ( obj ){
718    //      //
719    //      target->cd();
720    //      //
721    //      if( obj->IsA()->InheritsFrom("TTree") ) {
722    //        //
723    //        Long64_t nfiles = 0;
724    //        if ( fastMethod ){
725    //          //      globChain->Merge(target->GetFile(),0,"C keep fast");
726    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");
727    //        } else {
728    //          //globChain->Merge(target->GetFile(),0,"C keep");
729    //          printf(" 13 %llu \n",globChain->GetEntries());          
730    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");
731    //          printf(" 14 \n");
732    //        };
733    //        //
734    //        merged = true;
735    //        //
736    //        if ( DebugMode() ){
737    //          printf(" Merged %i files\n",(int)nfiles);
738    //          globChain->ls();
739    //        };
740    //        //
741    //        delete globChain;
742    //        //      return;
743    //        //
744    //      } else {
745    //        //
746    //        //      obj->Write( key->GetName() ); // <==================================================================================
747    //        //
748    //      };
749    //       };
750    //       delete obj;
751    //       oldkey = key;
752    //     };
753    //     //
754    //     first_source = (TDirectory*)sourcelist->After(first_source);
755    //     //
756    //   };
757    //   // save modifications to target file
758    //   //
759    //   target->SaveSelf(kTRUE);
760    //   //
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  Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){  //    // We must have been passed a file, we will use it
766     // We must have been passed a file, we will use it  //    // later to reset the compression level of the branches.
767     // later to reset the compression level of the branches.  //    if (!file) {
768     if (!file) {  //       // FIXME: We need an error message here.
769        // FIXME: We need an error message here.  //      printf(" 19 \n");
770       return 0;  //      return 0;
771     }  //    }
772    //    printf(" 20 \n");
773     // Options  
774     Bool_t fastClone = kFALSE;  //    // Options
775     TString opt = option;  //    Bool_t fastClone = kFALSE;
776     opt.ToLower();  //    TString opt = option;
777     if (opt.Contains("fast")) {  //    opt.ToLower();
778        fastClone = kTRUE;  //    if (opt.Contains("fast")) {
779     }  //       fastClone = kTRUE;
780    //       printf(" 21 \n");
781     // The chain tree must have a list of branches  //    }
782     // because we may try to change their basket  //    // The chain tree must have a list of branches
783     // size later.  //    // because we may try to change their basket
784     TObjArray* lbranches = mychain->GetListOfBranches();  //    // size later.
785     if (!lbranches) {  //    TObjArray* lbranches = mychain->GetListOfBranches();
786        // FIXME: We need an error message here.  //    if (!lbranches) {
787        return 0;  //       // FIXME: We need an error message here.
788     }  //      printf(" 22 \n");
789    //       return 0;
790     // The chain must have a current tree because  //    }
791     // that is the one we will clone.  
792     //   if (!fTree) {  //    //   file->cd();
793        // -- LoadTree() has not yet been called, no current tree.  //    // The chain must have a current tree because
794        // FIXME: We need an error message here.  //    // that is the one we will clone.
795     //      return 0;  //    //   if (!fTree) {
796     //   }  //       // -- LoadTree() has not yet been called, no current tree.
797    //       // FIXME: We need an error message here.
798     // Copy the chain's current tree without  //    //      return 0;
799     // copying any entries, we will do that later.  //    //   }
800     TTree* newTree = mychain->CloneTree(0);  
801     if (!newTree) {  //    // Copy the chain's current tree without
802        // FIXME: We need an error message here.  //    // copying any entries, we will do that later.
803        return 0;  //    printf(" 23 \n");
804     }  //    TTree* newTree = mychain->CloneTree(0);
805    //    if (!newTree) {
806     // Strip out the (potential) directory name.  //       // FIXME: We need an error message here.
807     // FIXME: The merged chain may or may not have the  //      printf(" 24 \n");
808     //        same name as the original chain.  This is  //       return 0;
809     //        bad because the chain name determines the  //    }
810     //        names of the trees in the chain by default.  //    printf(" 25 \n");
811     newTree->SetName(gSystem->BaseName(mychain->GetName()));  
812    
813     // FIXME: Why do we do this?  //    // Strip out the (potential) directory name.
814     //   newTree->SetAutoSave(-1);  //    // FIXME: The merged chain may or may not have the
815     newTree->SetAutoSave(900000000000000LL);  //    //        same name as the original chain.  This is
816    //    //        bad because the chain name determines the
817     // Circularity is incompatible with merging, it may  //    //        names of the trees in the chain by default.
818     // force us to throw away entries, which is not what  //    printf(" 26 \n");
819     // we are supposed to do.  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
820     newTree->SetCircular(0);  //    printf(" 27 \n");
821    
822     // Reset the compression level of the branches.  //    // FIXME: Why do we do this?
823     if (opt.Contains("c")) {  //    //   newTree->SetAutoSave(-1);
824        TBranch* branch = 0;  //    newTree->SetAutoSave(900000000000000LL);
825        TIter nextb(newTree->GetListOfBranches());  
826        while ((branch = (TBranch*) nextb())) {  //    printf(" 28 \n");
827           branch->SetCompressionLevel(file->GetCompressionLevel());  //    // Circularity is incompatible with merging, it may
828        }  //    // force us to throw away entries, which is not what
829     }  //    // we are supposed to do.
830    //    newTree->SetCircular(0);
831     // Reset the basket size of the branches.  
832     if (basketsize > 1000) {  //    // Reset the compression level of the branches.
833        TBranch* branch = 0;  //    if (opt.Contains("c")) {
834        TIter nextb(newTree->GetListOfBranches());  //       TBranch* branch = 0;
835        while ((branch = (TBranch*) nextb())) {  //       TIter nextb(newTree->GetListOfBranches());
836           branch->SetBasketSize(basketsize);  //       while ((branch = (TBranch*) nextb())) {
837        }  //      printf(" 29 \n");
838     }  //          branch->SetCompressionLevel(file->GetCompressionLevel());
839    //       }
840     Long64_t nentries = mychain->GetEntriesFast();  //    }
841    
842     // Copy the entries.  //    printf(" 30 \n");
843     if (fastClone) {  //    // Reset the basket size of the branches.
844        // For each tree in the chain.  //    if (basketsize > 1000) {
845        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //       TBranch* branch = 0;
846           if (mychain->LoadTree(i) < 0) {  //       TIter nextb(newTree->GetListOfBranches());
847              break;  //       while ((branch = (TBranch*) nextb())) {
848           }  //      printf(" 31 \n");
849           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //          branch->SetBasketSize(basketsize);
850           if (cloner.IsValid()) {  //       }
851              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //    }
852              cloner.Exec();  
853           } else {  //    printf(" 32 \n");
854              if (mychain->GetFile()) {  //    Long64_t nentries = mychain->GetEntriesFast();
855                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //    //Long64_t nentries = mychain->GetEntries();
856                 //            } else {  
857                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  //    // Copy the entries.
858              }  //    if (fastClone) {
859           }  //       // For each tree in the chain.
860        }  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
861     } else {  //          if (mychain->LoadTree(i) < 0) {
862        for (Long64_t i = 0; i < nentries; i++) {  //             break;
863           if (mychain->GetEntry(i) <= 0) {  //          }
864              break;  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
865           }  //          if (cloner.IsValid()) {
866           newTree->Fill();  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
867        }  //             cloner.Exec();
868     }  //          } else {
869    //             if (mychain->GetFile()) {
870     // Write the new tree header.  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
871     newTree->Write();  //             //            } else {
872    //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
873     // Get our return value.  //             }
874     Int_t nfiles = newTree->GetFileNumber() + 1;  //          }
875    //       }
876     // Close and delete the current file of the new tree.  //    } else {
877     if (!opt.Contains("keep")) {  //      printf(" 33 %llu \n",nentries);
878        // FIXME: What happens to fDirectory in newTree here?  //      mychain->Print();
879        delete newTree->GetCurrentFile();  //      for (Long64_t i = 0; i < nentries; i++) {
880     }  //        printf(" i %llu \n",i);
881     return nfiles;  //        // for (Long64_t i = 0; i < 1; i++) {
882  }  //          if (mychain->GetEntry(i) <= 0) {
883    //             break;
884    //          }
885    //          newTree->Fill();
886    //       }
887    //       printf(" 34 \n");
888    //    }
889    
890    //    // Write the new tree header.
891    //    printf(" 35 \n");
892    //    newTree->Write();
893    
894    //    printf(" 36 \n");
895    //    // Get our return value.
896    //    Int_t nfiles = newTree->GetFileNumber() + 1;
897    
898    //    // Close and delete the current file of the new tree.
899    //    if (!opt.Contains("keep")) {
900    //       // FIXME: What happens to fDirectory in newTree here?
901    //       delete newTree->GetCurrentFile();
902    //    }
903    //    return nfiles;
904    // }

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

  ViewVC Help
Powered by ViewVC 1.1.23