/[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.1 by mocchiut, Tue Dec 5 12:31:00 2006 UTC revision 1.15 by mocchiut, Fri Jan 30 09:37:18 2009 UTC
# Line 11  Line 11 
11  #include <TFile.h>  #include <TFile.h>
12  #include <TTree.h>  #include <TTree.h>
13  #include <TTimeStamp.h>  #include <TTimeStamp.h>
14    #include <TTreeCloner.h>
15  #include <RunGlue.h>  #include <RunGlue.h>
16  //  //
17  ClassImp(RunGlue);  ClassImp(RunGlue);
# Line 24  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 45  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 74  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;
# Line 115  TList *RunGlue::GetRunList(){ Line 116  TList *RunGlue::GetRunList(){
116      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
117      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86401;
118      //      //
     stringstream myquery;  
     myquery.str("");  
     myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit  
             << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";  
     //  
     pResult = dbc->Query(myquery.str().c_str());  
     for( UInt_t r=0; r < 1000; r++){  
       Row = pResult->Next();        
       if( Row == NULL ) break;  
       if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));  
       //  
       thisrun=dir+(TString)Row->GetField(0)+".Level2.root";        
       //  
       if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());  
       //  
       su = TFile::Open(thisrun);  
       if ( li->CheckLevel2File(thisrun) ){  
         lList->Add(su);  
       } else {  
         if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));  
       };  
       //  
     };  
     //  
119      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);
120      //      //
121      YY -= 2000;      YY -= 2000;
# Line 172  TList *RunGlue::GetRunList(){ Line 149  TList *RunGlue::GetRunList(){
149      //      //
150      printf(" Output filename is %s \n",fFilename.Data());      printf(" Output filename is %s \n",fFilename.Data());
151      //      //
152        if ( !this->OpenFile() ){
153             fEnd = true;
154             return(0);
155        };
156        //
157        stringstream myquery;
158        myquery.str("");
159        myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit
160                << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";
161        //
162        pResult = dbc->Query(myquery.str().c_str());
163        for( UInt_t r=0; r < 1000; r++){
164          Row = pResult->Next();      
165          if( Row == NULL ) break;
166          if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));
167          //
168          thisrun=dir+(TString)Row->GetField(0)+".Level2.root";      
169          //
170          if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
171          //
172          su = TFile::Open(thisrun);
173          if ( li->CheckLevel2File(thisrun) ){
174            lList->Add(su);
175          } else {
176                    if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
177          };
178          //
179        };
180        //
181        //
182      delete glrun;      delete glrun;
183      delete dbtime;      delete dbtime;
184      //      //
# Line 276  TList *RunGlue::GetRunList(){ Line 283  TList *RunGlue::GetRunList(){
283      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
284      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86401;
285      //      //
     stringstream myquery;  
     myquery.str("");  
     myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit  
             << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";  
     //  
     pResult = dbc->Query(myquery.str().c_str());  
     for( UInt_t r=0; r < 1000; r++){  
       Row = pResult->Next();        
       if( Row == NULL ) break;  
       if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));  
       //  
       thisrun=dir+(TString)Row->GetField(0)+".Level2.root";        
       //  
       if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());  
       //  
       su = TFile::Open(thisrun);  
       if ( su ){  
         TFile *su0 = TFile::Open(thisrun);  
         fDoneList->Add(su0);  
         fNlistdone++;  
       };  
       if ( li->CheckLevel2File(thisrun) ){  
         lList->Add(su);  
         if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0));  
       } else {  
         if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));  
       };  
       //  
     };  
     //  
