diff --git a/test/testApi.cc b/test/testApi.cc --- a/test/testApi.cc +++ b/test/testApi.cc @@ -1,35 +1,34 @@ #include "Rivet/AnalysisHandler.hh" #include "HepMC/GenEvent.h" #include "Rivet/Tools/RivetHepMC.hh" #include using namespace std; int main(int argc, char* argv[]) { assert(argc > 1); Rivet::AnalysisHandler ah; Rivet::Log::setLevel("Rivet", Rivet::Log::DEBUG); // Specify the analyses to be used ah.addAnalysis("EXAMPLE"); ah.addAnalyses({{ "MC_JETS", "EXAMPLE_CUTS", "EXAMPLE_SMEAR" }}); - std::ifstream file("testApi.hepmc"); - shared_ptr reader = Rivet::HepMCUtils::makeReader(file); + shared_ptr file; + shared_ptr reader = Rivet::HepMCUtils::makeReader("testApi.hepmc", file); std::shared_ptr evt = make_shared(); double sum_of_weights = 0.0; while ( Rivet::HepMCUtils::readEvent(reader, evt) ) { // Analyse current event ah.analyze(*evt); sum_of_weights += evt->weights()[0]; } - file.close(); ah.setCrossSection(make_pair(1.0, 0.1)); ah.finalize(); ah.writeData("out.yoda"); return 0; } diff --git a/test/testNaN.cc b/test/testNaN.cc --- a/test/testNaN.cc +++ b/test/testNaN.cc @@ -1,77 +1,76 @@ #include "Rivet/AnalysisHandler.hh" #include "Rivet/Analysis.hh" #include "Rivet/Tools/RivetYODA.hh" #include #include #include #include using namespace std; class NanTest : public Rivet::Analysis { public: DEFAULT_RIVET_ANALYSIS_CTOR(NanTest); void init() { book(_h_test, "test", 50, 66.0, 116.0); } void analyze(const Rivet::Event & e) { cout << "Normal fill" << endl; _h_test->fill(90.); cout << "Underflow fill" << endl; _h_test->fill(30.); cout << "Overflow fill" << endl; _h_test->fill(130.); cout << "Inf fill" << endl; try { _h_test->fill(numeric_limits::infinity()); } catch (YODA::RangeError & e) { cerr << e.what() << '\n'; if ( string(e.what()) != string("X is Inf") ) throw; } cout << "NaN fill" << endl; try { _h_test->fill(numeric_limits::quiet_NaN()); } catch (YODA::RangeError & e) { cerr << e.what() << '\n'; if ( string(e.what()) != string("X is NaN") ) throw; } } private: Rivet::Histo1DPtr _h_test; }; DECLARE_RIVET_PLUGIN(NanTest); int main(int argc, char* argv[]) { assert(argc > 1); Rivet::AnalysisHandler rivet; rivet.addAnalysis("NanTest"); - std::ifstream file("testApi.hepmc"); - shared_ptr reader = Rivet::HepMCUtils::makeReader(file); + std::shared_ptr file; + shared_ptr reader = Rivet::HepMCUtils::makeReader("testApi.hepmc", file); std::shared_ptr evt = make_shared(); double sum_of_weights = 0.0; while ( Rivet::HepMCUtils::readEvent(reader, evt) ) { // Analyse current event rivet.analyze(*evt); sum_of_weights += evt->weights()[0]; } - file.close(); rivet.setCrossSection(make_pair(1.0, 0.1)); rivet.finalize(); rivet.writeData("NaN.yoda"); return 0; }