|
[Rivet-svn] r2116 - in trunk: . bin include/Rivet src src/Analysesblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Nov 30 21:36:47 GMT 2009
Author: buckley Date: Mon Nov 30 21:36:47 2009 New Revision: 2116 Log: General tweaks around the implementation of the run class and cross-section handling Modified: trunk/ChangeLog trunk/bin/rivet trunk/include/Rivet/Run.hh trunk/src/Analyses/MC_LHC_WANALYSIS.cc trunk/src/Analyses/MC_LHC_ZANALYSIS.cc trunk/src/Analysis.cc trunk/src/Run.cc Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/ChangeLog Mon Nov 30 21:36:47 2009 (r2116) @@ -1,5 +1,8 @@ 2009-11-30 Andy Buckley <andy at insectnation.org> + * Using shared pointers to make I/O object memory management + neater and less error-prone. + * Adding crossSectionPerEvent() method [== crossSection()/sumOfWeights()] to Analysis. Useful for histogram scaling since numerator of sumW_passed/sumW_total (to calculate Modified: trunk/bin/rivet ============================================================================== --- trunk/bin/rivet Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/bin/rivet Mon Nov 30 21:36:47 2009 (r2116) @@ -397,7 +397,7 @@ EVTNUM += 1 logNEvt(EVTNUM, starttime, opts.MAXEVTNUM) if not run.processEvent(EVTNUM==1): - logging.warn("run.processEvent failed for evt #%i!" % (EVTNUM)) + #logging.warn("run.processEvent failed for evt #%i!" % (EVTNUM)) break if RECVD_KILL_SIGNAL is not None: break Modified: trunk/include/Rivet/Run.hh ============================================================================== --- trunk/include/Rivet/Run.hh Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/include/Rivet/Run.hh Mon Nov 30 21:36:47 2009 (r2116) @@ -93,11 +93,11 @@ /// @name HepMC I/O members //@{ - /// HepMC's own reader from streams - HepMC::IO_GenEvent* m_io; + /// Output stream for HepMC writer + shared_ptr<std::istream> _istr; - /// STL istream, used by IO_GenEvent if input is not a file - std::istream* m_istr; + /// HepMC I/O writer + shared_ptr<HepMC::IO_GenEvent> _io; //@} Modified: trunk/src/Analyses/MC_LHC_WANALYSIS.cc ============================================================================== --- trunk/src/Analyses/MC_LHC_WANALYSIS.cc Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/src/Analyses/MC_LHC_WANALYSIS.cc Mon Nov 30 21:36:47 2009 (r2116) @@ -15,6 +15,7 @@ /// Default constructor MC_LHC_WANALYSIS() : Analysis("MC_LHC_WANALYSIS") { + setNeedsCrossSection(true); _sumWPass = 0.0; } Modified: trunk/src/Analyses/MC_LHC_ZANALYSIS.cc ============================================================================== --- trunk/src/Analyses/MC_LHC_ZANALYSIS.cc Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/src/Analyses/MC_LHC_ZANALYSIS.cc Mon Nov 30 21:36:47 2009 (r2116) @@ -15,7 +15,7 @@ /// Default constructor MC_LHC_ZANALYSIS() : Analysis("MC_LHC_ZANALYSIS") { - // + setNeedsCrossSection(true); } Modified: trunk/src/Analysis.cc ============================================================================== --- trunk/src/Analysis.cc Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/src/Analysis.cc Mon Nov 30 21:36:47 2009 (r2116) @@ -12,9 +12,10 @@ Analysis::Analysis(const string& name) - : _gotCrossSection(false), + : _crossSection(-1.0), + _gotCrossSection(false), _needsCrossSection(false), - _analysishandler(0), + _analysishandler(NULL), _madeHistoDir(false) { ProjectionApplier::_allowProjReg = false; @@ -183,7 +184,7 @@ } double Analysis::crossSection() const { - if (!_gotCrossSection) { + if (!_gotCrossSection || _crossSection < 0) { string errMsg = "You did not set the cross section for the analysis " + name(); throw Error(errMsg); } Modified: trunk/src/Run.cc ============================================================================== --- trunk/src/Run.cc Mon Nov 30 20:29:30 2009 (r2115) +++ trunk/src/Run.cc Mon Nov 30 21:36:47 2009 (r2116) @@ -8,13 +8,12 @@ namespace Rivet { - Run::Run(AnalysisHandler& ah) : _ah(ah), _xs(-1.0), - m_io(NULL), m_istr(NULL) { - } + Run::Run(AnalysisHandler& ah) + : _ah(ah), _xs(-1.0) + { } - Run::~Run() { - } + Run::~Run() { } Run& Run::setCrossSection(const double xs) { @@ -31,13 +30,13 @@ bool Run::prepareFile(const std::string& evtfile) { if (evtfile == "-") { - m_io = new HepMC::IO_GenEvent(std::cin); + _io.reset(new HepMC::IO_GenEvent(std::cin)); } else { // Ignore the HepMC::IO_GenEvent(filename, ios) constructor, since it's only available from HepMC 2.4 - m_istr = new std::fstream(evtfile.c_str(), std::ios::in); - m_io = new HepMC::IO_GenEvent(*m_istr); + _istr.reset(new std::fstream(evtfile.c_str(), std::ios::in)); + _io.reset(new HepMC::IO_GenEvent(*_istr)); } - if (m_io->rdstate() != 0) { + if (_io->rdstate() != 0) { Log::getLog("Rivet.Run") << Log::ERROR << "Read error on file " << evtfile << endl; return false; } @@ -47,17 +46,11 @@ bool Run::processEvent(bool firstEvent) { - GenEvent* evt = new GenEvent(); - if (!m_io->fill_next_event(evt)) { - Log::getLog("Rivet.Run") << Log::DEBUG << "m_io->fill_next_event failed!" << endl; - delete evt; - return false; - } - - // Check for a bad read - if (m_io->rdstate() != 0) { - Log::getLog("Rivet.Run") << Log::DEBUG << "End of file?" << endl; - delete evt; + // Fill event and check for a bad read state + shared_ptr<GenEvent> evt; + evt.reset(new GenEvent()); + if (_io->rdstate() != 0 || !_io->fill_next_event(evt.get()) ) { + Log::getLog("Rivet.Run") << Log::DEBUG << "Read failed. End of file?" << endl; return false; } @@ -77,7 +70,6 @@ Log::getLog("Rivet.Run") << Log::ERROR << "Event beams mismatch: " << beams << " @ " << sqrts/GeV << " GeV" << " vs. first beams " << this->beams() << " @ " << this->sqrtS()/GeV << " GeV" << endl; - delete evt; return false; } } @@ -88,7 +80,6 @@ // If empty if (evt->particles_size() == 0) { Log::getLog("Rivet.Run") << Log::ERROR << "Empty first event." << endl; - delete evt; return false; } @@ -98,7 +89,6 @@ Log::getLog("Rivet.Run") << Log::ERROR << "All analyses were incompatible with the first event's beams\n" << "Exiting, since this probably isn't intentional!" << endl; - delete evt; return false; } @@ -107,8 +97,10 @@ cout << ana << endl; } } + } + // Set cross-section if specified from command line if (_xs > 0.0) { _ah.setCrossSection(_xs); @@ -128,26 +120,20 @@ Log::getLog("Rivet.Run") << Log::ERROR << "Total cross-section needed for at least one of the analyses. " << "Please set it (on the command line with '-x' if using the 'rivet' program)" << endl; - delete evt; return false; } } /// @todo If NOT first event, check that beams aren't changed - // Analyze event and delete HepMC event object + // Analyze event _ah.analyze(*evt); - delete evt; return true; } bool Run::finalizeFile() { - // Final HepMC object clean-up - delete m_io; - if (m_istr) delete m_istr; - return true; }
More information about the Rivet-svn mailing list |