BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
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

◆ main()

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

Definition at line 13 of file test_root.cxx.

13 {
14// std::cout << << " " << file1 << std::endl;
15// char* file = "result.root";
16 std::cout<<"argv[0]:"<<argv[0]<<std::endl;
17 std::cout<<"argv[1]:"<<argv[1]<<std::endl;
18 std::cout<<"argv[2]:"<<argv[2]<<std::endl;
19 std::cout<<"argv[3]:"<<argv[3]<<std::endl;
20 Target = TFile::Open(argv[1], "RECREATE" );
21 FileList = new TList();
22// char* file1="/home/bes/huangb/root_test/hist.root";
23 for(int i=0;i<10000;i++){
24 std::cout<<"argv[i+2]=="<<argv[i+2]<<std::endl;
25 if(string(argv[i+2])=="end") break;
26 FileList->Add( TFile::Open(argv[i+2]) );
27 }
28// FileList->Add( TFile::Open("/home/bes/huangb/root_test/hist1.root") );
30
31} /* end of main */
void MergeRootfile(TDirectory *target, TList *sourcelist)
Definition: test_root.cxx:32
TList * FileList
Definition: test_root.cxx:9
TFile * Target
Definition: test_root.cxx:10

◆ MergeRootfile()

void MergeRootfile ( TDirectory *  target,
TList *  sourcelist 
)

Definition at line 32 of file test_root.cxx.

32 {
33
34 // cout << "Target path: " << target->GetPath() << endl;
35 TString path( (char*)strstr( target->GetPath(), ":" ) );
36 path.Remove( 0, 2 );
37
38 TFile *first_source = (TFile*)sourcelist->First();
39 first_source->cd( path );
40 TDirectory *current_sourcedir = gDirectory;
41 //gain time, do not add the objects in the list in memory
42 Bool_t status = TH1::AddDirectoryStatus();
43 TH1::AddDirectory(kFALSE);
44
45 // loop over all keys in this directory
46 TChain *globChain = 0;
47 TIter nextkey( current_sourcedir->GetListOfKeys() );
48 TKey *key, *oldkey=0;
49 while ( (key = (TKey*)nextkey())) {
50
51 //keep only the highest cycle number for each key
52 if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;
53 // std::cout<<"key->GetName()=="<<key->GetName()<<std::endl;
54 // read object from first source file
55 first_source->cd( path );
56 TObject *obj = key->ReadObj();
57
58 TFolder* add = dynamic_cast<TFolder*>(obj);
59 TCollection *hh = add->GetListOfFolders();
60 TFolder* add1=new TFolder(key->GetName(), key->GetTitle());
61// TIter next(hh);
62
63 TFile *nextsource = (TFile*)sourcelist->After( first_source );
64 while ( nextsource ) {
65 TIter next(hh);
66 nextsource->cd( path );
67 std::cout<<"nextsource->Name()=="<<std::endl;
68 nextsource->Print();
69 std::cout<<"firstsource->Name()=="<<std::endl;
70 first_source->Print();
71 TFolder* kk=(TFolder *)nextsource->Get(key->GetName());
72 std::cout<<"key->GetName()=="<<key->GetName()<<std::endl;
73 first_source->cd( path );
74 while ((obj = next())){
75 TH1 *h1 = (TH1*)obj;
76 std::cout<<"obj->getName()=="<<obj->GetName()<<std::endl;
77 add1->Add(h1);
78 nextsource->cd( path );
79 TH1 *h2 = (TH1*)kk->FindObjectAny(h1->GetName());
80 if(h2){
81 h1->Add( h2 );
82 std::cout<<"h1->GetEntries()"<<h1->GetEntries()<<std::endl;
83 }
84 }
85 nextsource = (TFile*)sourcelist->After( nextsource );
86 }
87 target->cd();
88 // std::cout<<"add TFolder:"<<add1->GetName()<<std::endl;
89 add1->Write();
90 delete add1;
91 delete hh;
92}
93 target->SaveSelf(kTRUE);
94}
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition: Taupair.h:42
Index next(Index i)
Definition: EvtCyclic3.cc:107

Referenced by main().

Variable Documentation

◆ FileList

TList* FileList

Definition at line 9 of file test_root.cxx.

Referenced by main().

◆ Target

TFile* Target

Definition at line 10 of file test_root.cxx.

Referenced by main().