/[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.8 by pamela, Sun Feb 25 16:33:33 2007 UTC revision 1.21 by mocchiut, Fri Oct 17 13:17:05 2014 UTC
# Line 25  RunGlue::RunGlue() { Line 25  RunGlue::RunGlue() {
25  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) {  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) {
26    fDBG = false;    fDBG = false;
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 41  RunGlue::RunGlue(TSQLServer *da, UInt_t Line 42  RunGlue::RunGlue(TSQLServer *da, UInt_t
42      runmode = false;      runmode = false;
43      createlist = true;      createlist = true;
44    };    };
45      fUpgrade = true;
46    //    //
47    //  lList = new TList();    //  lList = new TList();
48    //    //
49  };  };
50    
   
51  void RunGlue::Clear() {  void RunGlue::Clear() {
52    fEnd = false;    fEnd = false;
53    run = 0;    run = 0;
# Line 75  void RunGlue::SetDList(TString list) { Line 76  void RunGlue::SetDList(TString list) {
76    if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true;    if (list.Contains("+ALL", TString::kIgnoreCase)) RUN = true;
77    //    //
78    fDList = list;    fDList = list;
79    li->SetWhichTrees(fDList);    //  li->SetWhichTrees(fDList);
80    //    //
81    if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data());    if ( DebugMode() ) printf(" Detector list is %s \n",fDList.Data());
82    //    //
83  };  };
84    
85  TList *RunGlue::GetRunList(){  TList *RunGlue::GetRunList(){
86    //    //  
87    lList = new TList();    lList = new TList();
88    lList->Clear();    lList->Clear();
89    TString thisrun;    TString thisrun;
# Line 114  TList *RunGlue::GetRunList(){ Line 115  TList *RunGlue::GetRunList(){
115      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
116      //      //
117      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
118      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86400;
119      //      //
120      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
121      //      //
# Line 173  TList *RunGlue::GetRunList(){ Line 174  TList *RunGlue::GetRunList(){
174        if ( li->CheckLevel2File(thisrun) ){        if ( li->CheckLevel2File(thisrun) ){
175          lList->Add(su);          lList->Add(su);
176        } else {        } else {
177          if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));                  if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
178        };        };
179        //        //
180      };      };
# Line 281  TList *RunGlue::GetRunList(){ Line 282  TList *RunGlue::GetRunList(){
282      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
283      //      //
284      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
285      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86400;
286      //      //
287      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
288      //      //
# Line 394  Bool_t RunGlue::OpenFile(){ Line 395  Bool_t RunGlue::OpenFile(){
395      return(false);      return(false);
396    } else {    } else {
397      //      //
398        // try to lock tables and work on a db level to avoid multiple file simultaneous access
399        //
400        stringstream oss;
401        //  
402        if ( fUpgrade ){
403          oss.str("");
404          oss << "lock table GL_ROOT write;";
405          TSQLResult *result = 0;
406          TSQLRow *row = 0;
407          result = dbc->Query(oss.str().c_str());
408          oss.str("");
409          oss << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
410          result = dbc->Query(oss.str().c_str());
411          row = result->Next();
412          if ( row ){
413            printf("Error opening target file (does %s exist? already in the DB? are the permissions ok?)\n",(this->GetFilename()).Data());
414            return(false);
415          } else {
416            oss.str("");
417            oss << "insert into GL_ROOT (PATH,NAME) values ('$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";      
418            result = dbc->Query(oss.str().c_str());
419          };
420          oss.str("");
421          oss << "unlock tables;";
422          result = dbc->Query(oss.str().c_str());
423        };
424        //    Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
425        Target = TFile::Open((this->GetFilename()).Data(), "NEW" );    
426        //    
427      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
428      //      //
429      Long64_t maxsize = 99900000000LL;        Long64_t maxsize = 99900000000LL;  
430      //      //
431      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      if ( !Target || Target->IsZombie()) {
432          printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data());
433          //      exit(1);
434          return(false);
435        }
436        //
437        Target->Write();
438        //
439      //fastMethod = kTRUE;      //fastMethod = kTRUE;
440      fastMethod = kFALSE;      fastMethod = kFALSE;
441      //          //    
     //      
     if ( !Target || Target->IsZombie()) {  
       printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());  
       exit(1);  
     }  
