11 #include "Riostream.h"
22 void MergeRootfile( TDirectory *target, TList *sourcelist );
25 void haddWana(
char *set =
"sumFeb21_2011", TString iPath =
"./")
29 if (strstr(
"sumFeb21_2011", set) > 0) {
30 char *runL =
" cutsOnly_Feb21 raw_sumFeb21";
32 else if (strstr(
"setXX", set) > 0) {
33 char *runL =
"HHHHH ";
36 printf(
" hadd: set=%s= NOT found, quit\n", set);
39 printf(
" hadd: set=%s= path=%s= ...\n", set, iPath.Data());
41 Target = TFile::Open( out +
".wana.hist.root",
"RECREATE" );
42 FileList =
new TList();
43 printf(
"sum Output '%s' \n", Target->GetName());
45 char *run = strtok(runL,
" ");
48 printf(
"add run %d '%s' \n", i++, run);
49 if (isAPS2010pol && strstr(set,
"run9setP") > 0 ) {
50 int irun = atoi(run + 1);
51 if (irun >= 10083013 && irun <= 10083058) {
52 printf(
"\tdrop %s from F10415\n", run);
55 if (irun >= 10098015 && irun <= 10098015) {
56 printf(
"\tdrop %s from F10508\n", run);
60 TString fullName = iPath + run +
".wana.hist.root";
61 FileList->Add( TFile::Open(fullName));
63 while (run = strtok(0,
" "));
65 MergeRootfile( Target, FileList );
66 printf(
"finished Output '%s' \n", Target->GetName());
70 void MergeRootfile( TDirectory *target, TList *sourcelist )
73 cout <<
"Target path: " << target->GetPath() << endl;
74 TString path( (
char*)strstr( target->GetPath(),
":" ) );
77 TFile *first_source = (TFile*)sourcelist->First();
78 first_source->cd( path );
79 TDirectory *current_sourcedir = gDirectory;
83 TChain *globChain = 0;
84 TIter nextkey( current_sourcedir->GetListOfKeys() );
86 while ( (key = (TKey*)nextkey())) {
87 const char *name = key->GetName();
89 if (nh % 100 == 0) printf(
"nh=%d addingX %s\n", nh, name);
92 first_source->cd( path );
93 TObject *obj = key->ReadObj();
95 if ( obj->IsA()->InheritsFrom(
"TH1" ) ) {
103 TFile *nextsource = (TFile*)sourcelist->After( first_source );
104 while ( nextsource ) {
107 nextsource->cd( path );
108 TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
115 nextsource = (TFile*)sourcelist->After( nextsource );
118 else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
121 const char* obj_name = obj->GetName();
123 globChain =
new TChain(obj_name);
124 globChain->Add(first_source->GetName());
125 TFile *nextsource = (TFile*)sourcelist->After( first_source );
128 while ( nextsource ) {
130 globChain->Add(nextsource->GetName());
131 nextsource = (TFile*)sourcelist->After( nextsource );
135 else if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
138 cout <<
"Found subdirectory " << obj->GetName() << endl;
142 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
147 MergeRootfile( core, newdir, sourcelist );
153 cout <<
"Unknown object type, name: "
154 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
165 if (obj->IsA()->InheritsFrom(
"TTree" ))
166 globChain->Write( key->GetName() );
168 obj->Write( key->GetName() );