Page MenuHomeHEPForge

No OneTemporary

diff --git a/include/Rivet/AnalysisBuilder.hh b/include/Rivet/AnalysisBuilder.hh
--- a/include/Rivet/AnalysisBuilder.hh
+++ b/include/Rivet/AnalysisBuilder.hh
@@ -1,90 +1,88 @@
// -*- C++ -*-
#ifndef RIVET_AnalysisBuilder_HH
#define RIVET_AnalysisBuilder_HH
#include "Rivet/Config/RivetCommon.hh"
#include "Rivet/AnalysisLoader.hh"
#include "Rivet/Tools/Logging.hh"
namespace Rivet {
// Forward declaration
class Analysis;
/// @cond ANALYSIS_PLUGIN_DETAILS
/// @brief Interface for analysis builders
class AnalysisBuilderBase {
public:
/// Default constructor
- AnalysisBuilderBase() { }
+ AnalysisBuilderBase() = default;
/// Constructor with alias name
- AnalysisBuilderBase(const string& alias) { _alias = alias; }
+ AnalysisBuilderBase(const string& alias) : _alias(alias) {}
/// Destructor
- virtual ~AnalysisBuilderBase() { }
+ virtual ~AnalysisBuilderBase() = default;
/// Factory method, to be implemented by the analysis-specific derived class
- virtual Analysis* mkAnalysis() const = 0;
+ virtual unique_ptr<Analysis> mkAnalysis() const = 0;
/// Get the analysis' name, by asking it directly
/// @todo Could avoid this slow lookup by passing it via the constructor... at the cost of potential inconsistency
string name() const {
- Analysis* a = mkAnalysis();
- const string rtn = a->name();
- delete a;
- return rtn;
+ auto a = mkAnalysis();
+ return a->name();
}
/// @brief Get any optional alias name attached to this builder
///
/// @note An empty string is returned if there is no alias
const string& alias() const {
return _alias;
}
protected:
/// The trick: the builder is able to register itself with Rivet's loader
void _register() {
AnalysisLoader::_registerBuilder(this);
}
private:
/// Optional alias name
string _alias;
};
/// @brief Self-registering analysis plugin builder
template <typename T>
class AnalysisBuilder : public AnalysisBuilderBase {
public:
AnalysisBuilder() {
_register();
}
AnalysisBuilder(const string& alias)
: AnalysisBuilderBase(alias)
{
_register();
}
- Analysis* mkAnalysis() const {
- return new T();
+ unique_ptr<Analysis> mkAnalysis() const {
+ return unique_ptr<T>(new T);
}
};
/// @endcond
}
#endif
diff --git a/include/Rivet/AnalysisLoader.hh b/include/Rivet/AnalysisLoader.hh
--- a/include/Rivet/AnalysisLoader.hh
+++ b/include/Rivet/AnalysisLoader.hh
@@ -1,54 +1,54 @@
// -*- C++ -*-
#ifndef RIVET_AnalysisLoader_HH
#define RIVET_AnalysisLoader_HH
#include "Rivet/Config/RivetCommon.hh"
#include <map>
#include <string>
namespace Rivet {
// Forward declarations
class Analysis;
class AnalysisBuilderBase;
class Log;
/// Internal class which loads and registers analyses from plugin libs
class AnalysisLoader {
public:
/// Get all the available analyses' names.
static vector<string> analysisNames();
static set<string> getAllAnalysisNames();
/// Get an analysis by name.
/// Warning: a name arg which matches no known analysis will return a null
/// pointer. Check your return values before using them!
- static Analysis* getAnalysis(const string& analysisname);
+ static unique_ptr<Analysis> getAnalysis(const string& analysisname);
/// Get all the available analyses.
- static vector<Analysis*> getAllAnalyses();
+ static vector<unique_ptr<Analysis>> getAllAnalyses();
private:
/// Allow the analysis builders to call the private _registerBuilder function
friend class AnalysisBuilderBase;
/// Register a new analysis builder
static void _registerBuilder(const AnalysisBuilderBase* a);
/// Load the available analyses at runtime.
static void _loadAnalysisPlugins();
typedef map<string, const AnalysisBuilderBase*> AnalysisBuilderMap;
static AnalysisBuilderMap _ptrs;
};
}
#endif
diff --git a/pyext/Makefile.am b/pyext/Makefile.am
--- a/pyext/Makefile.am
+++ b/pyext/Makefile.am
@@ -1,26 +1,26 @@
SUBDIRS = rivet
if ENABLE_PYEXT
-PYEXT_ENV = CC="$(CC)" CXX="$(CXX)" CXXFLAGS="$(PYEXT_CXXFLAGS)" ARCHFLAGS=""
+PYEXT_ENV = CC="$(CXX)" CXX="$(CXX)" CXXFLAGS="$(PYEXT_CXXFLAGS)" ARCHFLAGS=""
## Always force setup.py, it's not good at guessing what needs to rebuild
all-local:
$(PYEXT_ENV) $(PYTHON) setup.py install --install-lib=build/ --force
install-exec-local:
$(PYEXT_ENV) $(PYTHON) setup.py install --prefix=$(DESTDIR)$(prefix) --force
uninstall-local:
rm -rf $(DESTDIR)$(RIVET_PYTHONPATH)/rivet
rm -f $(DESTDIR)$(RIVET_PYTHONPATH)/rivet-$(VERSION)-py$(PYTHON_VERSION).egg-info
clean-local:
rm -f $(builddir)/*.pyc
rm -rf $(builddir)/build
rm -rf dist
distclean-local:
rm -f rivet.egg-info
endif
diff --git a/pyext/rivet/Makefile.am b/pyext/rivet/Makefile.am
--- a/pyext/rivet/Makefile.am
+++ b/pyext/rivet/Makefile.am
@@ -1,39 +1,39 @@
EXTRA_DIST = \
__init__.py \
spiresbib.py util.py \
plotinfo.py aopaths.py \
core.pyx rivet.pxd \
core.cpp
if WITH_CYTHON
RIVETINCLUDE = $(top_srcdir)/include/Rivet/
core.cpp: core.pyx rivet.pxd $(RIVETINCLUDE)/Analysis.hh $(RIVETINCLUDE)/AnalysisHandler.hh $(RIVETINCLUDE)/AnalysisLoader.hh $(RIVETINCLUDE)/Run.hh
- cython $(srcdir)/core.pyx --cplus -o $@
+ cython --cplus $(srcdir)/core.pyx -o $@
else
core.cpp:
@echo "Not (re)generating core.cpp since Cython is not installed"
endif
## fixes for out-of-source builds, especially "make distcheck"
all-local: fix-out-of-source
FIXSOURCES = $(EXTRA_DIST)
fix-out-of-source: $(FIXSOURCES)
rm -f $@
for i in $^; do \
orig="$$i"; \
build="$$(basename $$i)"; \
if [ ! -e $${build} ]; then cp $${orig} $${build}; \
echo $${build} >> $@; fi; \
done
touch $@
clean-local: fix-out-of-source
if [ -e $< ]; then if [ -n "$$(cat $<)" ]; then rm -f $$(cat $<); fi; fi
rm -f $<
diff --git a/pyext/rivet/core.pyx b/pyext/rivet/core.pyx
--- a/pyext/rivet/core.pyx
+++ b/pyext/rivet/core.pyx
@@ -1,165 +1,169 @@
+# distutils: language = c++
+
cimport rivet as c
+from cython.operator cimport dereference as deref
# Need to be careful with memory management -- perhaps use the base object that
# we used in YODA?
+cdef extern from "<utility>" namespace "std" nogil:
+ cdef c.unique_ptr[c.Analysis] move(c.unique_ptr[c.Analysis])
+
cdef class AnalysisHandler:
cdef c.AnalysisHandler *_ptr
def __cinit__(self):
self._ptr = new c.AnalysisHandler()
def __del__(self):
del self._ptr
def setIgnoreBeams(self, ignore=True):
self._ptr.setIgnoreBeams(ignore)
def addAnalysis(self, name):
self._ptr.addAnalysis(name)
return self
def writeData(self, name):
self._ptr.writeData(name)
def crossSection(self):
return self._ptr.crossSection()
def finalize(self):
self._ptr.finalize()
cdef class Run:
cdef c.Run *_ptr
def __cinit__(self, AnalysisHandler h):
self._ptr = new c.Run(h._ptr[0])
def __del__(self):
del self._ptr
def setCrossSection(self, double x):
self._ptr.setCrossSection(x)
return self
def setListAnalyses(self, choice):
self._ptr.setListAnalyses(choice)
return self
def init(self, name, weight=1.0):
return self._ptr.init(name, weight)
def openFile(self, name, weight=1.0):
return self._ptr.openFile(name, weight)
def readEvent(self):
return self._ptr.readEvent()
def processEvent(self):
return self._ptr.processEvent()
def finalize(self):
return self._ptr.finalize()
cdef class Analysis:
- cdef c.Analysis *_ptr
+ cdef c.unique_ptr[c.Analysis] _ptr
def __init__(self):
raise RuntimeError('This class cannot be instantiated')
- def __del__(self):
- del self._ptr
def requiredBeams(self):
- return self._ptr.requiredBeams()
+ return deref(self._ptr).requiredBeams()
def requiredEnergies(self):
- return self._ptr.requiredEnergies()
+ return deref(self._ptr).requiredEnergies()
def authors(self):
- return self._ptr.authors()
+ return deref(self._ptr).authors()
def bibKey(self):
- return self._ptr.bibKey()
+ return deref(self._ptr).bibKey()
def name(self):
- return self._ptr.name()
+ return deref(self._ptr).name()
def bibTeX(self):
- return self._ptr.bibTeX()
+ return deref(self._ptr).bibTeX()
def references(self):
- return self._ptr.references()
+ return deref(self._ptr).references()
def collider(self):
- return self._ptr.collider()
+ return deref(self._ptr).collider()
def description(self):
- return self._ptr.description()
+ return deref(self._ptr).description()
def experiment(self):
- return self._ptr.experiment()
+ return deref(self._ptr).experiment()
def inspireId(self):
- return self._ptr.inspireId()
+ return deref(self._ptr).inspireId()
def spiresId(self):
- return self._ptr.spiresId()
+ return deref(self._ptr).spiresId()
def runInfo(self):
- return self._ptr.runInfo()
+ return deref(self._ptr).runInfo()
def status(self):
- return self._ptr.status()
+ return deref(self._ptr).status()
def summary(self):
- return self._ptr.summary()
+ return deref(self._ptr).summary()
def year(self):
- return self._ptr.year()
+ return deref(self._ptr).year()
#cdef object
LEVELS = dict(TRACE = 0, DEBUG = 10, INFO = 20,
WARN = 30, WARNING = 30, ERROR = 40,
CRITICAL = 50, ALWAYS = 50)
cdef class AnalysisLoader:
@staticmethod
def analysisNames():
return c.AnalysisLoader_analysisNames()
@staticmethod
def getAnalysis(name):
- cdef c.Analysis* ptr = c.AnalysisLoader_getAnalysis(name)
+ cdef c.unique_ptr[c.Analysis] ptr = c.AnalysisLoader_getAnalysis(name)
cdef Analysis pyobj = Analysis.__new__(Analysis)
if not ptr:
return None
- pyobj._ptr = ptr
+ pyobj._ptr = move(ptr)
# Create python object
return pyobj
def addAnalysisLibPath(path):
c.addAnalysisLibPath(path)
def findAnalysisRefFile(q):
return c.findAnalysisRefFile(q)
def getAnalysisPlotPaths():
return c.getAnalysisPlotPaths()
def getAnalysisRefPaths():
return c.getAnalysisRefPaths()
def getAnalysisLibPaths():
return c.getAnalysisLibPaths()
def setAnalysisLibPaths(xs):
c.setAnalysisLibPaths(xs)
def version():
return c.version()
def setLogLevel(name, level):
c.setLogLevel(name, level)
diff --git a/pyext/rivet/rivet.pxd b/pyext/rivet/rivet.pxd
--- a/pyext/rivet/rivet.pxd
+++ b/pyext/rivet/rivet.pxd
@@ -1,74 +1,75 @@
from libcpp.map cimport map
from libcpp.pair cimport pair
from libcpp.vector cimport vector
from libcpp cimport bool
from libcpp.string cimport string
+from libcpp.memory cimport unique_ptr
ctypedef int PdgId
ctypedef pair[PdgId,PdgId] PdgIdPair
cdef extern from "Rivet/AnalysisHandler.hh" namespace "Rivet":
cdef cppclass AnalysisHandler:
void setIgnoreBeams(bool)
AnalysisHandler& addAnalysis(string)
void writeData(string&)
double crossSection()
void finalize()
cdef extern from "Rivet/Run.hh" namespace "Rivet":
cdef cppclass Run:
Run(AnalysisHandler)
Run& setCrossSection(double) # For chaining?
Run& setListAnalyses(bool)
bool init(string, double) # $2=1.0
bool openFile(string, double) # $2=1.0
bool readEvent()
bool processEvent()
bool finalize()
cdef extern from "Rivet/Analysis.hh" namespace "Rivet":
cdef cppclass Analysis:
vector[PdgIdPair]& requiredBeams()
vector[pair[double, double]] requiredEnergies()
vector[string] authors()
vector[string] references()
string name()
string bibTeX()
string bibKey()
string collider()
string description()
string experiment()
string inspireId()
string spiresId()
string runInfo()
string status()
string summary()
string year()
# Might need to translate the following errors, although I believe 'what' is now
# preserved. But often, we need the exception class name.
#Error
#RangeError
#LogicError
#PidError
#InfoError
#WeightError
#UserError
cdef extern from "Rivet/AnalysisLoader.hh":
vector[string] AnalysisLoader_analysisNames "Rivet::AnalysisLoader::analysisNames" ()
- Analysis* AnalysisLoader_getAnalysis "Rivet::AnalysisLoader::getAnalysis" (string)
+ unique_ptr[Analysis] AnalysisLoader_getAnalysis "Rivet::AnalysisLoader::getAnalysis" (string)
cdef extern from "Rivet/Tools/RivetPaths.hh" namespace "Rivet":
void addAnalysisLibPath(string)
string findAnalysisRefFile(string)
vector[string] getAnalysisPlotPaths()
vector[string] getAnalysisRefPaths()
vector[string] getAnalysisLibPaths()
void setAnalysisLibPaths(vector[string])
cdef extern from "Rivet/Rivet.hh" namespace "Rivet":
string version()
cdef extern from "Rivet/Tools/Logging.hh":
void setLogLevel "Rivet::Log::setLevel" (string, int)
diff --git a/pyext/setup.py.in b/pyext/setup.py.in
--- a/pyext/setup.py.in
+++ b/pyext/setup.py.in
@@ -1,48 +1,48 @@
#! /usr/bin/env python
from distutils.core import setup
from distutils.extension import Extension
from glob import glob
## Extension definition
import os.path
srcincdir = os.path.abspath("@top_srcdir@/include")
buildincdir = os.path.abspath("@top_builddir@/include")
srcdir = os.path.abspath("@top_srcdir@/src")
libdir = os.path.abspath("@top_builddir@/src/.libs")
## Assemble the library search dirs
lookupdirs = [
libdir,
"@HEPMCLIBPATH@",
"@FASTJETLIBPATH@",
"@YODALIBPATH@" ]
## Be careful with extracting the GSL path from the flags string
import re
re_libdirflag = re.compile(r".*-L\s*(\S+).*")
re_match = re_libdirflag.search("@GSL_LDFLAGS@")
if re_match:
lookupdirs.append( re_match.group(1) )
## A helper function (since we have two modules now...)
def ext(name, depends=[], statics=[]):
return Extension(
"rivet.%s" % name,
["rivet/%s.cpp" % name] + statics,
- language="C++",
+ language="c++",
depends=depends,
include_dirs=[srcincdir, buildincdir],
extra_compile_args= "-I@prefix@/include @PYEXT_CXXFLAGS@ @HEPMCCPPFLAGS@ @FASTJETCPPFLAGS@ @YODACPPFLAGS@ @GSLCPPFLAGS@".split(),
library_dirs=lookupdirs,
runtime_library_dirs=lookupdirs[1:],
- libraries=["stdc++", "gsl", "HepMC", "fastjet", "YODA", "Rivet"])
+ libraries=["gsl", "HepMC", "fastjet", "YODA", "Rivet"])
header_files = glob("../include/Rivet/*.h") + glob("../include/Rivet/Utils/*.h")
extns = [ext("core", header_files)]
setup(name = "rivet",
version="@PACKAGE_VERSION@",
ext_modules = extns,
packages = ["rivet"])
diff --git a/src/Core/AnalysisLoader.cc b/src/Core/AnalysisLoader.cc
--- a/src/Core/AnalysisLoader.cc
+++ b/src/Core/AnalysisLoader.cc
@@ -1,125 +1,125 @@
// -*- C++ -*-
#include "Rivet/AnalysisLoader.hh"
#include "Rivet/Tools/RivetPaths.hh"
#include "Rivet/Tools/Utils.hh"
#include "Rivet/Tools/osdir.hh"
#include "Rivet/Analysis.hh"
#include <dlfcn.h>
namespace Rivet {
namespace {
inline Log& getLog() {
return Log::getLog("Rivet.AnalysisLoader");
}
}
// Initialise static ptr collection
AnalysisLoader::AnalysisBuilderMap AnalysisLoader::_ptrs;
vector<string> AnalysisLoader::analysisNames() {
_loadAnalysisPlugins();
vector<string> names;
foreach (const AnalysisBuilderMap::value_type& p, _ptrs) names += p.first;
return names;
}
set<string> AnalysisLoader::getAllAnalysisNames() {
set<string> anaset;
vector<string> anas = analysisNames();
foreach (const string &ana, anas) {
anaset.insert(ana);
}
return anaset;
}
- Analysis* AnalysisLoader::getAnalysis(const string& analysisname) {
+ unique_ptr<Analysis> AnalysisLoader::getAnalysis(const string& analysisname) {
_loadAnalysisPlugins();
AnalysisBuilderMap::const_iterator ai = _ptrs.find(analysisname);
- if (ai == _ptrs.end()) return 0;
+ if (ai == _ptrs.end()) return nullptr;
return ai->second->mkAnalysis();
}
- vector<Analysis*> AnalysisLoader::getAllAnalyses() {
+ vector<unique_ptr<Analysis>> AnalysisLoader::getAllAnalyses() {
_loadAnalysisPlugins();
- vector<Analysis*> analyses;
- foreach (const AnalysisBuilderMap::value_type& p, _ptrs) {
- analyses += p.second->mkAnalysis();
+ vector<unique_ptr<Analysis>> analyses;
+ foreach (const auto & p, _ptrs) {
+ analyses.emplace_back( p.second->mkAnalysis() );
}
return analyses;
}
void AnalysisLoader::_registerBuilder(const AnalysisBuilderBase* ab) {
if (!ab) return;
const string name = ab->name();
if (_ptrs.find(name) != _ptrs.end()) {
// Duplicate analyses will be ignored... loudly
//cerr << "Ignoring duplicate plugin analysis called '" << name << "'" << endl;
MSG_WARNING("Ignoring duplicate plugin analysis called '" << name << "'");
} else {
MSG_TRACE("Registering a plugin analysis called '" << name << "'");
_ptrs[name] = ab;
}
const string aname = ab->alias();
if (!aname.empty()) {
//MSG_WARNING("ALIAS!!! " << aname);
if (_ptrs.find(aname) != _ptrs.end()) {
MSG_WARNING("Ignoring duplicate plugin analysis alias '" << aname << "'");
} else {
MSG_TRACE("Registering a plugin analysis via alias '" << aname << "'");
_ptrs[aname] = ab;
}
}
}
void AnalysisLoader::_loadAnalysisPlugins() {
// Only run once
if (!_ptrs.empty()) return;
// Build the list of directories to search
const vector<string> dirs = getAnalysisLibPaths();
// Find plugin module library files
const string libsuffix = ".so";
vector<string> pluginfiles;
foreach (const string& d, dirs) {
if (d.empty()) continue;
oslink::directory dir(d);
while (dir) {
string filename = dir.next();
// Require that plugin lib name starts with 'Rivet'
if (filename.find("Rivet") != 0) continue;
size_t posn = filename.find(libsuffix);
if (posn == string::npos || posn != filename.length()-libsuffix.length()) continue;
/// @todo Make sure this is an abs path
/// @todo Sys-dependent path separator instead of "/"
const string path = d + "/" + filename;
// Ensure no duplicate paths
if (find(pluginfiles.begin(), pluginfiles.end(), path) == pluginfiles.end()) {
pluginfiles += path;
}
}
}
// Load the plugin files
MSG_TRACE("Candidate analysis plugin libs: " << pluginfiles);
foreach (const string& pf, pluginfiles) {
MSG_TRACE("Trying to load plugin analyses from file " << pf);
void* handle = dlopen(pf.c_str(), RTLD_LAZY);
if (!handle) {
MSG_WARNING("Cannot open " << pf << ": " << dlerror());
continue;
}
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 19, 8:00 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3805950
Default Alt Text
(19 KB)

Event Timeline