442      //      //
443      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
444      Target->SetCompressionLevel(2);      //    Target->SetCompressionLevel(2);
445        Target->SetCompressionLevel(3);
446        //Target->SetCompressionLevel(5);
447      //      //
448      fOpen = true;      fOpen = true;
449      return(true);      return(true);
# Line 471  void RunGlue::UpdateDB(TList *dlist){ Line 505  void RunGlue::UpdateDB(TList *dlist){
505    };    };
506    //    //
507    myquery.str("");    myquery.str("");
   myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";  
   if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());  
   //  
   pResult = dbc->Query(myquery.str().c_str());  
   if ( !pResult ){  
     printf(" ERROR WRITING ON DB!\n");  
     return;  
   };  
   myquery.str("");  
508    myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";    myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
509    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
510    //    //
# Line 495  void RunGlue::UpdateDB(TList *dlist){ Line 520  void RunGlue::UpdateDB(TList *dlist){
520    } else {    } else {
521      idl2 = (UInt_t)atoll(Row->GetField(0));      idl2 = (UInt_t)atoll(Row->GetField(0));
522    };    };
523      myquery.str("");
524      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
525      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
526      myquery << "update GL_ROOT set ID_RAW=" << idr << " where ID=" << idl2 << ";";
527      if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
528      //
529      pResult = dbc->Query(myquery.str().c_str());
530      if ( !pResult ){
531        printf(" ERROR WRITING ON DB!\n");
532        return;
533      };
534    //    //
535    //    //
536    //    //
# Line 527  void RunGlue::UpdateDB(TList *dlist){ Line 563  void RunGlue::UpdateDB(TList *dlist){
563  //  //
564  void RunGlue::MergeRootfile(TList *sourcelist) {  void RunGlue::MergeRootfile(TList *sourcelist) {
565    //    //
566    merged = false;    merged = true;
   //  
   TDirectory *target = Target;  
   //  
   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());  
   //  
   TString path( (char*)strstr( target->GetPath(), ":" ) );  
   path.Remove(0,2);  
567    //    //
568    TDirectory *first_source = (TDirectory*)sourcelist->First();    //  if ( li ) li->Delete();
569    THashList allNames;    PamLevel2 *nli = new PamLevel2(wd,sourcelist,fDList);
570    //    nli->SetSELLI(2);
571    while ( first_source ){    //
572      //    Target->cd();
573      TDirectory *current_sourcedir = first_source->GetDirectory(path);    //
574      //    nli->CreateCloneTrees(Target);
575      if ( !current_sourcedir ){    //
576        first_source = (TDirectory*)sourcelist->After(first_source);    /*  nli->GetCloneTree("Tracker")->SetAutoSave(900000000000000LL);
577        continue;    nli->GetCloneTree("Trigger")->SetAutoSave(900000000000000LL);
578      nli->GetCloneTree("Calorimeter")->SetAutoSave(900000000000000LL);
579      nli->GetCloneTree("S4")->SetAutoSave(900000000000000LL);
580      nli->GetCloneTree("Anticounter")->SetAutoSave(900000000000000LL);
581      nli->GetCloneTree("NeutronD")->SetAutoSave(900000000000000LL);
582      nli->GetCloneTree("OrbitalInfo")->SetAutoSave(900000000000000LL);
583      nli->GetCloneTree("Run")->SetAutoSave(900000000000000LL);
584      nli->GetCloneTree("ToF")->SetAutoSave(900000000000000LL);*/
585      //
586      ULong64_t nevents = nli->GetEntries();        
587      printf(" NEVENTS %llu \n",nevents);
588      for(ULong64_t iev=0; iev<nevents; iev++){
589        nli->Clear();
590        if( nli->GetEntry(iev) ){
591          nli->FillCloneTrees();
592        };
593      };
594      Target->cd();
595      nli->WriteCloneTrees();
596      printf("Written file %s \n",Target->GetName());
597      //  Target->Write();
598      //  TTree *slist = (TTree*)Target->Get("SelectionList");
599      //  slist->Delete("all");
600      if ( !nli->GetCloneTree("ProcessingInfo") ){
601        TChain *P = new TChain("ProcessingInfo");
602        // loop over files and create chains
603        TIter next(sourcelist);
604        TSystemFile *questo = 0;
605        bool found = false;
606        while ((questo = (TSystemFile*) next())) {
607          TString name = questo->GetName();
608          if ( P->Add(name) ) found = true;
609      }      }
610      //      if ( found ){
611      // loop over all keys in this directory        TTree *Pclone = P->CloneTree();
612      //        Target->cd();
613      TChain *globChain = 0;            Pclone->Write("ProcessingInfo",TObject::kOverwrite);
614      TIter nextkey( current_sourcedir->GetListOfKeys() );        P->Delete();
615      TKey *key = 0;        P=0;
616      TKey *oldkey = 0;      }
617      TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory    }
618      //    //  
619      while ( (key = (TKey*)nextkey()) ) {    Target->Close();
620        //  
621        //      printf(" target ls \n");  //   //
622        //      Target->ls();  //   TDirectory *target = Target;
623        //  //   //
624        if ( current_sourcedir == target ) break;  //   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
625        //  //   //
626        if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key  //   TString path( (char*)strstr( target->GetPath(), ":" ) );
627        //  //   path.Remove(0,2);
628        if ( allNames.FindObject(key->GetName()) ) continue;  //   //
629        //  //   TDirectory *first_source = (TDirectory*)sourcelist->First();
630        if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());  //   THashList allNames;
631        //  //   //
632        //  //   while ( first_source ){
633        //  //     //
634        if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;  //     TDirectory *current_sourcedir = first_source->GetDirectory(path);
635        //  //     //
636        if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;  //     if ( !current_sourcedir ){
637        //  //       first_source = (TDirectory*)sourcelist->After(first_source);
638        if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;  //       continue;
639        //  //     }
640        if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;  //     //
641        //  //     // loop over all keys in this directory
642        if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;  //     //
643        //  //     TChain *globChain = 0;    
644        if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;  //     TIter nextkey( current_sourcedir->GetListOfKeys() );
645        //  //     TKey *key = 0;
646        if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;  //     TKey *oldkey = 0;
647        //  //     TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory
648        if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;  //     //
649        //  //     while ( (key = (TKey*)nextkey()) ) {
650        if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;  //       //
651        //  //       //      printf(" target ls \n");
652        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") ){  //       //      Target->ls();
653          if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());  //       //
654          continue;  //       if ( current_sourcedir == target ) break;
655        };  //       //
656        //  //       if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
657        allNames.Add(new TObjString(key->GetName()));  //       //
658        //  //       if ( allNames.FindObject(key->GetName()) ) continue;
659        // read object from first source file  //       //
660        //  //       if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
661        current_sourcedir->cd();  //       //
662        TObject *obj = key->ReadObj();  //       //
663        //  //       //
664        if ( obj->IsA()->InheritsFrom("TTree") ){  //       if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
665          //  //       //
666          // loop over all source files create a chain of Trees "globChain"  //       if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
667          //  //       //
668          TString obj_name;  //       if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
669          //  //       //
670          if ( path.Length() ) {  //       if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
671            obj_name = path + "/" + obj->GetName();  //       //
672          } else {  //       if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
673            obj_name = obj->GetName();  //       //
674          };  //       if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
675          //  //       //
676          globChain = new TChain(obj_name);  //       if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
677          //  //       //
678          globChain->SetCacheSize(0);  //       if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
679          //  //       //
680          globChain->Add(first_source->GetName());  //       if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
681          //  //       //
682          TFile *nextsource = (TFile*)sourcelist->After( first_source );  //       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") ){
683          //  //      if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());
684          while ( nextsource ) {              //      continue;
685            //  //       };
686            //do not add to the list a file that does not contain this Tree  //       //
687            //  //       printf(" 1 \n");
688            TFile *curf = TFile::Open(nextsource->GetName());  //       allNames.Add(new TObjString(key->GetName()));
689            //  //       printf(" 2 \n");
690            if ( curf ) {  //       //
691              //  //       // read object from first source file
692              Bool_t mustAdd = kFALSE;  //       //
693              //  //       current_sourcedir->cd();
694              if (curf->FindKey(obj_name)) {  //       TObject *obj = key->ReadObj();
695                //  //       printf(" 3 \n");
696                mustAdd = kTRUE;  //       //
697                //  //       if ( obj->IsA()->InheritsFrom("TTree") ){
698              } else {  //      //
699                //  //              // loop over all source files create a chain of Trees "globChain"
700                //we could be more clever here. No need to import the object  //      //
701                //we are missing a function in TDirectory  //      TString obj_name;
702                //  //      printf(" 4 \n");
703                TObject *aobj = curf->Get(obj_name);  //      //
704                //  //      if ( path.Length() ) {
705                if ( aobj ){  //        obj_name = path + "/" + obj->GetName();
706                  mustAdd = kTRUE;  //      } else {
707                  delete aobj;  //        obj_name = obj->GetName();
708                };  //      };
709              };  //      //
710              if (mustAdd) {  //      globChain = new TChain(obj_name);
711                globChain->Add(nextsource->GetName());  //      //
712              };  //      globChain->SetCacheSize(0);
713            };  //      //
714            delete curf;  //      printf(" 5 \n");
715            nextsource = (TFile*)sourcelist->After(nextsource);  //      globChain->Add(first_source->GetName());
716          };  //      printf(" 6 \n");
717          //  //      //
718          delete nextsource;  //      TFile *nextsource = (TFile*)sourcelist->After( first_source );
719          //  //      //
720        } else {  //      while ( nextsource ) {            
721          //  //        //
722          // object is of no type that we know or can handle  //        //do not add to the list a file that does not contain this Tree
723          //  //        //
724          if ( DebugMode() ) cout << "Unknown object type, name: "  //        printf(" 7 \n");
725               << obj->GetName() << " title: " << obj->GetTitle() << endl;  //        TFile *curf = TFile::Open(nextsource->GetName());
726        };  //        //
727        //  //        if ( curf ) {
728        // now write the merged histogram (which is "in" obj) to the target file  //          //
729        // note that this will just store obj in the current directory level,  //          Bool_t mustAdd = kFALSE;
730        // which is not persistent until the complete directory itself is stored  //          //
731        // by "target->Write()" below  //          if (curf->FindKey(obj_name)) {
732        //  //            //
733        if ( obj ){  //            mustAdd = kTRUE;
734          //  //            //
735          target->cd();  //          } else {
736          //  //            //
737          if( obj->IsA()->InheritsFrom("TTree") ) {  //            //we could be more clever here. No need to import the object
738            //  //            //we are missing a function in TDirectory
739            Long64_t nfiles = 0;  //            //
740            if ( fastMethod ){  //            TObject *aobj = curf->Get(obj_name);
741              //      globChain->Merge(target->GetFile(),0,"C keep fast");  //            //
742              nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");  //            if ( aobj ){
743            } else {  //              mustAdd = kTRUE;
744              //globChain->Merge(target->GetFile(),0,"C keep");  //              delete aobj;
745              nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");  //            };
746            };  //          };
747            //  //          if (mustAdd) {
748            merged = true;  //            printf(" 8 \n");
749            //  //            globChain->Add(nextsource->GetName());
750            if ( DebugMode() ){  //            printf(" 9 \n");
751              printf(" Merged %i files\n",(int)nfiles);  //          };
752              globChain->ls();  //        };
753            };  //        delete curf;
754            //  //        nextsource = (TFile*)sourcelist->After(nextsource);
755            delete globChain;  //      };
756            //      return;  //      //
757            //  //      printf(" 10 \n");      
758          } else {  //      delete nextsource;
759            //  //      printf(" 11 \n");
760            //      obj->Write( key->GetName() ); // <==================================================================================  //      //
761            //  //       } else {
762          };  //      //
763        };  //      // object is of no type that we know or can handle
764        delete obj;  //      //
765        oldkey = key;  //      if ( DebugMode() ) cout << "Unknown object type, name: "
766      };  //           << obj->GetName() << " title: " << obj->GetTitle() << endl;
767      //  //       };
768      first_source = (TDirectory*)sourcelist->After(first_source);  //       //
769      //  //       // now write the merged histogram (which is "in" obj) to the target file
770    };  //       // note that this will just store obj in the current directory level,
771    // save modifications to target file  //       // which is not persistent until the complete directory itself is stored
772    //  //       // by "target->Write()" below
773    target->SaveSelf(kTRUE);  //       //
774    //  //       printf(" 12 \n");
775    //       if ( obj ){
776    //      //
777    //      target->cd();
778    //      //
779    //      if( obj->IsA()->InheritsFrom("TTree") ) {
780    //        //
781    //        Long64_t nfiles = 0;
782    //        if ( fastMethod ){
783    //          //      globChain->Merge(target->GetFile(),0,"C keep fast");
784    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");
785    //        } else {
786    //          //globChain->Merge(target->GetFile(),0,"C keep");
787    //          printf(" 13 %llu \n",globChain->GetEntries());          
788    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");
789    //          printf(" 14 \n");
790    //        };
791    //        //
792    //        merged = true;
793    //        //
794    //        if ( DebugMode() ){
795    //          printf(" Merged %i files\n",(int)nfiles);
796    //          globChain->ls();
797    //        };
798    //        //
799    //        delete globChain;
800    //        //      return;
801    //        //
802    //      } else {
803    //        //
804    //        //      obj->Write( key->GetName() ); // <==================================================================================
805    //        //
806    //      };
807    //       };
808    //       delete obj;
809    //       oldkey = key;
810    //     };
811    //     //
812    //     first_source = (TDirectory*)sourcelist->After(first_source);
813    //     //
814    //   };
815    //   // save modifications to target file
816    //   //
817    //   target->SaveSelf(kTRUE);
818    //   //
819  };  };
820    
821    
822  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){
823     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
824     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
825     if (!file) {  //    if (!file) {
826        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
827       return 0;  //      printf(" 19 \n");
828     }  //      return 0;
829    //    }
830     // Options  //    printf(" 20 \n");
831     Bool_t fastClone = kFALSE;  
832     TString opt = option;  //    // Options
833     opt.ToLower();  //    Bool_t fastClone = kFALSE;
834     if (opt.Contains("fast")) {  //    TString opt = option;
835        fastClone = kTRUE;  //    opt.ToLower();
836     }  //    if (opt.Contains("fast")) {
837    //       fastClone = kTRUE;
838     // The chain tree must have a list of branches  //       printf(" 21 \n");
839     // because we may try to change their basket  //    }
840     // size later.  //    // The chain tree must have a list of branches
841     TObjArray* lbranches = mychain->GetListOfBranches();  //    // because we may try to change their basket
842     if (!lbranches) {  //    // size later.
843        // FIXME: We need an error message here.  //    TObjArray* lbranches = mychain->GetListOfBranches();
844        return 0;  //    if (!lbranches) {
845     }  //       // FIXME: We need an error message here.
846    //      printf(" 22 \n");
847     // The chain must have a current tree because  //       return 0;
848     // that is the one we will clone.  //    }
849     //   if (!fTree) {  
850        // -- LoadTree() has not yet been called, no current tree.  //    //   file->cd();
851        // FIXME: We need an error message here.  //    // The chain must have a current tree because
852     //      return 0;  //    // that is the one we will clone.
853     //   }  //    //   if (!fTree) {
854    //       // -- LoadTree() has not yet been called, no current tree.
855     // Copy the chain's current tree without  //       // FIXME: We need an error message here.
856     // copying any entries, we will do that later.  //    //      return 0;
857     TTree* newTree = mychain->CloneTree(0);  //    //   }
858     if (!newTree) {  
859        // FIXME: We need an error message here.  //    // Copy the chain's current tree without
860        return 0;  //    // copying any entries, we will do that later.
861     }  //    printf(" 23 \n");
862    //    TTree* newTree = mychain->CloneTree(0);
863     // Strip out the (potential) directory name.  //    if (!newTree) {
864     // FIXME: The merged chain may or may not have the  //       // FIXME: We need an error message here.
865     //        same name as the original chain.  This is  //      printf(" 24 \n");
866     //        bad because the chain name determines the  //       return 0;
867     //        names of the trees in the chain by default.  //    }
868     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    printf(" 25 \n");
869    
870     // FIXME: Why do we do this?  
871     //   newTree->SetAutoSave(-1);  //    // Strip out the (potential) directory name.
872     newTree->SetAutoSave(900000000000000LL);  //    // FIXME: The merged chain may or may not have the
873    //    //        same name as the original chain.  This is
874     // Circularity is incompatible with merging, it may  //    //        bad because the chain name determines the
875     // force us to throw away entries, which is not what  //    //        names of the trees in the chain by default.
876     // we are supposed to do.  //    printf(" 26 \n");
877     newTree->SetCircular(0);  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
878    //    printf(" 27 \n");
879     // Reset the compression level of the branches.  
880     if (opt.Contains("c")) {  //    // FIXME: Why do we do this?
881        TBranch* branch = 0;  //    //   newTree->SetAutoSave(-1);
882        TIter nextb(newTree->GetListOfBranches());  //    newTree->SetAutoSave(900000000000000LL);
883        while ((branch = (TBranch*) nextb())) {  
884           branch->SetCompressionLevel(file->GetCompressionLevel());  //    printf(" 28 \n");
885        }  //    // Circularity is incompatible with merging, it may
886     }  //    // force us to throw away entries, which is not what
887    //    // we are supposed to do.
888     // Reset the basket size of the branches.  //    newTree->SetCircular(0);
889     if (basketsize > 1000) {  
890        TBranch* branch = 0;  //    // Reset the compression level of the branches.
891        TIter nextb(newTree->GetListOfBranches());  //    if (opt.Contains("c")) {
892        while ((branch = (TBranch*) nextb())) {  //       TBranch* branch = 0;
893           branch->SetBasketSize(basketsize);  //       TIter nextb(newTree->GetListOfBranches());
894        }  //       while ((branch = (TBranch*) nextb())) {
895     }  //      printf(" 29 \n");
896    //          branch->SetCompressionLevel(file->GetCompressionLevel());
897     Long64_t nentries = mychain->GetEntriesFast();  //       }
898    //    }
899     // Copy the entries.  
900     if (fastClone) {  //    printf(" 30 \n");
901        // For each tree in the chain.  //    // Reset the basket size of the branches.
902        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //    if (basketsize > 1000) {
903           if (mychain->LoadTree(i) < 0) {  //       TBranch* branch = 0;
904              break;  //       TIter nextb(newTree->GetListOfBranches());
905           }  //       while ((branch = (TBranch*) nextb())) {
906           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //      printf(" 31 \n");
907           if (cloner.IsValid()) {  //          branch->SetBasketSize(basketsize);
908              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //       }
909              cloner.Exec();  //    }
910           } else {  
911              if (mychain->GetFile()) {  //    printf(" 32 \n");
912                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //    Long64_t nentries = mychain->GetEntriesFast();
913                 //            } else {  //    //Long64_t nentries = mychain->GetEntries();
914                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  
915              }  //    // Copy the entries.
916           }  //    if (fastClone) {
917        }  //       // For each tree in the chain.
918     } else {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
919        for (Long64_t i = 0; i < nentries; i++) {  //          if (mychain->LoadTree(i) < 0) {
920           if (mychain->GetEntry(i) <= 0) {  //             break;
921              break;  //          }
922           }  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
923           newTree->Fill();  //          if (cloner.IsValid()) {
924        }  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
925     }  //             cloner.Exec();
926    //          } else {
927     // Write the new tree header.  //             if (mychain->GetFile()) {
928     newTree->Write();  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
929    //             //            } else {
930     // Get our return value.  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
931     Int_t nfiles = newTree->GetFileNumber() + 1;  //             }
932    //          }
933     // Close and delete the current file of the new tree.  //       }
934     if (!opt.Contains("keep")) {  //    } else {
935        // FIXME: What happens to fDirectory in newTree here?  //      printf(" 33 %llu \n",nentries);
936        delete newTree->GetCurrentFile();  //      mychain->Print();
937     }  //      for (Long64_t i = 0; i < nentries; i++) {
938     return nfiles;  //        printf(" i %llu \n",i);
939  }  //        // for (Long64_t i = 0; i < 1; i++) {
940    //          if (mychain->GetEntry(i) <= 0) {
941    //             break;
942    //          }
943    //          newTree->Fill();
944    //       }
945    //       printf(" 34 \n");
946    //    }
947    
948    //    // Write the new tree header.
949    //    printf(" 35 \n");
950    //    newTree->Write();
951    
952    //    printf(" 36 \n");
953    //    // Get our return value.
954    //    Int_t nfiles = newTree->GetFileNumber() + 1;
955    
956    //    // Close and delete the current file of the new tree.
957    //    if (!opt.Contains("keep")) {
958    //       // FIXME: What happens to fDirectory in newTree here?
959    //       delete newTree->GetCurrentFile();
960    //    }
961    //    return nfiles;
962    // }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.23