Skip to content

Instantly share code, notes, and snippets.

@jdbrice
Created August 1, 2016 21:15
Show Gist options
  • Select an option

  • Save jdbrice/f79eda8e17b50022c01766a98dfae4f0 to your computer and use it in GitHub Desktop.

Select an option

Save jdbrice/f79eda8e17b50022c01766a98dfae4f0 to your computer and use it in GitHub Desktop.
#include <map>
#include <unordered_map>
#include <vector>
map<int, bool> runNumbers;
vector<int> runNumbersInFile( string fn ) {
TFile * f = new TFile( fn.c_str(), "READ" );
TTreeReader reader( "tof", f );
TTreeReaderValue<Int_t> runId( reader, "run" );
unordered_map< Int_t, bool > unqRuns;
while( reader.Next() ) {
unqRuns[ *runId ] = true;
}
f->Close();
vector<int> runNums;
for ( auto kv : unqRuns ){
runNums.push_back( kv.first );
}
return runNums;
}
void runMapMaker( string filelist = "filelist_period1.lis" ){
ifstream inf( filelist.c_str() );
std::string line ="";
while( getline( inf, line ) ){
// cout << "filename : " << line << endl;
vector<int> rns = runNumbersInFile( line );
for ( int rn : rns ){
runNumbers[ rn ] = true;
}
}
int iRun = 0;
for ( auto kv : runNumbers ){
cout << "runMap[ " << kv.first << " ] = " << iRun << ";" << endl;
iRun++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment