23 ProcResults::ProcResults() {
27 ProcResults::ProcResults(
const Serial::FBProcData* msgreader) {
29 read(msgreader,
false);
35 const Tensor& ProcResults::processAmplitude(
WTerm what)
const {
36 return _processAmplitude.get(what);
40 return _processAmplitude.get(what);
43 const Tensor& ProcResults::processAmplitudeSquared(
WTerm what)
const {
44 return _processSquaredAmplitude.get(what);
48 return _processSquaredAmplitude.get(what);
51 vector<reference_wrapper<const Tensor>> ProcResults::processFormFactors(
const string& name)
const {
52 vector<reference_wrapper<const Tensor>> result;
53 auto it = _processFormFactors.find(name);
54 if (it != _processFormFactors.end()) {
55 transform(it->second.begin(), it->second.end(), back_inserter(result),
56 [](
const Tensor& elem) -> reference_wrapper<const Tensor> {
return cref(elem); });
61 vector<reference_wrapper<Tensor>> ProcResults::processFormFactors(
const string& name) {
62 vector<reference_wrapper<Tensor>> result;
63 auto it = _processFormFactors.find(name);
64 if (it != _processFormFactors.end()) {
65 transform(it->second.begin(), it->second.end(), back_inserter(result),
66 [](
Tensor& elem) -> reference_wrapper<Tensor> {
return ref(elem); });
71 void ProcResults::appendFormFactor(
const std::string& name,
const Tensor& amp) {
72 _processFormFactors[name].push_back(amp);
75 void ProcResults::appendFormFactor(
const std::string& name,
Tensor&& amp) {
76 _processFormFactors[name].push_back(move(amp));
79 void ProcResults::clearFormFactors() {
80 _processFormFactors.clear();
83 bool ProcResults::haveFormFactors()
const {
84 return _processFormFactors.size() > 0;
87 vector<string> ProcResults::availableSchemes()
const {
88 vector<string> result;
89 result.reserve(_processFormFactors.size());
90 transform(_processFormFactors.begin(), _processFormFactors.end(), back_inserter(result), [](
const pair<string, vector<Tensor>>& val) ->
string {
return val.first; });
94 const Tensor& ProcResults::processWeight(
const string& name)
const {
98 Tensor& ProcResults::processWeight(
const string& name) {
102 void ProcResults::setProcessWeight(
const string& name,
const Tensor& amp) {
103 _processWeights[name] = amp;
106 void ProcResults::setProcessWeight(
const string& name,
Tensor&& amp) {
107 _processWeights[name] = move(amp);
110 void ProcResults::clearWeights() {
111 _processWeights.clear();
114 bool ProcResults::haveWeights()
const {
115 return _processWeights.size() > 0;
119 void ProcResults::defineSettings() {
120 setPath(
"ProcessWrite");
121 addSetting<bool>(
"Amplitudes",
true);
122 addSetting<bool>(
"SquaredAmplitudes",
true);
123 addSetting<bool>(
"FormFactors",
true);
127 vector<flatbuffers::Offset<Serial::FBFormFactor>> ffs;
128 vector<flatbuffers::Offset<Serial::FBTensor>> wgtsVals;
129 vector<string> wgtsNames;
130 ffs.reserve(_processFormFactors.size());
131 wgtsVals.reserve(_processWeights.size());
132 wgtsNames.reserve(_processWeights.size());
133 if(isOn(
"FormFactors")) {
134 for (
auto& elem : _processFormFactors) {
135 auto name = msgwriter->CreateString(elem.first);
136 vector<flatbuffers::Offset<Serial::FBTensor>> ffVec;
137 ffVec.reserve(elem.second.size());
138 for (
auto& elem2 : elem.second) {
140 elem2.write(msgwriter, &val);
141 ffVec.push_back(val);
143 auto serialFFVec = msgwriter->CreateVector(ffVec);
144 Serial::FBFormFactorBuilder serialFF{*msgwriter};
145 serialFF.add_id(name);
146 serialFF.add_ffsvals(serialFFVec);
147 auto resFF = serialFF.Finish();
148 ffs.push_back(resFF);
151 for (
auto& elem : _processWeights) {
152 wgtsNames.push_back(elem.first);
154 elem.second.write(msgwriter, &val);
155 wgtsVals.push_back(val);
161 if(isOn(
"Amplitudes")) {
162 _processAmplitude.numerator.write(msgwriter, &num);
163 _processAmplitude.denominator.write(msgwriter, &den);
165 if(isOn(
"SquaredAmplitudes")) {
166 _processSquaredAmplitude.numerator.write(msgwriter, &2num);
167 _processSquaredAmplitude.denominator.write(msgwriter, &2den);
170 if(isOn(
"FormFactors")) {
171 serialFF = msgwriter->CreateVector(ffs);
173 auto serialWgtN = msgwriter->CreateVectorOfStrings(wgtsNames);
174 auto serialWgtV = msgwriter->CreateVector(wgtsVals);
175 Serial::FBProcDataBuilder serialprocess{*msgwriter};
176 if(isOn(
"Amplitudes")) {
177 serialprocess.add_ampnum(ampnum);
178 serialprocess.add_ampden(ampden);
180 if(isOn(
"SquaredAmplitudes")) {
181 serialprocess.add_amp2num(amp2num);
182 serialprocess.add_amp2den(amp2den);
184 if(isOn(
"FormFactors")) {
185 serialprocess.add_formfacts(serialFF);
187 serialprocess.add_weightames(serialWgtN);
188 serialprocess.add_weighvalues(serialWgtV);
189 *msg = serialprocess.Finish();
193 if (msgreader !=
nullptr) {
195 if(!merge && flatbuffers::IsFieldPresent(msgreader, Serial::FBProcData::VT_AMPNUM)) {
196 _processAmplitude.numerator.read(msgreader->ampnum());
197 _processAmplitude.denominator.read(msgreader->ampden());
199 if(!merge && flatbuffers::IsFieldPresent(msgreader, Serial::FBProcData::VT_AMP2NUM)) {
200 _processSquaredAmplitude.numerator.read(msgreader->amp2num());
201 _processSquaredAmplitude.denominator.read(msgreader->amp2den());
203 if(flatbuffers::IsFieldPresent(msgreader, Serial::FBProcData::VT_FORMFACTS)) {
204 auto formfacts = msgreader->formfacts();
206 _processFormFactors.clear();
208 for (
unsigned int i = 0; i < formfacts->size() && result; ++i) {
209 auto elem = formfacts->Get(i);
210 auto it = _processFormFactors.find(elem->id()->c_str());
211 if(it != _processFormFactors.end() && strcmp(elem->id()->c_str(),
"Denominator") != 0) {
212 MSG_ERROR(
"Try to merge two process form factor schemes with same name '" +
string(elem->id()->c_str()) +
216 auto res = _processFormFactors.insert({elem->id()->c_str(), vector<Tensor>{}});
217 auto ffVec = elem->ffsvals();
218 for (
unsigned int j = 0; j < ffVec->size(); ++j) {
219 auto elem2 = ffVec->Get(j);
222 res.first->second.push_back(move(t));
227 auto wName = msgreader->weightames();
228 auto wVal = msgreader->weighvalues();
230 _processWeights.clear();
232 for (
unsigned int i = 0; i < wName->size() && result; ++i) {
233 auto it = _processWeights.find(wName->Get(i)->c_str());
234 if(it != _processWeights.end()) {
235 MSG_ERROR(
"Try to merge two process weights with same name '" +
string(wName->Get(i)->c_str()) +
"'!");
240 t.
read(wVal->Get(i));
241 _processWeights.insert({wName->Get(i)->c_str(), t});
249 Log& ProcResults::getLog()
const {
250 return Log::getLog(
"Hammer.ProcResults");
auto const & getOrThrow(const std::map< KeyType, ValueType > &data, KeyType key, std::exception error)
TensorData read(const Serial::FBTensor *msgreader)
Message logging routines.
Container for process-related results of weight calculation.
Multidimensional tensor class with complex numbers as elements.
void read(const Serial::FBTensor *msgreader)
read the contents of the tensor for serialization
Out-of-range error class.
Serialization related typedefs and includes.