14 #include <boost/algorithm/string.hpp>
16 #include "yaml-cpp/yaml.h"
31 Log& ProcessDefinitions::getLog()
const {
32 return Log::getLog(
"Hammer.ProcessDefinitions");
35 void ProcessDefinitions::write(flatbuffers::FlatBufferBuilder* msgwriter,
37 vector<flatbuffers::Offset<Serial::FBVecString>> includes;
38 vector<flatbuffers::Offset<Serial::FBVecString>> forbids;
39 for(
auto& elem: _includedDecays) {
40 auto serialvals = msgwriter->CreateVectorOfStrings(elem);
41 Serial::FBVecStringBuilder serialBuilder{*msgwriter};
42 serialBuilder.add_value(serialvals);
43 includes.push_back(serialBuilder.Finish());
45 for(
auto& elem: _forbiddenDecays) {
46 auto serialvals = msgwriter->CreateVectorOfStrings(elem);
47 Serial::FBVecStringBuilder serialBuilder{*msgwriter};
48 serialBuilder.add_value(serialvals);
49 includes.push_back(serialBuilder.Finish());
51 vector<flatbuffers::Offset<Serial::FBIdSet>> includeprocsvals;
52 vector<uint64_t> includeprocskeys;
53 includeprocsvals.reserve(_includedProcesses.size());
54 includeprocskeys.reserve(_includedProcesses.size());
55 for(
auto& elem: _includedProcesses) {
56 includeprocskeys.push_back(elem.first);
58 ids.reserve(elem.second.size());
59 copy(elem.second.begin(),elem.second.end(), back_inserter(ids));
60 auto serialid = msgwriter->CreateVector(ids);
61 Serial::FBIdSetBuilder serialBuilder{*msgwriter};
62 serialBuilder.add_ids(serialid);
63 includeprocsvals.push_back(serialBuilder.Finish());
65 vector<uint64_t> forbidprocids;
66 forbidprocids.reserve(_forbiddenProcesses.size());
67 copy(_forbiddenProcesses.begin(),_forbiddenProcesses.end(), back_inserter(forbidprocids));
68 auto serialid = msgwriter->CreateVector(forbidprocids);
69 Serial::FBIdSetBuilder serialBuilder{*msgwriter};
70 serialBuilder.add_ids(serialid);
71 auto serialforbidprocs = serialBuilder.Finish();
72 auto serialincludes = msgwriter->CreateVector(includes);
73 auto serialforbids = msgwriter->CreateVector(forbids);
74 auto serialincludprocsvals = msgwriter->CreateVector(includeprocsvals);
75 auto serialincludprocskeys = msgwriter->CreateVector(includeprocskeys);
76 Serial::FBProcDefsBuilder builder{*msgwriter};
77 builder.add_includenames(serialincludes);
78 builder.add_forbidnames(serialforbids);
79 builder.add_includeprocsverts(serialincludprocsvals);
80 builder.add_includeprocsid(serialincludprocskeys);
81 builder.add_forbidprocs(serialforbidprocs);
82 *procdefs = builder.Finish();
86 if (msgreader !=
nullptr) {
87 auto includenames = msgreader->includenames();
88 _includedDecays.clear();
90 _includedDecays.reserve(includenames->size());
91 for (
unsigned int i = 0; i < includenames->size(); ++i) {
92 auto vecstr = includenames->Get(i)->value();
94 tmp.reserve(vecstr->size());
95 for (
unsigned int j = 0; j < vecstr->size(); ++j) {
96 tmp.push_back(vecstr->Get(j)->c_str());
98 _includedDecays.push_back(tmp);
101 auto forbidnames = msgreader->forbidnames();
102 _forbiddenDecays.clear();
104 _forbiddenDecays.reserve(forbidnames->size());
105 for (
unsigned int i = 0; i < forbidnames->size(); ++i) {
106 auto vecstr = forbidnames->Get(i)->value();
108 tmp.reserve(vecstr->size());
109 for (
unsigned int j = 0; j < vecstr->size(); ++j) {
110 tmp.push_back(vecstr->Get(j)->c_str());
112 _forbiddenDecays.push_back(tmp);
115 auto includeprocsverts = msgreader->includeprocsverts();
116 auto includeprocsid = msgreader->includeprocsid();
117 _includedProcesses.clear();
119 for (
unsigned int i = 0; i < includeprocsid->size(); ++i) {
121 auto idset = includeprocsverts->Get(i)->ids();
122 for (
unsigned int j = 0; j < idset->size(); ++j) {
123 tmp.insert(idset->Get(j));
125 _includedProcesses[includeprocsid->Get(i)] = tmp;
128 _forbiddenProcesses.clear();
129 auto forbidprocs = msgreader->forbidprocs()->ids();
131 for (
unsigned int j = 0; j < forbidprocs->size(); ++j) {
132 _forbiddenProcesses.insert(forbidprocs->Get(j));
140 void ProcessDefinitions::addIncludedDecay(
const vector<string>& decay) {
141 _includedDecays.push_back(decay);
144 void ProcessDefinitions::addForbiddenDecay(
const vector<string>& decay) {
145 _forbiddenDecays.push_back(decay);
148 vector<set<HashId>> ProcessDefinitions::includedDecaySignatures()
const {
149 return decaySignatures(_includedDecays);
152 vector<set<HashId>> ProcessDefinitions::forbiddenDecaySignatures()
const {
153 return decaySignatures(_forbiddenDecays);
156 vector<set<HashId>> ProcessDefinitions::decaySignatures(
const vector<vector<string>>& container)
const {
157 vector<set<HashId>> result;
158 PID& pdg = PID::instance();
159 for(
auto& elem: container) {
160 vector<set<HashId>> accum;
161 for(
auto& elem2: elem) {
163 if(temp.size() == 0) {
167 if(accum.size() == 0) {
169 accum.push_back({
id});
173 vector<set<HashId>> tempprod(accum.size() * temp.size());
174 for(
size_t i = 0; i< accum.size(); ++i) {
175 for(
size_t j = 0; j< temp.size(); ++j) {
176 tempprod[i * temp.size() + j] = accum[i];
177 tempprod[i * temp.size() + j].insert(temp[j]);
180 accum.swap(tempprod);
183 result.insert(result.end(), accum.begin(),accum.end());
188 bool ProcessDefinitions::isProcessIncluded(set<HashId> subamplitudes,
HashId processId)
const {
189 if (_includedDecayCombos.size() == 0) {
192 if (_includedProcesses.find(processId) != _includedProcesses.end()) {
195 if (_forbiddenProcesses.find(processId) != _forbiddenProcesses.end()) {
198 bool included =
false;
199 for (
auto& elem : _includedDecayCombos) {
200 if (includes(subamplitudes.begin(), subamplitudes.end(), elem.begin(), elem.end())) {
206 _includedProcesses.insert(make_pair(processId, subamplitudes));
209 _forbiddenProcesses.insert(processId);
214 set<HashId> ProcessDefinitions::decayStringsToProcessIds(
const vector<vector<string>>& names)
const {
216 auto subamplitudes = decaySignatures(names);
217 for (
auto& elem : subamplitudes) {
218 for (
auto& elem2 : _includedProcesses) {
219 if (includes(elem2.second.begin(), elem2.second.end(), elem.begin(), elem.end())) {
220 results.insert(elem2.first);
227 void ProcessDefinitions::forbidProcess(
HashId processId)
const {
228 _forbiddenProcesses.insert(processId);
229 _includedProcesses.erase(processId);
232 void ProcessDefinitions::init() {
233 _includedDecayCombos = includedDecaySignatures();
234 _includedProcesses.clear();
235 _forbiddenProcesses.clear();
239 out << YAML::convert<ProcessDefinitions>::encode(s);
247 Node convert<::Hammer::ProcessDefinitions>::encode(const ::Hammer::ProcessDefinitions& value) {
249 if (value._includedDecays.size() > 0) {
251 for (
auto& elem : value._includedDecays) {
252 if (elem.size() == 1) {
253 tmpNode.push_back(elem[0]);
256 for (
auto& elem2 : elem) {
257 tmpNode2.push_back(elem2);
259 tmpNode.push_back(tmpNode2);
262 node[
"Include"] = tmpNode;
264 if (value._forbiddenDecays.size() > 0) {
266 for (
auto& elem : value._forbiddenDecays) {
267 if (elem.size() == 1) {
268 tmpNode.push_back(elem[0]);
271 for (
auto& elem2 : elem) {
272 tmpNode2.push_back(elem2);
274 tmpNode.push_back(tmpNode2);
277 node[
"Forbid"] = tmpNode;
284 for (
auto entry : node) {
285 string base = entry.first.as<
string>();
286 if (base ==
"Include" || base ==
"Forbid") {
289 if (entry.second.Type() == YAML::NodeType::Sequence) {
290 YAML::Node seqgroup = entry.second;
291 for (
auto elem : seqgroup) {
292 if (elem.Type() == YAML::NodeType::Scalar) {
293 container->push_back({elem.as<
string>()});
294 }
else if (elem.Type() == YAML::NodeType::Sequence) {
296 vector<string> tmpvec = elem.as<vector<string>>();
297 container->push_back(tmpvec);
298 }
catch (YAML::Exception&) {
PDG codes to UID functions.
TensorData read(const Serial::FBTensor *msgreader)
YAML::Emitter & operator<<(YAML::Emitter &out, const ProcessDefinitions &s)
std::vector< HashId > expandToValidVertexUIDs(const std::string &name, const bool &hadOnly=false) const
std::vector< std::vector< std::string > > _forbiddenDecays
the Hammer forbidden decays
Container class for storing included/forbidden process info.
Hammer exception definitions.
std::vector< std::vector< std::string > > _includedDecays
the Hammer included decays
Hammer settings manager class.
Hammer class for dealing with particle data.
Hammer particle data class.
Serialization related typedefs and includes.