/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/calibUtil/calibUtil-00-00-43/src/test/test_root.cxx File Reference

#include <string.h>
#include "TChain.h"
#include "TFile.h"
#include "TH1.h"
#include "TTree.h"
#include "TKey.h"
#include "Riostream.h"
#include "TFolder.h"

Go to the source code of this file.

Functions

void MergeRootfile (TDirectory *target, TList *sourcelist)
int main (int argc, char *argv[])

Variables

TList * FileList
TFile * Target


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 13 of file test_root.cxx.

References FileList, genRecEmupikp::i, MergeRootfile(), deljobs::string, and Target.

00013                                  {
00014 //  std::cout <<  << "  " << file1 << std::endl;
00015 //  char* file = "result.root";
00016   std::cout<<"argv[0]:"<<argv[0]<<std::endl;
00017    std::cout<<"argv[1]:"<<argv[1]<<std::endl;
00018    std::cout<<"argv[2]:"<<argv[2]<<std::endl;
00019    std::cout<<"argv[3]:"<<argv[3]<<std::endl;
00020   Target = TFile::Open(argv[1], "RECREATE" );
00021   FileList = new TList();
00022 //  char* file1="/home/bes/huangb/root_test/hist.root";
00023   for(int i=0;i<10000;i++){
00024     std::cout<<"argv[i+2]=="<<argv[i+2]<<std::endl;
00025     if(string(argv[i+2])=="end") break;
00026     FileList->Add( TFile::Open(argv[i+2]) );
00027   }
00028 //  FileList->Add( TFile::Open("/home/bes/huangb/root_test/hist1.root") );
00029   MergeRootfile( Target, FileList );
00030 
00031 } /* end of main */

void MergeRootfile ( TDirectory *  target,
TList *  sourcelist 
)

Definition at line 32 of file test_root.cxx.

References key, and next.

Referenced by main().

00032                                                             {
00033 
00034   //  cout << "Target path: " << target->GetPath() << endl;
00035   TString path( (char*)strstr( target->GetPath(), ":" ) );
00036   path.Remove( 0, 2 );
00037 
00038   TFile *first_source = (TFile*)sourcelist->First();
00039   first_source->cd( path );
00040   TDirectory *current_sourcedir = gDirectory;
00041   //gain time, do not add the objects in the list in memory
00042   Bool_t status = TH1::AddDirectoryStatus();
00043   TH1::AddDirectory(kFALSE);
00044 
00045   // loop over all keys in this directory
00046   TChain *globChain = 0;
00047   TIter nextkey( current_sourcedir->GetListOfKeys() );
00048   TKey *key, *oldkey=0;
00049   while ( (key = (TKey*)nextkey())) {
00050 
00051     //keep only the highest cycle number for each key
00052     if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;
00053    //  std::cout<<"key->GetName()=="<<key->GetName()<<std::endl;
00054     // read object from first source file
00055     first_source->cd( path );
00056     TObject *obj = key->ReadObj();
00057 
00058       TFolder* add = dynamic_cast<TFolder*>(obj);
00059       TCollection *hh = add->GetListOfFolders();
00060       TFolder* add1=new TFolder(key->GetName(), key->GetTitle());
00061 //     TIter next(hh);
00062 
00063       TFile *nextsource = (TFile*)sourcelist->After( first_source );
00064       while ( nextsource ) {
00065         TIter next(hh);
00066         nextsource->cd( path );
00067         std::cout<<"nextsource->Name()=="<<std::endl;
00068         nextsource->Print();
00069         std::cout<<"firstsource->Name()=="<<std::endl;
00070         first_source->Print();
00071         TFolder* kk=(TFolder *)nextsource->Get(key->GetName());
00072         std::cout<<"key->GetName()=="<<key->GetName()<<std::endl;
00073          first_source->cd( path );
00074          while ((obj = next())){
00075          TH1 *h1 = (TH1*)obj;
00076          std::cout<<"obj->getName()=="<<obj->GetName()<<std::endl;
00077          add1->Add(h1);
00078         nextsource->cd( path );
00079         TH1 *h2 = (TH1*)kk->FindObjectAny(h1->GetName());
00080     if(h2){
00081         h1->Add( h2 );
00082         std::cout<<"h1->GetEntries()"<<h1->GetEntries()<<std::endl;
00083         }
00084         }
00085         nextsource = (TFile*)sourcelist->After( nextsource );
00086       }
00087     target->cd();
00088    // std::cout<<"add TFolder:"<<add1->GetName()<<std::endl;
00089    add1->Write();
00090     delete add1;
00091     delete hh;
00092 }
00093   target->SaveSelf(kTRUE);
00094 }


Variable Documentation

TList* FileList

Definition at line 9 of file test_root.cxx.

Referenced by main().

TFile* Target

Definition at line 10 of file test_root.cxx.

Referenced by main().


Generated on Tue Nov 29 23:14:52 2016 for BOSS_7.0.2 by  doxygen 1.4.7