From 7a85fddc7e4082b17500edb7fc08cf68efcda984 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 22 Dec 2016 00:25:36 +0100 Subject: [PATCH] Hadrons: modification of registration mechanism to allow for persistent caches --- extras/Hadrons/Application.cc | 2 +- extras/Hadrons/Environment.cc | 47 +++++++++++++++++++++++++++++----- extras/Hadrons/Environment.hpp | 4 ++- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index cf7906eb..4bb3b383 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -306,7 +306,7 @@ void Application::configLoop(void) << " " << BIG_SEP << std::endl; env_.setTrajectory(t); env_.executeProgram(program_); - env_.freeAll(); } LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; + env_.freeAll(); } diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 4b230e20..68c170b8 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -410,12 +410,19 @@ Environment::Size Environment::executeProgram(const std::vector &p) // general memory management /////////////////////////////////////////////////// void Environment::addObject(const std::string name, const int moduleAddress) { - ObjInfo info; - - info.name = name; - info.module = moduleAddress; - object_.push_back(std::move(info)); - objectAddress_[name] = static_cast(object_.size() - 1); + if (!hasObject(name)) + { + ObjInfo info; + + info.name = name; + info.module = moduleAddress; + object_.push_back(std::move(info)); + objectAddress_[name] = static_cast(object_.size() - 1); + } + else + { + HADRON_ERROR("object '" + name + "' already exists"); + } } void Environment::registerObject(const unsigned int address, @@ -444,6 +451,10 @@ void Environment::registerObject(const unsigned int address, void Environment::registerObject(const std::string name, const unsigned int size, const unsigned int Ls) { + if (!hasObject(name)) + { + addObject(name); + } registerObject(getObjectAddress(name), size, Ls); } @@ -573,6 +584,30 @@ bool Environment::hasRegisteredObject(const std::string name) const } } +bool Environment::hasCreatedObject(const unsigned int address) const +{ + if (hasObject(address)) + { + return (object_[address].data != nullptr); + } + else + { + return false; + } +} + +bool Environment::hasCreatedObject(const std::string name) const +{ + if (hasObject(name)) + { + return hasCreatedObject(getObjectAddress(name)); + } + else + { + return false; + } +} + bool Environment::isObject5d(const unsigned int address) const { return (getObjectLs(address) > 1); diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 41a7a008..041bcc0e 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -137,7 +137,7 @@ public: Size executeProgram(const std::vector &p); // general memory management void addObject(const std::string name, - const int moduleAddress); + const int moduleAddress = -1); void registerObject(const unsigned int address, const unsigned int size, const unsigned int Ls = 1); @@ -176,6 +176,8 @@ public: bool hasObject(const std::string name) const; bool hasRegisteredObject(const unsigned int address) const; bool hasRegisteredObject(const std::string name) const; + bool hasCreatedObject(const unsigned int address) const; + bool hasCreatedObject(const std::string name) const; bool isObject5d(const unsigned int address) const; bool isObject5d(const std::string name) const; Environment::Size getTotalSize(void) const;