12#ifndef ALICEO2_ROOTSERKEYVALUESTORE_H
13#define ALICEO2_ROOTSERKEYVALUESTORE_H
21#include <TBufferFile.h>
62 std::swap(*
this, temp);
76 TClass
const*
cl =
nullptr;
89 static constexpr const char* GetStateString[4] = {
98 return (
int)
state < 4 ? GetStateString[(int)
state] :
nullptr;
105 template <
typename T>
114 template <
typename T>
115 const T*
get(std::string
const&
key)
const
118 return get_impl<T>(
key,
s,
int{});
122 template <
typename T>
125 return get_impl<T>(
key,
state,
int{});
130 template <
typename T>
146 return mStore.find(
key) != mStore.end();
156 void print(
bool includetypeinfo =
false)
const;
162 mStore =
other.mStore;
166 std::map<std::string, SerializedInfo> mStore;
169 template <
typename T>
174 auto ptr = std::make_unique<T>(T{
value});
175 auto cl = TClass::GetClass(
typeid(
value));
180 std::unique_ptr<char> bufferptr(
nullptr);
182 buff.WriteObjectAny(
ptr.get(), cl);
183 int N = buff.Length();
184 bufferptr.reset(
new char[N]);
185 memcpy(bufferptr.get(), buff.Buffer(),
sizeof(
char) * N);
187 auto name = std::type_index(
typeid(
value)).name();
188 mStore.insert(std::pair<std::string, SerializedInfo>(
key, SerializedInfo(N, std::move(bufferptr), cl,
name)));
192 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
T>
::type* =
nullptr>
196 static_assert(!std::is_pointer<T>::value);
198 auto ptr = std::make_unique<T>(T{
value});
200 std::unique_ptr<char> bufferptr(
new char[N]);
201 memcpy(bufferptr.get(), (
char*)
ptr.get(),
sizeof(
char) * N);
203 auto name = std::type_index(
typeid(
value)).name();
204 mStore.insert(std::pair<std::string, SerializedInfo>(
key, SerializedInfo(N, std::move(bufferptr),
nullptr,
name)));
208 template <
typename T>
212 auto iter = mStore.find(
key);
213 if (iter != mStore.end()) {
214 auto&
info =
const_cast<SerializedInfo&
>(iter->second);
215 auto cl = TClass::GetClass(
typeid(T));
220 if (
info.cl && strcmp(cl->GetName(),
info.cl->GetName()) == 0) {
223 return (T*)
info.objptr;
228 auto instance = (
T*)buff.ReadObjectAny(cl);
229 info.objptr = instance;
230 return (T*)
info.objptr;
241 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
T>
::type* =
nullptr>
245 auto iter = mStore.find(
key);
246 if (iter != mStore.end()) {
247 auto&
info =
const_cast<SerializedInfo&
>(iter->second);
248 if (strcmp(std::type_index(
typeid(T)).
name(),
info.typeinfo_name.c_str()) == 0) {
251 return (T*)
info.objptr;
254 return (T*)
info.objptr;
265 void remove_entry(std::string
const&
key)
267 auto iter = mStore.find(
key);
268 if (iter != mStore.end()) {
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
const T & getRef(std::string const &key, GetState &state) const
const T * get(std::string const &key, GetState &state) const
returns object pointer for this key or nullptr if error or does not exist; state is set with meaningf...
RootSerializableKeyValueStore()=default
void put(std::string const &key, T const &value)
const T * get(std::string const &key) const
returns object pointer for this key or nullptr if error or does not exist.
static const char * getStateString(GetState state)
void copyFrom(RootSerializableKeyValueStore const &other)
resets store to the store of another object
void clear()
clear the store
bool has(std::string const &key) const
checks if a key exists
GLuint const GLchar * name
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.
Structure encapsulating the stored information: raw buffers and attached type information (combinatio...
SerializedInfo & operator=(SerializedInfo const &other)
Int_t N
pointer for "caching"
SerializedInfo(SerializedInfo const &other)
SerializedInfo(int N, std::unique_ptr< char > buffer, TClass const *cl, std::string const &s)
std::string typeinfo_name
ClassDefNV(SerializedInfo, 1)
VectorOfTObjectPtrs other