#include "eff_utils/BinnedEfficiency.hpp" #include "eff_utils/EffWriteManager.hpp" #include #include #include #include using namespace eff_utils; using namespace std; /* Read input spc files with BinnedEfficiency objects and merge histogram with the equivalent meta data to one object . /author Slava Shary (shary@fnal.gov) */ void Usage(){ cout << "Usage: MergeSPCFiles " << "-input " << "-out_dir " << "-mode " << endl; cout << "Input and output files must be located in different directories" << endl ; cout << "The mode could be \"replace\" or \"add\" (default) "<< endl ; exit(-1); } int main(int argc, char** argv) { enum MODE {ADD, REPLACE} ; MODE mode = ADD ; string filename ; string dir = "." ; if (argc == 1) Usage() ; for( int arg=1; arg efficiencies ; // read list of file and read all available efficiencies ifstream f(filename.c_str()) ; while(f && f.good()) { string ist; getline(f,ist); // open file and read efficiencies ifstream fstr(ist.c_str(),ios::in); BinnedEfficiency* beff = 0 ; while ( (beff = new BinnedEfficiency( fstr ))->isValid() ) { // if there is an efficiency with the same set of meta data, // add the new efficiency to the old one // or replce the old one with the new vector::iterator it = efficiencies.begin(); for (; it != efficiencies.end() ; it++) { if ((*it)->Info() != beff->Info()) continue ; if (mode == REPLACE) { (*it) = beff ; cout << "Replace efficiency "<< beff->Info().EffName() ; string ids ; if ( beff->Info().getEntry("MCReqId", ids)) cout << " ID: " << ids ; cout << " with one from file " << filename << endl ; } else (*it)->add(beff) ; break ; } // if not , add the new efficiency to the list if (it == efficiencies.end()) efficiencies.push_back(beff) ; } } // end of input file list // 1) create a WriteManager and specify the directory path EffWriteManager manager(dir) ; // 2) stream it out to the file for (vector::iterator it = efficiencies.begin(); it != efficiencies.end(); it++) manager.Save(**it) ; return 0; }