BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
test_root.cxx
Go to the documentation of this file.
1#include "Riostream.h"
2#include "TChain.h"
3#include "TFile.h"
4#include "TFolder.h"
5#include "TH1.h"
6#include "TKey.h"
7#include "TTree.h"
8#include <string.h>
9
10using namespace std;
11TList* FileList;
12TFile* Target;
13void MergeRootfile( TDirectory* target, TList* sourcelist );
14
15int main( int argc, char* argv[] ) {
16 // std::cout << << " " << file1 << std::endl;
17 // char* file = "result.root";
18 std::cout << "argv[0]:" << argv[0] << std::endl;
19 std::cout << "argv[1]:" << argv[1] << std::endl;
20 std::cout << "argv[2]:" << argv[2] << std::endl;
21 std::cout << "argv[3]:" << argv[3] << std::endl;
22 Target = TFile::Open( argv[1], "RECREATE" );
23 FileList = new TList();
24 // char* file1="/home/bes/huangb/root_test/hist.root";
25 for ( int i = 0; i < 10000; i++ )
26 {
27 std::cout << "argv[i+2]==" << argv[i + 2] << std::endl;
28 if ( string( argv[i + 2] ) == "end" ) break;
29 FileList->Add( TFile::Open( argv[i + 2] ) );
30 }
31 // FileList->Add( TFile::Open("/home/bes/huangb/root_test/hist1.root") );
33
34} /* end of main */
35void MergeRootfile( TDirectory* target, TList* sourcelist ) {
36
37 // cout << "Target path: " << target->GetPath() << endl;
38 TString path( (char*)strstr( target->GetPath(), ":" ) );
39 path.Remove( 0, 2 );
40
41 TFile* first_source = (TFile*)sourcelist->First();
42 first_source->cd( path );
43 TDirectory* current_sourcedir = gDirectory;
44 // gain time, do not add the objects in the list in memory
45 Bool_t status = TH1::AddDirectoryStatus();
46 TH1::AddDirectory( kFALSE );
47
48 // loop over all keys in this directory
49 TChain* globChain = 0;
50 TIter nextkey( current_sourcedir->GetListOfKeys() );
51 TKey * key, *oldkey = 0;
52 while ( ( key = (TKey*)nextkey() ) )
53 {
54
55 // keep only the highest cycle number for each key
56 if ( oldkey && !strcmp( oldkey->GetName(), key->GetName() ) ) continue;
57 // std::cout<<"key->GetName()=="<<key->GetName()<<std::endl;
58 // read object from first source file
59 first_source->cd( path );
60 TObject* obj = key->ReadObj();
61
62 TFolder* add = dynamic_cast<TFolder*>( obj );
63 TCollection* hh = add->GetListOfFolders();
64 TFolder* add1 = new TFolder( key->GetName(), key->GetTitle() );
65 // TIter next(hh);
66
67 TFile* nextsource = (TFile*)sourcelist->After( first_source );
68 while ( nextsource )
69 {
70 TIter next( hh );
71 nextsource->cd( path );
72 std::cout << "nextsource->Name()==" << std::endl;
73 nextsource->Print();
74 std::cout << "firstsource->Name()==" << std::endl;
75 first_source->Print();
76 TFolder* kk = (TFolder*)nextsource->Get( key->GetName() );
77 std::cout << "key->GetName()==" << key->GetName() << std::endl;
78 first_source->cd( path );
79 while ( ( obj = next() ) )
80 {
81 TH1* h1 = (TH1*)obj;
82 std::cout << "obj->getName()==" << obj->GetName() << std::endl;
83 add1->Add( h1 );
84 nextsource->cd( path );
85 TH1* h2 = (TH1*)kk->FindObjectAny( h1->GetName() );
86 if ( h2 )
87 {
88 h1->Add( h2 );
89 std::cout << "h1->GetEntries()" << h1->GetEntries() << std::endl;
90 }
91 }
92 nextsource = (TFile*)sourcelist->After( nextsource );
93 }
94 target->cd();
95 // std::cout<<"add TFolder:"<<add1->GetName()<<std::endl;
96 add1->Write();
97 delete add1;
98 delete hh;
99 }
100 target->SaveSelf( kTRUE );
101}
*************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
int main()
Definition phokhara.cc:42
void MergeRootfile(TDirectory *target, TList *sourcelist)
Definition test_root.cxx:35
TList * FileList
Definition test_root.cxx:11
TFile * Target
Definition test_root.cxx:12