Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
read_ntuple_with_chain.C
Go to the documentation of this file.
1// Read several previously produced N-Tuples and print on screen its
2// content.
3//
4// you can easily create some files with the following statement:
5//
6// for i in 0 1 2 3 4 5; \\
7// do root -x -b -q \\
8// "write_ntuple_to_file.cxx \\
9// (\"conductivity_experiment_${i}.root\", 100)"; \\
10// done
11
13 // initiate a TChain with the name of the TTree to be processed
14 TChain in_chain("cond_data");
15 in_chain.Add("conductivity_experiment*.root"); // add files,
16 // wildcards work
17
18 // define variables and assign them to the corresponding branches
19 float pot, cur, temp, pres;
20 in_chain.SetBranchAddress("Potential", &pot);
21 in_chain.SetBranchAddress("Current", &cur);
22 in_chain.SetBranchAddress("Temperature", &temp);
23 in_chain.SetBranchAddress("Pressure", &pres);
24
25 cout << "Potential\tCurrent\tTemperature\tPressure\n";
26 for (size_t irow=0; irow<in_chain.GetEntries(); ++irow){
27 in_chain.GetEntry(irow); // loads all variables that have
28 // been connected to branches
29 cout << pot << "\t" << cur << "\t" << temp <<
30 "\t" << pres << endl;
31 }
32}
A chain is a collection of files containing TTree objects.
Definition TChain.h:33
Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError) override
Definition TChain.cxx:3069
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition TChain.cxx:211
Long64_t GetEntries() const override
Return the total number of entries in the chain.
Definition TChain.cxx:958
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Get entry from the file to memory.
Definition TChain.cxx:996
void read_ntuple_with_chain()