File indexing completed on 2026-06-02 08:51:48
0001 #ifndef OBSERVABLE_H
0002 #define OBSERVABLE_H
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <ElementaryUtils/logger/CustomException.h>
0012 #include <ElementaryUtils/parameters/Parameters.h>
0013 #include <stddef.h>
0014 #include <iterator>
0015 #include <map>
0016 #include <string>
0017 #include <vector>
0018
0019 #include "../../beans/automation/BaseObjectData.h"
0020 #include "../../beans/channel/ChannelType.h"
0021 #include "../../beans/gpd/GPDType.h"
0022 #include "../../beans/List.h"
0023 #include "../../ModuleObject.h"
0024 #include "../../utils/type/PhysicalType.h"
0025
0026 namespace PARTONS {
0027
0028
0029
0030
0031
0032
0033 template<typename KinematicType, typename ResultType>
0034 class Observable: public ModuleObject {
0035
0036 public:
0037
0038
0039
0040
0041 virtual ~Observable() {
0042 }
0043
0044 virtual Observable* clone() const = 0;
0045
0046 virtual std::string toString() const {
0047 return ModuleObject::toString();
0048 }
0049
0050 virtual void resolveObjectDependencies() {
0051 ModuleObject::resolveObjectDependencies();
0052 }
0053
0054 virtual void run() {
0055 throw ElemUtils::CustomException(getClassName(), __func__,
0056 "This must be implemented in daughter class");
0057 }
0058
0059 virtual void configure(const ElemUtils::Parameters ¶meters) {
0060 ModuleObject::configure(parameters);
0061 }
0062
0063 virtual void prepareSubModules(
0064 const std::map<std::string, BaseObjectData>& subModulesData) {
0065 ModuleObject::prepareSubModules(subModulesData);
0066 }
0067
0068
0069
0070
0071
0072
0073
0074 virtual ResultType compute(const KinematicType& kinematic,
0075 const List<GPDType> & gpdType = List<GPDType>()) = 0;
0076
0077
0078
0079
0080
0081 virtual List<GPDType> getListOfAvailableGPDTypeForComputation() const = 0;
0082
0083 protected:
0084
0085
0086
0087
0088
0089
0090
0091
0092 Observable(const std::string &className, ChannelType::Type channelType) :
0093 ModuleObject(className, channelType) {
0094 }
0095
0096
0097
0098
0099
0100 Observable(const Observable& other) :
0101 ModuleObject(other) {
0102 }
0103
0104 virtual void initModule() {
0105 }
0106
0107 virtual void isModuleWellConfigured() {
0108 }
0109
0110
0111
0112
0113 virtual PhysicalType<double> computeObservable(
0114 const KinematicType& kinematic, const List<GPDType>& gpdType) = 0;
0115
0116
0117
0118
0119 std::vector<double> serializeKinematicsAndGPDTypesIntoStdVector(
0120 const KinematicType& kin, const List<GPDType>& list) const {
0121
0122 std::vector<double> result;
0123
0124 kin.serializeIntoStdVector(result);
0125
0126 for (size_t i = 0; i < list.size(); i++) {
0127 result.push_back(static_cast<double>(list[i].getType()));
0128 }
0129
0130 return result;
0131 }
0132
0133
0134
0135
0136 void unserializeKinematicsAndGPDTypesFromStdVector(
0137 const std::vector<double>& vec, KinematicType& kin,
0138 List<GPDType>& list) const {
0139
0140 std::vector<double>::const_iterator it = vec.begin();
0141
0142 kin.unserializeFromStdVector(it, vec.end());
0143
0144 list.clear();
0145
0146 for (; it != vec.end(); it++) {
0147 list.add(GPDType(static_cast<GPDType::Type>(*it)));
0148 }
0149 }
0150
0151 };
0152
0153 }
0154
0155 #endif