Last active
August 29, 2015 14:03
-
-
Save pgjones/5e6e5b355e633d0f7dad to your computer and use it in GitHub Desktop.
Example TChain root file loading for rat-4.5.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////// | |
/// My preferred method to load a root file in root. | |
/// Must load in root as .L Load.cc+ | |
/// | |
/// 11/10/2012 : New File | |
//////////////////////////////////////////////////////// | |
#include <RAT/DS/Root.hh> | |
#include <RAT/DS/EV.hh> | |
#include <RAT/DS/Run.hh> | |
#include <TH1D.h> | |
#include <TChain.h> | |
#include <TFile.h> | |
#include <time.h> | |
using namespace std; | |
void | |
LoadRootFile( const char* lpFile, | |
TChain **tree, | |
TChain **runTree, | |
RAT::DS::Root **rDS, | |
RAT::DS::Run **rRun ); | |
void | |
DoSomething( const char* inFile ) | |
{ | |
// Load the root file first | |
RAT::DS::Root* rDS; | |
RAT::DS::Run* rRun; | |
TChain *tree, *runTree; | |
LoadRootFile( inFile, &tree, &runTree, &rDS, &rRun ); | |
time_t codeStart = time( NULL ); | |
for( int iEvent = 0; iEvent < tree->GetEntries(); iEvent++ ) | |
{ | |
if( iEvent % 100 == 0 ) | |
cout << iEvent << " finished at " << time( NULL ) - codeStart << endl; | |
tree->GetEntry( iEvent ); | |
// Do something here | |
} | |
} | |
void | |
LoadRootFile( const char* lpFile, | |
TChain **tree, | |
TChain **runTree, | |
RAT::DS::Root **rDS, | |
RAT::DS::Run **rRun ) | |
{ | |
*tree = new TChain( "T" ); | |
(*tree)->Add( lpFile ); | |
*runTree = new TChain( "runT" ); | |
(*runTree)->Add( lpFile ); | |
*rDS = new RAT::DS::Root(); | |
(*tree)->SetBranchAddress( "ds", &(*rDS) ); | |
*rRun = new RAT::DS::Run(); | |
(*runTree)->SetBranchAddress( "run", &(*rRun) ); | |
(*runTree)->GetEntry(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.L Load.cc+ | |
DoSomething( "file*.root" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment