/[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.18 by mocchiut, Fri Sep 14 08:07:15 2012 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);  
   //  
   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 );  
         //  
         while ( nextsource ) {              
           //  
           //do not add to the list a file that does not contain this Tree  
           //  
           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);  
567    //    //
568      //  if ( li ) li->Delete();
569      PamLevel2 *nli = new PamLevel2(wd,sourcelist,fDList);
570      nli->SetSELLI(2);
571      //
572      Target->cd();
573      //
574      nli->CreateCloneTrees(Target);
575      ULong64_t nevents = nli->GetEntries();        
576      printf(" NEVENTS %llu \n",nevents);
577      for(ULong64_t iev=0; iev<nevents; iev++){
578        nli->Clear();
579        if( nli->GetEntry(iev) ){
580          nli->FillCloneTrees();
581        };
582      };
583      Target->cd();
584      nli->WriteCloneTrees();
585      printf("Written file %s \n",Target->GetName());
586      //  Target->Write();
587      //  TTree *slist = (TTree*)Target->Get("SelectionList");
588      //  slist->Delete("all");
589      Target->Close();
590    
591    //   //
592    //   TDirectory *target = Target;
593    //   //
594    //   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
595    //   //
596    //   TString path( (char*)strstr( target->GetPath(), ":" ) );
597    //   path.Remove(0,2);
598    //   //
599    //   TDirectory *first_source = (TDirectory*)sourcelist->First();
600    //   THashList allNames;
601    //   //
602    //   while ( first_source ){
603    //     //
604    //     TDirectory *current_sourcedir = first_source->GetDirectory(path);
605    //     //
606    //     if ( !current_sourcedir ){
607    //       first_source = (TDirectory*)sourcelist->After(first_source);
608    //       continue;
609    //     }
610    //     //
611    //     // loop over all keys in this directory
612    //     //
613    //     TChain *globChain = 0;    
614    //     TIter nextkey( current_sourcedir->GetListOfKeys() );
615    //     TKey *key = 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()) ) {
620    //       //
621    //       //      printf(" target ls \n");
622    //       //      Target->ls();
623    //       //
624    //       if ( current_sourcedir == target ) break;
625    //       //
626    //       if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
627    //       //
628    //       if ( allNames.FindObject(key->GetName()) ) continue;
629    //       //
630    //       if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
631    //       //
632    //       //
633    //       //
634    //       if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
635    //       //
636    //       if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
637    //       //
638    //       if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
639    //       //
640    //       if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
641    //       //
642    //       if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
643    //       //
644    //       if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
645    //       //
646    //       if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
647    //       //
648    //       if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
649    //       //
650    //       if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
651    //       //
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") ){
653    //      if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());
654    //      continue;
655    //       };
656    //       //
657    //       printf(" 1 \n");
658    //       allNames.Add(new TObjString(key->GetName()));
659    //       printf(" 2 \n");
660    //       //
661    //       // read object from first source file
662    //       //
663    //       current_sourcedir->cd();
664    //       TObject *obj = key->ReadObj();
665    //       printf(" 3 \n");
666    //       //
667    //       if ( obj->IsA()->InheritsFrom("TTree") ){
668    //      //
669    //              // loop over all source files create a chain of Trees "globChain"
670    //      //
671    //      TString obj_name;
672    //      printf(" 4 \n");
673    //      //
674    //      if ( path.Length() ) {
675    //        obj_name = path + "/" + obj->GetName();
676    //      } else {
677    //        obj_name = obj->GetName();
678    //      };
679    //      //
680    //      globChain = new TChain(obj_name);
681    //      //
682    //      globChain->SetCacheSize(0);
683    //      //
684    //      printf(" 5 \n");
685    //      globChain->Add(first_source->GetName());
686    //      printf(" 6 \n");
687    //      //
688    //      TFile *nextsource = (TFile*)sourcelist->After( first_source );
689    //      //
690    //      while ( nextsource ) {            
691    //        //
692    //        //do not add to the list a file that does not contain this Tree
693    //        //
694    //        printf(" 7 \n");
695    //        TFile *curf = TFile::Open(nextsource->GetName());
696    //        //
697    //        if ( curf ) {
698    //          //
699    //          Bool_t mustAdd = kFALSE;
700    //          //
701    //          if (curf->FindKey(obj_name)) {
702    //            //
703    //            mustAdd = kTRUE;
704    //            //
705    //          } else {
706    //            //
707    //            //we could be more clever here. No need to import the object
708    //            //we are missing a function in TDirectory
709    //            //
710    //            TObject *aobj = curf->Get(obj_name);
711    //            //
712    //            if ( aobj ){
713    //              mustAdd = kTRUE;
714    //              delete aobj;
715    //            };
716    //          };
717    //          if (mustAdd) {
718    //            printf(" 8 \n");
719    //            globChain->Add(nextsource->GetName());
720    //            printf(" 9 \n");
721    //          };
722    //        };
723    //        delete curf;
724    //        nextsource = (TFile*)sourcelist->After(nextsource);
725    //      };
726    //      //
727    //      printf(" 10 \n");      
728    //      delete nextsource;
729    //      printf(" 11 \n");
730    //      //
731    //       } else {
732    //      //
733    //      // object is of no type that we know or can handle
734    //      //
735    //      if ( DebugMode() ) cout << "Unknown object type, name: "
736    //           << obj->GetName() << " title: " << obj->GetTitle() << endl;
737    //       };
738    //       //
739    //       // now write the merged histogram (which is "in" obj) to the target file
740    //       // note that this will just store obj in the current directory level,
741    //       // which is not persistent until the complete directory itself is stored
742    //       // by "target->Write()" below
743    //       //
744    //       printf(" 12 \n");
745    //       if ( obj ){
746    //      //
747    //      target->cd();
748    //      //
749    //      if( obj->IsA()->InheritsFrom("TTree") ) {
750    //        //
751    //        Long64_t nfiles = 0;
752    //        if ( fastMethod ){
753    //          //      globChain->Merge(target->GetFile(),0,"C keep fast");
754    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep fast");
755    //        } else {
756    //          //globChain->Merge(target->GetFile(),0,"C keep");
757    //          printf(" 13 %llu \n",globChain->GetEntries());          
758    //          nfiles=this->Mergy((TChain*)globChain,target->GetFile(),0,"C keep");
759    //          printf(" 14 \n");
760    //        };
761    //        //
762    //        merged = true;
763    //        //
764    //        if ( DebugMode() ){
765    //          printf(" Merged %i files\n",(int)nfiles);
766    //          globChain->ls();
767    //        };
768    //        //
769    //        delete globChain;
770    //        //      return;
771    //        //
772    //      } else {
773    //        //
774    //        //      obj->Write( key->GetName() ); // <==================================================================================
775    //        //
776    //      };
777    //       };
778    //       delete obj;
779    //       oldkey = key;
780    //     };
781    //     //
782    //     first_source = (TDirectory*)sourcelist->After(first_source);
783    //     //
784    //   };
785    //   // save modifications to target file
786    //   //
787    //   target->SaveSelf(kTRUE);
788    //   //
789  };  };
790    
791    
792  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){
793     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
794     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
795     if (!file) {  //    if (!file) {
796        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
797       return 0;  //      printf(" 19 \n");
798     }  //      return 0;
799    //    }
800     // Options  //    printf(" 20 \n");
801     Bool_t fastClone = kFALSE;  
802     TString opt = option;  //    // Options
803     opt.ToLower();  //    Bool_t fastClone = kFALSE;
804     if (opt.Contains("fast")) {  //    TString opt = option;
805        fastClone = kTRUE;  //    opt.ToLower();
806     }  //    if (opt.Contains("fast")) {
807    //       fastClone = kTRUE;
808     // The chain tree must have a list of branches  //       printf(" 21 \n");
809     // because we may try to change their basket  //    }
810     // size later.  //    // The chain tree must have a list of branches
811     TObjArray* lbranches = mychain->GetListOfBranches();  //    // because we may try to change their basket
812     if (!lbranches) {  //    // size later.
813        // FIXME: We need an error message here.  //    TObjArray* lbranches = mychain->GetListOfBranches();
814        return 0;  //    if (!lbranches) {
815     }  //       // FIXME: We need an error message here.
816    //      printf(" 22 \n");
817     // The chain must have a current tree because  //       return 0;
818     // that is the one we will clone.  //    }
819     //   if (!fTree) {  
820        // -- LoadTree() has not yet been called, no current tree.  //    //   file->cd();
821        // FIXME: We need an error message here.  //    // The chain must have a current tree because
822     //      return 0;  //    // that is the one we will clone.
823     //   }  //    //   if (!fTree) {
824    //       // -- LoadTree() has not yet been called, no current tree.
825     // Copy the chain's current tree without  //       // FIXME: We need an error message here.
826     // copying any entries, we will do that later.  //    //      return 0;
827     TTree* newTree = mychain->CloneTree(0);  //    //   }
828     if (!newTree) {  
829        // FIXME: We need an error message here.  //    // Copy the chain's current tree without
830        return 0;  //    // copying any entries, we will do that later.
831     }  //    printf(" 23 \n");
832    //    TTree* newTree = mychain->CloneTree(0);
833     // Strip out the (potential) directory name.  //    if (!newTree) {
834     // FIXME: The merged chain may or may not have the  //       // FIXME: We need an error message here.
835     //        same name as the original chain.  This is  //      printf(" 24 \n");
836     //        bad because the chain name determines the  //       return 0;
837     //        names of the trees in the chain by default.  //    }
838     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    printf(" 25 \n");
839    
840     // FIXME: Why do we do this?  
841     //   newTree->SetAutoSave(-1);  //    // Strip out the (potential) directory name.
842     newTree->SetAutoSave(900000000000000LL);  //    // FIXME: The merged chain may or may not have the
843    //    //        same name as the original chain.  This is
844     // Circularity is incompatible with merging, it may  //    //        bad because the chain name determines the
845     // force us to throw away entries, which is not what  //    //        names of the trees in the chain by default.
846     // we are supposed to do.  //    printf(" 26 \n");
847     newTree->SetCircular(0);  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
848    //    printf(" 27 \n");
849     // Reset the compression level of the branches.  
850     if (opt.Contains("c")) {  //    // FIXME: Why do we do this?
851        TBranch* branch = 0;  //    //   newTree->SetAutoSave(-1);
852        TIter nextb(newTree->GetListOfBranches());  //    newTree->SetAutoSave(900000000000000LL);
853        while ((branch = (TBranch*) nextb())) {  
854           branch->SetCompressionLevel(file->GetCompressionLevel());  //    printf(" 28 \n");
855        }  //    // Circularity is incompatible with merging, it may
856     }  //    // force us to throw away entries, which is not what
857    //    // we are supposed to do.
858     // Reset the basket size of the branches.  //    newTree->SetCircular(0);
859     if (basketsize > 1000) {  
860        TBranch* branch = 0;  //    // Reset the compression level of the branches.
861        TIter nextb(newTree->GetListOfBranches());  //    if (opt.Contains("c")) {
862        while ((branch = (TBranch*) nextb())) {  //       TBranch* branch = 0;
863           branch->SetBasketSize(basketsize);  //       TIter nextb(newTree->GetListOfBranches());
864        }  //       while ((branch = (TBranch*) nextb())) {
865     }  //      printf(" 29 \n");
866    //          branch->SetCompressionLevel(file->GetCompressionLevel());
867     Long64_t nentries = mychain->GetEntriesFast();  //       }
868    //    }
869     // Copy the entries.  
870     if (fastClone) {  //    printf(" 30 \n");
871        // For each tree in the chain.  //    // Reset the basket size of the branches.
872        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //    if (basketsize > 1000) {
873           if (mychain->LoadTree(i) < 0) {  //       TBranch* branch = 0;
874              break;  //       TIter nextb(newTree->GetListOfBranches());
875           }  //       while ((branch = (TBranch*) nextb())) {
876           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //      printf(" 31 \n");
877           if (cloner.IsValid()) {  //          branch->SetBasketSize(basketsize);
878              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //       }
879              cloner.Exec();  //    }
880           } else {  
881              if (mychain->GetFile()) {  //    printf(" 32 \n");
882                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //    Long64_t nentries = mychain->GetEntriesFast();
883                 //            } else {  //    //Long64_t nentries = mychain->GetEntries();
884                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  
885              }  //    // Copy the entries.
886           }  //    if (fastClone) {
887        }  //       // For each tree in the chain.
888     } else {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
889        for (Long64_t i = 0; i < nentries; i++) {  //          if (mychain->LoadTree(i) < 0) {
890           if (mychain->GetEntry(i) <= 0) {  //             break;
891              break;  //          }
892           }  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
893           newTree->Fill();  //          if (cloner.IsValid()) {
894        }  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
895     }  //             cloner.Exec();
896    //          } else {
897     // Write the new tree header.  //             if (mychain->GetFile()) {
898     newTree->Write();  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
899    //             //            } else {
900     // Get our return value.  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
901     Int_t nfiles = newTree->GetFileNumber() + 1;  //             }
902    //          }
903     // Close and delete the current file of the new tree.  //       }
904     if (!opt.Contains("keep")) {  //    } else {
905        // FIXME: What happens to fDirectory in newTree here?  //      printf(" 33 %llu \n",nentries);
906        delete newTree->GetCurrentFile();  //      mychain->Print();
907     }  //      for (Long64_t i = 0; i < nentries; i++) {
908     return nfiles;  //        printf(" i %llu \n",i);
909  }  //        // for (Long64_t i = 0; i < 1; i++) {
910    //          if (mychain->GetEntry(i) <= 0) {
911    //             break;
912    //          }
913    //          newTree->Fill();
914    //       }
915    //       printf(" 34 \n");
916    //    }
917    
918    //    // Write the new tree header.
919    //    printf(" 35 \n");
920    //    newTree->Write();
921    
922    //    printf(" 36 \n");
923    //    // Get our return value.
924    //    Int_t nfiles = newTree->GetFileNumber() + 1;
925    
926    //    // Close and delete the current file of the new tree.
927    //    if (!opt.Contains("keep")) {
928    //       // FIXME: What happens to fDirectory in newTree here?
929    //       delete newTree->GetCurrentFile();
930    //    }
931    //    return nfiles;
932    // }

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

  ViewVC Help
Powered by ViewVC 1.1.23