Skip to content
Snippets Groups Projects
Commit ff09c1fe authored by Klaus Zenker (HZDR)'s avatar Klaus Zenker (HZDR) Committed by Zenker, Dr. Klaus (FWKE) - 126506
Browse files

Add time information for the history buffers.

parent 29d427bf
No related branches found
No related tags found
No related merge requests found
......@@ -85,14 +85,24 @@ namespace ChimeraTK { namespace history {
struct AccessorAttacher;
template<typename UserType>
struct HistoryEntry{
HistoryEntry(bool enableHistory): data(std::vector<ArrayOutput<UserType> >{}),
timeStamp(std::vector<ArrayOutput<uint64_t> >{}),
withTimeStamps(enableHistory){ }
std::vector<ArrayOutput<UserType> > data;
std::vector<ArrayOutput<uint64_t> > timeStamp;
bool withTimeStamps;
};
struct ServerHistory : public ApplicationModule {
ServerHistory(EntityOwner* owner, const std::string& name, const std::string& description,
size_t historyLength = 1200, bool eliminateHierarchy = false, const std::unordered_set<std::string>& tags = {})
: ApplicationModule(owner, name, description, eliminateHierarchy, tags), _historyLength(historyLength) {}
size_t historyLength = 1200, bool enableTimeStamps = false, bool eliminateHierarchy = false, const std::unordered_set<std::string>& tags = {})
: ApplicationModule(owner, name, description, eliminateHierarchy, tags), _historyLength(historyLength), _enbaleTimeStamps(enableTimeStamps) { }
/** Default constructor, creates a non-working module. Can be used for late
* initialisation. */
ServerHistory() : _historyLength(1200) {}
ServerHistory() : _historyLength(1200), _enbaleTimeStamps(false) {}
/** Add a Module as a source to this History module. */
void addSource(const Module& source, const RegisterPath& namePrefix, const VariableNetworkNode &trigger = {});
......@@ -111,7 +121,7 @@ namespace ChimeraTK { namespace history {
* ArrayPushInput and ArrayOutput accessors. These accessors are dynamically
* created by the AccessorAttacher. */
template<typename UserType>
using AccessorList = std::list<std::pair<ArrayPushInput<UserType>, std::vector<ArrayOutput<UserType>>>>;
using AccessorList = std::list<std::pair<ArrayPushInput<UserType>, HistoryEntry<UserType> > >;
TemplateUserTypeMap<AccessorList> _accessorListMap;
/** boost::fusion::map of UserTypes to std::lists containing the names of the
......@@ -127,6 +137,7 @@ namespace ChimeraTK { namespace history {
std::list<std::string> _overallVariableList;
size_t _historyLength;
bool _enbaleTimeStamps;
friend struct AccessorAttacher;
};
......
#include "ServerHistory.h"
//#include "ChimeraTK/TransferElementID.h"
#include "boost/date_time/posix_time/posix_time.hpp"
namespace ChimeraTK { namespace history {
......@@ -90,17 +90,27 @@ namespace ChimeraTK { namespace history {
0,
"",
}),
std::forward_as_tuple(std::vector<ArrayOutput<UserType>>{}));
std::forward_as_tuple(HistoryEntry<UserType>{_enbaleTimeStamps}));
for(size_t i = 0; i < nElements; i++) {
if(nElements == 1) {
// in case of a scalar history only use the variableName
tmpList.back().second.emplace_back(
tmpList.back().second.data.emplace_back(
ArrayOutput<UserType>{&groupMap[dirName], baseName, "", _historyLength, "", {"CS", getName()}});
if(_enbaleTimeStamps){
tmpList.back().second.timeStamp.emplace_back(
ArrayOutput<uint64_t>{&groupMap[dirName], baseName + "_timeStamps", "Time stamps for entries in the history buffer",
_historyLength, "", {"CS", getName()}});
}
}
else {
// in case of an array history append the index to the variableName
tmpList.back().second.emplace_back(ArrayOutput<UserType>{
tmpList.back().second.data.emplace_back(ArrayOutput<UserType>{
&groupMap[dirName], baseName + "_" + std::to_string(i), "", _historyLength, "", {"CS", getName()}});
if(_enbaleTimeStamps){
tmpList.back().second.timeStamp.emplace_back(
ArrayOutput<uint64_t>{&groupMap[dirName], baseName + "_" + std::to_string(i) + "_timeStamps", "Time stamps for entries in the history buffer",
_historyLength, "", {"CS", getName()}});
}
}
}
nameList.push_back(variableName);
......@@ -119,9 +129,15 @@ namespace ChimeraTK { namespace history {
if(accessor->first.getId() == _id) {
for(size_t i = 0; i < accessor->first.getNElements(); i++) {
std::rotate(
accessor->second.at(i).begin(), accessor->second.at(i).begin() + 1, accessor->second.at(i).end());
*(accessor->second.at(i).end() - 1) = accessor->first[i];
accessor->second.at(i).write();
accessor->second.data.at(i).begin(), accessor->second.data.at(i).begin() + 1, accessor->second.data.at(i).end());
*(accessor->second.data.at(i).end() - 1) = accessor->first[i];
accessor->second.data.at(i).write();
if(accessor->second.withTimeStamps){
std::rotate(
accessor->second.timeStamp.at(i).begin(), accessor->second.timeStamp.at(i).begin() + 1, accessor->second.timeStamp.at(i).end());
*(accessor->second.timeStamp.at(i).end() - 1) = boost::posix_time::to_time_t(boost::posix_time::second_clock::local_time());
accessor->second.timeStamp.at(i).write();
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment