Commit f8c808c4 authored by Pawel Sznajder's avatar Pawel Sznajder
Browse files

remove internal variables from Observables, serialize via std::vector

parent dd24236b
......@@ -10,6 +10,7 @@
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../BaseObject.h"
#include "channel/ChannelType.h"
......@@ -56,6 +57,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
//********************************************************
//*** SETTERS AND GETTERS ********************************
//********************************************************
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../utils/type/PhysicalType.h"
#include "../../utils/type/PhysicalUnit.h"
......@@ -54,6 +55,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
//********************************************************
//*** GETTERS AND SETTERS ********************************
//********************************************************
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../../utils/type/PhysicalType.h"
#include "../../../utils/type/PhysicalUnit.h"
......@@ -99,6 +100,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
/**
* Is equal operator. Checks if values of kinematic variables are the same.
*/
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../../utils/type/PhysicalType.h"
#include "../../../utils/type/PhysicalUnit.h"
......@@ -100,6 +101,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
/**
* Is equal operator. Checks if values of kinematic variables are the same.
*/
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../utils/type/PhysicalType.h"
#include "../../utils/type/PhysicalUnit.h"
......@@ -154,6 +155,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
/**
* Is equal operator. Checks if values of kinematic variables are the same.
*/
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../../utils/type/PhysicalType.h"
#include "../../../utils/type/PhysicalUnit.h"
......@@ -137,6 +138,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
/**
* Is equal operator. Checks if values of kinematic variables are the same.
*/
......
......@@ -10,6 +10,7 @@
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../channel/ChannelType.h"
#include "../Kinematic.h"
......@@ -47,6 +48,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
//********************************************************
//*** SETTERS AND GETTERS ********************************
//********************************************************
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <string>
#include <vector>
#include "../../../utils/type/PhysicalType.h"
#include "../../../utils/type/PhysicalUnit.h"
......@@ -138,6 +139,17 @@ public:
*/
void unserialize(ElemUtils::Packet &packet);
/**
* Serialize to std::vector<double>.
*/
void serializeIntoStdVector(std::vector<double>& vec) const;
/**
* Unserialize from std::vector<double>.
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end);
/**
* Is equal operator. Checks if values of kinematic variables are the same.
*/
......
......@@ -80,19 +80,12 @@ protected:
*/
DVCSObservable(const DVCSObservable& other);
virtual void setKinematics(const DVCSObservableKinematic& kinematic);
virtual void initModule();
virtual void isModuleWellConfigured();
virtual PhysicalType<double> computeObservable(
const DVCSObservableKinematic& kinematic,
const List<GPDType>& gpdType) = 0;
double m_xB; ///< Bjorken variable.
double m_t; ///< Mandelstam variable (square of the 4-momentum transferm in GeV2).
double m_Q2; ///< Virtuality of the incoming photon (in GeV2).
double m_E; ///< Beam energy in target rest frame (in GeV).
double m_phi; ///< Angle between leptonic and hadronic plane (in radians, Trento convention).
DVCSProcessModule* m_pProcessModule; ///< Pointer to the underlying process module.
};
......
......@@ -11,6 +11,7 @@
#include <ElementaryUtils/logger/CustomException.h>
#include <ElementaryUtils/parameters/Parameters.h>
#include <stddef.h>
#include <iterator>
#include <map>
#include <string>
#include <vector>
......@@ -100,12 +101,6 @@ protected:
ModuleObject(other) {
}
/**
* Set internal kinematics
* @param kinematic Kinematics to be set
*/
virtual void setKinematics(const KinematicType& kinematic) = 0;
virtual void initModule() {
}
......@@ -119,12 +114,15 @@ protected:
const KinematicType& kinematic, const List<GPDType>& gpdType) = 0;
/**
* List of GPD types to std::vector<double>.
* Serialize kinematics and list of GPD types to std::vector<double>.
*/
std::vector<double> gpdTypesToVector(const List<GPDType>& list) const {
std::vector<double> serializeKinematicsAndGPDTypesIntoStdVector(
const KinematicType& kin, const List<GPDType>& list) const {
std::vector<double> result;
kin.serializeIntoStdVector(result);
for (size_t i = 0; i < list.size(); i++) {
result.push_back(static_cast<double>(list[i].getType()));
}
......@@ -133,17 +131,21 @@ protected:
}
/**
* std::vector<double> to list of GPD types.
* Unserialize kinematics and list of GPD types from std::vector<double>.
*/
List<GPDType> gpdTypesFromVector(const std::vector<double>& vec) const {
void unserializeKinematicsAndGPDTypesFromStdVector(
const std::vector<double>& vec, KinematicType& kin,
List<GPDType>& list) const {
List<GPDType> result;
std::vector<double>::const_iterator it = vec.begin();
for (size_t i = 0; i < vec.size(); i++) {
result.add(GPDType(static_cast<GPDType::Type>(vec[i])));
}
kin.unserializeFromStdVector(it, vec.end());
return result;
list.clear();
for (; it != vec.end(); it++) {
list.add(GPDType(static_cast<GPDType::Type>(*it)));
}
}
};
......
......@@ -11,7 +11,6 @@
#include <ElementaryUtils/parameters/Parameters.h>
#include <map>
#include <string>
#include <vector>
#include "../../../beans/automation/BaseObjectData.h"
#include "../../../beans/gpd/GPDType.h"
......@@ -80,26 +79,12 @@ protected:
*/
TCSObservable(const TCSObservable& other);
virtual void setKinematics(const TCSObservableKinematic& kinematic);
virtual void initModule();
virtual void isModuleWellConfigured();
virtual PhysicalType<double> computeObservable(
const TCSObservableKinematic& kinematic,
const List<GPDType>& gpdType) = 0;
/**
* Serialize kinematics and list of GPD types to std::vector<double>.
*/
std::vector<double> serializeKinematicsAndGPDTypesToVector(
const TCSObservableKinematic& kin, const List<GPDType>& list) const;
/**
* Unserialize kinematics and list of GPD types from std::vector<double>.
*/
void unserializeKinematicsAndGPDTypesFromVector(
const std::vector<double>& vec, TCSObservableKinematic& kin,
List<GPDType>& list) const;
TCSProcessModule* m_pProcessModule; ///< Pointer to the underlying process module.
};
......
......@@ -12,8 +12,10 @@
#include <ElementaryUtils/parameters/GenericType.h>
#include <ElementaryUtils/string_utils/Formatter.h>
#include <ElementaryUtils/thread/Packet.h>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include "../../BaseObject.h"
#include "PhysicalUnit.h"
......@@ -118,6 +120,47 @@ public:
m_unit = type;
}
/**
* Serialize into std::vector<double>
*/
void serializeIntoStdVector(std::vector<double>& vec) const {
vec.push_back(static_cast<double>(m_initialized));
vec.push_back(static_cast<double>(m_value));
vec.push_back(static_cast<double>(m_unit));
}
/**
* Uneserialize from std::vector<double>
*/
void unserializeFromStdVector(std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
if (it >= end) {
throw ElemUtils::CustomException(this->getClassName(), __func__,
"Input vector is too short");
}
m_initialized = static_cast<bool>(*it);
it++;
if (it >= end) {
throw ElemUtils::CustomException(this->getClassName(), __func__,
"Input vector is too short");
}
m_value = static_cast<T>(*it);
it++;
if (it >= end) {
throw ElemUtils::CustomException(this->getClassName(), __func__,
"Input vector is too short");
}
m_unit = static_cast<PhysicalUnit::Type>(*it);
it++;
}
/**
* Return string representing value and unit. To be used mainly in the generation of hash sums.
*/
......
......@@ -41,6 +41,14 @@ void Kinematic::unserialize(ElemUtils::Packet& packet) {
BaseObject::unserialize(packet);
}
void Kinematic::serializeIntoStdVector(std::vector<double>& vec) const {
}
void Kinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
}
ChannelType::Type Kinematic::getChannelType() const {
return m_channelType;
}
......
......@@ -167,12 +167,14 @@ std::string ConvolCoeffFunctionKinematic::toString() const {
}
void ConvolCoeffFunctionKinematic::serialize(ElemUtils::Packet& packet) const {
Kinematic::serialize(packet);
packet << m_xi << m_t << m_MuF2 << m_MuR2;
}
void ConvolCoeffFunctionKinematic::unserialize(ElemUtils::Packet& packet) {
Kinematic::unserialize(packet);
packet >> m_xi;
......@@ -181,6 +183,29 @@ void ConvolCoeffFunctionKinematic::unserialize(ElemUtils::Packet& packet) {
packet >> m_MuR2;
}
void ConvolCoeffFunctionKinematic::serializeIntoStdVector(
std::vector<double>& vec) const {
Kinematic::serializeIntoStdVector(vec);
m_xi.serializeIntoStdVector(vec);
m_t.serializeIntoStdVector(vec);
m_MuF2.serializeIntoStdVector(vec);
m_MuR2.serializeIntoStdVector(vec);
}
void ConvolCoeffFunctionKinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
Kinematic::unserializeFromStdVector(it, end);
m_xi.unserializeFromStdVector(it, end);
m_t.unserializeFromStdVector(it, end);
m_MuF2.unserializeFromStdVector(it, end);
m_MuR2.unserializeFromStdVector(it, end);
}
const PhysicalType<double>& ConvolCoeffFunctionKinematic::getMuF2() const {
return m_MuF2;
}
......
......@@ -123,6 +123,25 @@ void DVCSConvolCoeffFunctionKinematic::unserialize(ElemUtils::Packet& packet) {
updateHashSum();
}
void DVCSConvolCoeffFunctionKinematic::serializeIntoStdVector(
std::vector<double>& vec) const {
ConvolCoeffFunctionKinematic::serializeIntoStdVector(vec);
m_Q2.serializeIntoStdVector(vec);
}
void DVCSConvolCoeffFunctionKinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
ConvolCoeffFunctionKinematic::unserializeFromStdVector(it, end);
m_Q2.unserializeFromStdVector(it, end);
updateHashSum();
}
bool DVCSConvolCoeffFunctionKinematic::operator ==(
const DVCSConvolCoeffFunctionKinematic& other) const {
return m_xi == other.getXi() && m_t == other.getT()
......
......@@ -123,6 +123,25 @@ void TCSConvolCoeffFunctionKinematic::unserialize(ElemUtils::Packet& packet) {
updateHashSum();
}
void TCSConvolCoeffFunctionKinematic::serializeIntoStdVector(
std::vector<double>& vec) const {
ConvolCoeffFunctionKinematic::serializeIntoStdVector(vec);
m_Q2Prim.serializeIntoStdVector(vec);
}
void TCSConvolCoeffFunctionKinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
ConvolCoeffFunctionKinematic::unserializeFromStdVector(it, end);
m_Q2Prim.unserializeFromStdVector(it, end);
updateHashSum();
}
bool TCSConvolCoeffFunctionKinematic::operator ==(
const TCSConvolCoeffFunctionKinematic& other) const {
return m_xi == other.getXi() && m_t == other.getT()
......
......@@ -223,6 +223,32 @@ void GPDKinematic::unserialize(ElemUtils::Packet &packet) {
updateHashSum();
}
void GPDKinematic::serializeIntoStdVector(std::vector<double>& vec) const {
Kinematic::serializeIntoStdVector(vec);
m_x.serializeIntoStdVector(vec);
m_xi.serializeIntoStdVector(vec);
m_t.serializeIntoStdVector(vec);
m_MuF2.serializeIntoStdVector(vec);
m_MuR2.serializeIntoStdVector(vec);
}
void GPDKinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
Kinematic::unserializeFromStdVector(it, end);
m_x.unserializeFromStdVector(it, end);
m_xi.unserializeFromStdVector(it, end);
m_t.unserializeFromStdVector(it, end);
m_MuF2.unserializeFromStdVector(it, end);
m_MuR2.unserializeFromStdVector(it, end);
updateHashSum();
}
bool GPDKinematic::operator ==(const GPDKinematic& other) const {
return m_x == other.getX() && m_xi == other.getXi() && m_t == other.getT()
&& m_MuF2 == other.getMuF2() && m_MuR2 == other.getMuR2();
......
......@@ -202,7 +202,7 @@ std::string DVCSObservableKinematic::toString() const {
ElemUtils::Formatter formatter;
formatter << Kinematic::toString() << '\n';
formatter << ObservableKinematic::toString() << '\n';
if (m_xB.isInitialized())
formatter << "xB: " << m_xB.toString() << ' ';
......@@ -220,14 +220,14 @@ std::string DVCSObservableKinematic::toString() const {
void DVCSObservableKinematic::serialize(ElemUtils::Packet &packet) const {
Kinematic::serialize(packet);
ObservableKinematic::serialize(packet);
packet << m_xB << m_t << m_Q2 << m_E << m_phi;
}
void DVCSObservableKinematic::unserialize(ElemUtils::Packet &packet) {
Kinematic::unserialize(packet);
ObservableKinematic::unserialize(packet);
packet >> m_xB;
packet >> m_t;
......@@ -238,6 +238,33 @@ void DVCSObservableKinematic::unserialize(ElemUtils::Packet &packet) {
updateHashSum();
}
void DVCSObservableKinematic::serializeIntoStdVector(
std::vector<double>& vec) const {
ObservableKinematic::serializeIntoStdVector(vec);
m_xB.serializeIntoStdVector(vec);
m_t.serializeIntoStdVector(vec);
m_Q2.serializeIntoStdVector(vec);
m_E.serializeIntoStdVector(vec);
m_phi.serializeIntoStdVector(vec);
}
void DVCSObservableKinematic::unserializeFromStdVector(
std::vector<double>::const_iterator& it,
const std::vector<double>::const_iterator& end) {
ObservableKinematic::unserializeFromStdVector(it, end);
m_xB.unserializeFromStdVector(it, end);
m_t.unserializeFromStdVector(it, end);
m_Q2.unserializeFromStdVector(it, end);
m_E.unserializeFromStdVector(it, end);
m_phi.unserializeFromStdVector(it, end);