This macro will add histograms from a list of root files and write them to a target root file. The target file is newly created and must not be identical to one of the source files. This code is based on the hadd.C example by Rene Brun and Dirk Geppert, which had a problem with directories more than one level deep. The macro from Sven has been enhanced by Anne-Sylvie Nicollerat Anne-.nosp@m.Sylv.nosp@m.ie.Ni.nosp@m.coll.nosp@m.erat@.nosp@m.cern.nosp@m..ch to automatically add Trees (via a chain of trees).
#include <string.h>
void hadd() {
}
MergeRootfile( Target, FileList );
}
path.Remove( 0, 2 );
first_source->
cd( path );
while ( (key = (
TKey*)nextkey())) {
first_source->
cd( path );
while ( nextsource ) {
if (key2) {
delete h2;
}
nextsource = (
TFile*)sourcelist->
After( nextsource );
}
}
const char* obj_name= obj->
GetName();
globChain =
new TChain(obj_name);
while ( nextsource ) {
nextsource = (
TFile*)sourcelist->
After( nextsource );
}
cout <<
"Found subdirectory " << obj->
GetName() << endl;
MergeRootfile( newdir, sourcelist );
} else {
cout << "Unknown object type, name: "
}
if ( obj ) {
else
}
}
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
R__EXTERN TSystem * gSystem
A chain is a collection of files containing TTree objects.
virtual Long64_t Merge(const char *name, Option_t *option="")
Merge all the entries in the chain into a new tree in a new file.
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Bool_t cd() override
Change current directory to "this" directory.
Describe directory structure in memory.
virtual TList * GetListOfKeys() const
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
TH1 is the base class of all histogram classes in ROOT.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual TObject * ReadObj()
To read a TObject* from the file.
TObject * After(const TObject *obj) const override
Returns the object after object obj.
void Add(TObject *obj) override
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual const char * GetTitle() const
Returns title of object.
virtual TClass * IsA() const
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.