Warning, /CondFormats/SerializationHelper/README.md is written in an unsupported language. File is not indexed.
0001 # Overview of CondFormats/SerializatonHelper
0002
0003 This package provides a mechanism to load plugins which are capable of doing C++ object serialization/deserialization
0004 using the same mechanism (boost serialization) as the conditions database.
0005
0006
0007 ## Using the Code
0008 The plugin factory is named `SerializationHelperFactory` which returns instances of `SerializationHelperBase`. The
0009 latter provides methods to serialize an C++ class to a buffer and to deserialize from a buffer to an instance of a C++
0010 class. Polymorphism is supported for serialization/deserialization.
0011
0012 ## Registering a Plugin
0013
0014 The normal way to register a plugin is to just register a plugin for the CondDBESSource. The registration macros for
0015 the CondDBESSource contain calls to the macros used to generate the SerializationHelpers. One caveat is for the case
0016 where the same C++ class is begin stored in multiple Records within CondDBESSource. As the CondDBESSource registration
0017 macro includes both the Record name and the C++ class name, but the SerializationHelper system only cares about the
0018 C++ class name, this situation can cause the registration of the same C++ class multiple times which leads to a
0019 compilation error. This problem can be overcome by replacing one of the `REGISTER_PLUGIN` calls with `REGISTER_PLUGIN_NO_SERIAL`. E.g.
0020
0021 change
0022 ```cpp
0023 REGISTER_PLUGIN(FooRecord, Foo);
0024 REGISTER_PLUGIN(OtherFooRecord, Foo);
0025 ```
0026
0027 to
0028 ```cpp
0029 REGISTER_PLUGIN(FooRecord, Foo);
0030 REGISTER_PLUGIN_NO_SERIAL(OtherFooRecord, Foo);
0031 ```
0032
0033 ### Handling polymorphism
0034
0035 If the type retrieved from the EventSetup is actually a base class but what is stored is a concrete instance of
0036 one or more inheriting types, then one must explicitly create a template specialization of `cond::serialization::BaseClassInfo<>`.
0037 The template argument is the name of the base class being used by the EventSetup system. The class variable `kAbstract` states
0038 if an instance of a base class has abstract virtual functions (and therefore one can not create an instance of the base class).
0039 The type `inheriting_classes_t` is a compile time list of the inheriting classes which can be stored.
0040
0041 In addition, one must call the `DEFINE_COND_CLASSNAME` macro for the inheriting classes in order to get their names registered
0042 into the system. This is needed as the name of the actual stored type must be written into the file.
0043
0044 #### Example
0045 Say we have the base class `Base` which is what the EventSetup sees and the class has abstract virtual functions.
0046 Say we have two types `InheritA` and `InheritB` which inherit from `Base` and are actually what is to be stored. Then one would define
0047
0048 ```cpp
0049 namespace cond::serialization {
0050 template<>
0051 struct BaseClassInfo<Base> {
0052 constexpr static bool kAbstract = true;
0053 using inheriting_classes_t = edm::mpl::Vector<InheritA,InheritB>;
0054 };
0055 }
0056
0057 DEFINE_COND_CLASSNAME(InheritA)
0058 DEFINE_COND_CLASSNAME(InheritB)
0059 ```
0060
0061 This code needs to be in the same file as the calls to `REGISTER_PLUGIN`.