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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.23