286      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);
287      //      //
288      YY -= 2000;      YY -= 2000;
# Line 339  TList *RunGlue::GetRunList(){ Line 316  TList *RunGlue::GetRunList(){
316      //      //
317      printf(" Output filename is %s \n",fFilename.Data());      printf(" Output filename is %s \n",fFilename.Data());
318      //      //
319        if ( !this->OpenFile() ) return(0);
320        //
321        stringstream myquery;
322        myquery.str("");
323        myquery << "SELECT ID FROM GL_RUN WHERE RUNHEADER_TIME>=" << (UInt_t)lowerlimit
324                << " AND RUNHEADER_TIME<" << (UInt_t)upperlimit << " ORDER BY RUNHEADER_TIME ASC;";
325        //
326        pResult = dbc->Query(myquery.str().c_str());
327        for( UInt_t r=0; r < 1000; r++){
328          Row = pResult->Next();      
329          if( Row == NULL ) break;
330          if ( DebugMode() ) printf(" %u RUN %s \n",r,Row->GetField(0));
331          //
332          thisrun=dir+(TString)Row->GetField(0)+".Level2.root";      
333          //
334          if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
335          //
336          su = TFile::Open(thisrun);
337          if ( su ){
338            TFile *su0 = TFile::Open(thisrun);
339            fDoneList->Add(su0);
340            fNlistdone++;
341          };
342          if ( li->CheckLevel2File(thisrun) ){
343            lList->Add(su);
344            if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0));
345          } else {
346            if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
347          };
348          //
349        };
350        //
351      if ( DebugMode() ){      if ( DebugMode() ){
352        UInt_t ll = 0;        UInt_t ll = 0;
353        while ( (TFile*)lList->At(ll) ){        while ( (TFile*)lList->At(ll) ){
# Line 371  TList *RunGlue::GetRunList(){ Line 380  TList *RunGlue::GetRunList(){
380    
381  Bool_t RunGlue::OpenFile(){  Bool_t RunGlue::OpenFile(){
382    //    //
383      fOpen = false;
384    printf(" Check if output file already exists \n");    printf(" Check if output file already exists \n");
385    Target = TFile::Open((this->GetFilename()).Data(), "READ" );    ifstream myfile;
386    //    myfile.open((this->GetFilename()).Data());
387    if ( Target ){    if ( myfile ){
388      Target->Close();      //  Target = TFile::Open((this->GetFilename()).Data(), "READ" );
389        //
390        //  if ( Target ){
391        //    Target->Close();
392        myfile.close();
393      printf("Error opening target file, %s  already exist!\n",(this->GetFilename()).Data());      printf("Error opening target file, %s  already exist!\n",(this->GetFilename()).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 = 10000000000LL;        Long64_t maxsize = 99900000000LL;  
403      //      //
     Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );  
     fastMethod = kTRUE;  
     //fastMethod = kFALSE;  
     //      
     //      
404      if ( !Target || Target->IsZombie()) {      if ( !Target || Target->IsZombie()) {
405        printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());        printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data());
406        exit(1);        //      exit(1);
407          return(false);
408      }      }
409      //      //
410        Target->Write();
411        //
412        //fastMethod = kTRUE;
413        fastMethod = kFALSE;
414        //    
415        //
416      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
417        //    Target->SetCompressionLevel(2);
418        Target->SetCompressionLevel(3);
419        //Target->SetCompressionLevel(5);
420      //      //
421        fOpen = true;
422      return(true);      return(true);
423      //      //
424    };    };
# Line 434  void RunGlue::UpdateDB(TList *dlist){ Line 457  void RunGlue::UpdateDB(TList *dlist){
457    //    //
458    UInt_t ll = 0;    UInt_t ll = 0;
459    UInt_t idl2 = 0;    UInt_t idl2 = 0;
460      UInt_t idr = 0;
461      //
462      //
463      myquery.str("");
464      myquery << "select ID from GL_RAW where NAME='level2 files';";
465      if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
466    //    //
467      pResult = dbc->Query(myquery.str().c_str());
468      if ( !pResult ){
469        printf(" ERROR QUERYING ON DB!\n");
470        return;
471      };
472      Row = pResult->Next();
473      if( Row == NULL ){
474        printf(" ERROR QUERYING THE DB!\n");
475        return;
476      } else {
477        idr = (UInt_t)atoll(Row->GetField(0));
478      };
479    //    //
480    myquery.str("");    myquery.str("");
481    myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (4294967295,'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";    //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
482      myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
483    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
484    //    //
485    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
# Line 493  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( (char*)strstr( target->GetPath(), ":" ) );  
   path.Remove(0,2);  
   //  
   TDirectory *first_source = (TDirectory*)sourcelist->First();  
   THashList allNames;  
539    //    //
540    while ( first_source ){    if ( li ) li->Delete();
541      //    li = new PamLevel2(wd,sourcelist,fDList);
542      TDirectory *current_sourcedir = first_source->GetDirectory(path);    li->SetSELLI(2);
543      //    //
544      if ( !current_sourcedir ){    Target->cd();
545        first_source = (TDirectory*)sourcelist->After(first_source);    //
546        continue;    li->CreateCloneTrees(Target);
547      }    ULong64_t nevents = li->GetEntries();
548      //    printf(" NEVENTS %llu \n",nevents);
549      // loop over all keys in this directory    for(ULong64_t iev=0; iev<nevents; iev++){
550      //      li->Clear();
551      TChain *globChain = 0;      if( li->GetEntry(iev) ){
552      TIter nextkey( current_sourcedir->GetListOfKeys() );        li->FillCloneTrees();
553      TKey *key, *oldkey=0;      };
554      TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory    };
555      //    Target->cd();
556      while ( (key = (TKey*)nextkey()) ) {    li->WriteCloneTrees();
557        //    printf("Written file %s \n",Target->GetName());
558        if ( current_sourcedir == target ) break;    //  Target->Write();
559        //    //  TTree *slist = (TTree*)Target->Get("SelectionList");
560        if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue; //keep only the highest cycle number for each key    //  slist->Delete("all");
561        //    Target->Close();
562        if (allNames.FindObject(key->GetName())) continue;  
563        //  //   //
564        if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());  //   TDirectory *target = Target;
565        //  //   //
566        //  //   if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
567        //  //   //
568        if ( !strcmp(key->GetName(),"Tracker") && !li->TRK2 && !li->TRK1 && !li->TRKh ) continue;  //   TString path( (char*)strstr( target->GetPath(), ":" ) );
569        //  //   path.Remove(0,2);
570        if ( !strcmp(key->GetName(),"Calorimeter") && !li->CAL2 && !li->CAL1 ) continue;  //   //
571        //  //   TDirectory *first_source = (TDirectory*)sourcelist->First();
572        if ( !strcmp(key->GetName(),"ToF") && !li->TOF ) continue;  //   THashList allNames;
573        //  //   //
574        if ( !strcmp(key->GetName(),"Trigger") && !li->TRG ) continue;  //   while ( first_source ){
575        //  //     //
576        if ( !strcmp(key->GetName(),"Anticounter") && !li->AC ) continue;  //     TDirectory *current_sourcedir = first_source->GetDirectory(path);
577        //  //     //
578        if ( !strcmp(key->GetName(),"S4") && !li->S4 ) continue;  //     if ( !current_sourcedir ){
579        //  //       first_source = (TDirectory*)sourcelist->After(first_source);
580        if ( !strcmp(key->GetName(),"NeutronD") && !li->ND ) continue;  //       continue;
581        //  //     }
582        if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->ORB ) continue;  //     //
583        //  //     // loop over all keys in this directory
584        if ( !strcmp(key->GetName(),"Run") && !RUN ) continue;  //     //
585        //  //     TChain *globChain = 0;    
586        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") ){  //     TIter nextkey( current_sourcedir->GetListOfKeys() );
587          if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());  //     TKey *key = 0;
588          continue;  //     TKey *oldkey = 0;
589        };  //     TH1::AddDirectory(kFALSE); // gain time, do not add the objects in the list in memory
590        //  //     //
591        allNames.Add(new TObjString(key->GetName()));  //     while ( (key = (TKey*)nextkey()) ) {
592        //  //       //
593        // read object from first source file  //       //      printf(" target ls \n");
594        //  //       //      Target->ls();
595        current_sourcedir->cd();  //       //
596        TObject *obj = key->ReadObj();  //       if ( current_sourcedir == target ) break;
597        //  //       //
598        if ( obj->IsA()->InheritsFrom("TTree") ){  //       if ( oldkey && !strcmp(oldkey->GetName(),key->GetName()) ) continue; //keep only the highest cycle number for each key
599          //  //       //
600          // loop over all source files create a chain of Trees "globChain"  //       if ( allNames.FindObject(key->GetName()) ) continue;
601          //  //       //
602          TString obj_name;  //       if ( DebugMode() ) printf(" Key name is -%s- \n",key->GetName());
603          //  //       //
604          if ( path.Length() ) {  //       //
605            obj_name = path + "/" + obj->GetName();  //       //
606          } else {  //       if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
607            obj_name = obj->GetName();  //       //
608          };  //       if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
609          //  //       //
610          globChain = new TChain(obj_name);  //       if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
611          //  //       //
612          globChain->Add(first_source->GetName());  //       if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
613          //  //       //
614          TFile *nextsource = (TFile*)sourcelist->After( first_source );  //       if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
615          //  //       //
616          while ( nextsource ) {              //       if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
617            //  //       //
618            //do not add to the list a file that does not contain this Tree  //       if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
619            //  //       //
620            TFile *curf = TFile::Open(nextsource->GetName());  //       if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
621            //  //       //
622            if ( curf ) {  //       if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
623              //  //       //
624              Bool_t mustAdd = kFALSE;  //       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              if (curf->FindKey(obj_name)) {  //      continue;
627                //  //       };
628                mustAdd = kTRUE;  //       //
629                //  //       printf(" 1 \n");
630              } else {  //       allNames.Add(new TObjString(key->GetName()));
631                //  //       printf(" 2 \n");
632                //we could be more clever here. No need to import the object  //       //
633                //we are missing a function in TDirectory  //       // read object from first source file
634                //  //       //
635                TObject *aobj = curf->Get(obj_name);  //       current_sourcedir->cd();
636                //  //       TObject *obj = key->ReadObj();
637                if ( aobj ){  //       printf(" 3 \n");
638                  mustAdd = kTRUE;  //       //
639                  delete aobj;  //       if ( obj->IsA()->InheritsFrom("TTree") ){
640                };  //      //
641              };  //              // loop over all source files create a chain of Trees "globChain"
642              if (mustAdd) {  //      //
643                globChain->Add(nextsource->GetName());  //      TString obj_name;
644              };  //      printf(" 4 \n");
645            };  //      //
646            delete curf;  //      if ( path.Length() ) {
647            nextsource = (TFile*)sourcelist->After(nextsource);  //        obj_name = path + "/" + obj->GetName();
648          };  //      } else {
649          //  //        obj_name = obj->GetName();
650        } else {  //      };
651          //  //      //
652          // object is of no type that we know or can handle  //      globChain = new TChain(obj_name);
653          //  //      //
654          if ( DebugMode() ) cout << "Unknown object type, name: "  //      globChain->SetCacheSize(0);
655               << obj->GetName() << " title: " << obj->GetTitle() << endl;  //      //
656        };  //      printf(" 5 \n");
657        //  //      globChain->Add(first_source->GetName());
658        // now write the merged histogram (which is "in" obj) to the target file  //      printf(" 6 \n");
659        // note that this will just store obj in the current directory level,  //      //
660        // which is not persistent until the complete directory itself is stored  //      TFile *nextsource = (TFile*)sourcelist->After( first_source );
661        // by "target->Write()" below  //      //
662        //  //      while ( nextsource ) {            
663        if ( obj ){  //        //
664          //  //        //do not add to the list a file that does not contain this Tree
665          target->cd();  //        //
666          //  //        printf(" 7 \n");
667          if( obj->IsA()->InheritsFrom("TTree") ) {  //        TFile *curf = TFile::Open(nextsource->GetName());
668            //  //        //
669            //  //        if ( curf ) {
670            if ( fastMethod ){  //          //
671              globChain->Merge(target->GetFile(),0,"keep fast");  //          Bool_t mustAdd = kFALSE;
672            } else {  //          //
673              globChain->Merge(target->GetFile(),0,"keep");  //          if (curf->FindKey(obj_name)) {
674            };  //            //
675            //  //            mustAdd = kTRUE;
676            merged = true;  //            //
677            //  //          } else {
678            if ( DebugMode() ) globChain->ls();  //            //
679            //  //            //we could be more clever here. No need to import the object
680            delete globChain;  //            //we are missing a function in TDirectory
681            //  //            //
682          } else {  //            TObject *aobj = curf->Get(obj_name);
683            //  //            //
684            //      obj->Write( key->GetName() ); // <==================================================================================  //            if ( aobj ){
685            //  //              mustAdd = kTRUE;
686          };  //              delete aobj;
687        };  //            };
688        oldkey = key;  //          };
689      };  //          if (mustAdd) {
690      //  //            printf(" 8 \n");
691      first_source = (TDirectory*)sourcelist->After(first_source);  //            globChain->Add(nextsource->GetName());
692      //  //            printf(" 9 \n");
693    };  //          };
694    // save modifications to target file  //        };
695    target->SaveSelf(kTRUE);  //        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){
765    //    // We must have been passed a file, we will use it
766    //    // later to reset the compression level of the branches.
767    //    if (!file) {
768    //       // FIXME: We need an error message here.
769    //      printf(" 19 \n");
770    //      return 0;
771    //    }
772    //    printf(" 20 \n");
773    
774    //    // Options
775    //    Bool_t fastClone = kFALSE;
776    //    TString opt = option;
777    //    opt.ToLower();
778    //    if (opt.Contains("fast")) {
779    //       fastClone = kTRUE;
780    //       printf(" 21 \n");
781    //    }
782    //    // The chain tree must have a list of branches
783    //    // because we may try to change their basket
784    //    // size later.
785    //    TObjArray* lbranches = mychain->GetListOfBranches();
786    //    if (!lbranches) {
787    //       // FIXME: We need an error message here.
788    //      printf(" 22 \n");
789    //       return 0;
790    //    }
791    
792    //    //   file->cd();
793    //    // The chain must have a current tree because
794    //    // that is the one we will clone.
795    //    //   if (!fTree) {
796    //       // -- LoadTree() has not yet been called, no current tree.
797    //       // FIXME: We need an error message here.
798    //    //      return 0;
799    //    //   }
800    
801    //    // Copy the chain's current tree without
802    //    // copying any entries, we will do that later.
803    //    printf(" 23 \n");
804    //    TTree* newTree = mychain->CloneTree(0);
805    //    if (!newTree) {
806    //       // FIXME: We need an error message here.
807    //      printf(" 24 \n");
808    //       return 0;
809    //    }
810    //    printf(" 25 \n");
811    
812    
813    //    // Strip out the (potential) directory name.
814    //    // FIXME: The merged chain may or may not have the
815    //    //        same name as the original chain.  This is
816    //    //        bad because the chain name determines the
817    //    //        names of the trees in the chain by default.
818    //    printf(" 26 \n");
819    //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
820    //    printf(" 27 \n");
821    
822    //    // FIXME: Why do we do this?
823    //    //   newTree->SetAutoSave(-1);
824    //    newTree->SetAutoSave(900000000000000LL);
825    
826    //    printf(" 28 \n");
827    //    // 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    
832    //    // Reset the compression level of the branches.
833    //    if (opt.Contains("c")) {
834    //       TBranch* branch = 0;
835    //       TIter nextb(newTree->GetListOfBranches());
836    //       while ((branch = (TBranch*) nextb())) {
837    //      printf(" 29 \n");
838    //          branch->SetCompressionLevel(file->GetCompressionLevel());
839    //       }
840    //    }
841    
842    //    printf(" 30 \n");
843    //    // Reset the basket size of the branches.
844    //    if (basketsize > 1000) {
845    //       TBranch* branch = 0;
846    //       TIter nextb(newTree->GetListOfBranches());
847    //       while ((branch = (TBranch*) nextb())) {
848    //      printf(" 31 \n");
849    //          branch->SetBasketSize(basketsize);
850    //       }
851    //    }
852    
853    //    printf(" 32 \n");
854    //    Long64_t nentries = mychain->GetEntriesFast();
855    //    //Long64_t nentries = mychain->GetEntries();
856    
857    //    // 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    //          if (mychain->LoadTree(i) < 0) {
862    //             break;
863    //          }
864    //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
865    //          if (cloner.IsValid()) {
866    //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
867    //             cloner.Exec();
868    //          } else {
869    //             if (mychain->GetFile()) {
870    //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
871    //             //            } else {
872    //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
873    //             }
874    //          }
875    //       }
876    //    } else {
877    //      printf(" 33 %llu \n",nentries);
878    //      mychain->Print();
879    //      for (Long64_t i = 0; i < nentries; i++) {
880    //        printf(" i %llu \n",i);
881    //        // 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.1  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23