26 HistogramSet::HistogramSet(
bool compressed) : _isCompressed{compressed} {
31 _compressionReverseDict{other._compressionReverseDict},
32 _labelsDict{other._labelsDict},
33 _labelsReverseDict{other._labelsReverseDict},
34 _isCompressed{other._isCompressed} {
35 transform(other._data.begin(), other._data.end(), back_inserter(_data),
36 [&](
const unique_ptr<Histogram>& original) -> unique_ptr<Histogram> {
37 return original->collapseIntoNew(newName, newDef, collapsedIndexPositions);
44 return _data[it->second].get();
52 if(
id <
_data.size()) {
53 return _data[id].get();
62 sort(tmpLabels.begin(), tmpLabels.end());
67 size_t pos =
_data.size();
88 if(
id ==
_data.size()) {
89 _data.push_back(move(hist));
91 return _data[id].get();
103 auto idsets = msgreader->idset()->evtids();
104 vector<EventUID> keys;
105 keys.reserve(idsets->size());
106 for (
unsigned int i = 0; i < idsets->size(); ++i) {
107 auto procids = idsets->Get(i)->ids();
109 for (
unsigned int j = 0; j < procids->size(); ++j) {
110 key.insert(procids->Get(j));
114 size_t newK =
_data.size();
116 auto itNewKeys = partition(keys.begin(), keys.end(), [&](
const EventUID& elem) ->
bool {
auto it =
_compressionDict.find(elem);
118 candKs.insert(it->second);
122 if(candKs.size() > 1) {
123 throw Error(
"Event ID grouping in Histogram merging is not consistent.\n"
124 "Mahna Mahna\nDo doo be-do-do\nMahna Mahna\nDo do-do do\n"
125 "Mahna Mahna\nDo doo be-do-do be-do-do be-do-do be-do-do-doodle do do do-doo do!");
128 if(candKs.size() > 0) {
129 newK = *candKs.begin();
135 for(
auto it = itNewKeys; it != keys.end(); ++it) {
137 itCompRev->second.insert(*it);
139 if (newK ==
_data.size()) {
140 auto idlabels = msgreader->idset()->labels();
142 for (
unsigned int l = 0; l < idlabels->size(); ++l) {
143 labels.push_back(static_cast<IndexLabel>(idlabels->Get(l)));
150 _data.back()->read(msgreader, def);
155 h.
read(msgreader, def);
160 _data[newK]->read(msgreader, def);
171 vector<flatbuffers::Offset<Serial::FBIdSet>> serialEvtIds;
172 for(
auto& elem: evtids) {
173 vector<uint64_t> procids;
174 procids.reserve(elem.size());
175 copy(elem.begin(), elem.end(), back_inserter(procids));
176 auto serialProcids = msgwriter->CreateVector(procids);
177 Serial::FBIdSetBuilder serialEventId{*msgwriter};
178 serialEventId.add_ids(serialProcids);
179 auto key = serialEventId.Finish();
180 serialEvtIds.push_back(key);
182 auto serialIds = msgwriter->CreateVector(serialEvtIds);
183 auto& evtLabels =
_labelsDict.find(it->second)->second;
184 vector<int16_t> labels;
185 for (
auto elem : evtLabels) {
186 labels.push_back(static_cast<int16_t>(elem));
188 auto serialLabels = msgwriter->CreateVector(labels);
189 Serial::FBEvtIdSetBuilder serialEventIdSet{*msgwriter};
190 serialEventIdSet.add_evtids(serialIds);
191 serialEventIdSet.add_labels(serialLabels);
192 auto idset = serialEventIdSet.Finish();
193 auto hbuilder =
_data[it->second]->write(msgwriter);
194 hbuilder->add_idset(idset);
212 vector<IOHistogram> iodata;
213 for(
size_t i = 0; i <
_data.size(); ++i) {
215 result.emplace(it->second,
_data[i]->evalToList(externalData[i]));
221 if(
_data.size() == 0) {
225 for(
size_t i = 1; i <
_data.size(); ++i) {
226 auto result_temp =
_data[i]->evalToList(externalData[i]);
227 transform(result.begin(), result.end(), result_temp.begin(), result.begin(), plus<BinContents>()); }
234 result.insert(elem.first);
241 vector<LabelsList> result;
248 vector<EventUID> result;
std::set< ProcessUID > EventUID
Multidimensional histogram class with Tensor as cell bins.
size_t addEventId(const EventUID &id, const LabelsList &labels)
std::vector< BinContents > IOHistogram
EventUIDGroup read(const Serial::FBHistogram *msgreader, const HistogramDefinition &def, bool merge)
std::set< EventUID > EventUIDGroup
Container class for histograms belonging to different event types.
Histogram * getHistogram(const EventUID &id)
std::vector< std::unique_ptr< Histogram > > _data
std::vector< LabelsList > getHistogramLabels() const
EventIdGroupDict< IOHistogram > specializeEventHistograms(const std::vector< Tensor > &externalData) const
std::unique_ptr< Serial::FBHistogramBuilder > write(flatbuffers::FlatBufferBuilder *msgwriter, const EventUID &id) const
UMap< LabelsList, size_t > _labelsReverseDict
EventUIDGroup getEventIdsInHistogram() const
EventIdDict< size_t > _compressionDict
std::map< size_t, LabelsList > _labelsDict
UMap< EventUIDGroup, T > EventIdGroupDict
Histogram definition class.
HistogramSet(bool compressed=false)
IOHistogram specializeSumHistogram(const std::vector< Tensor > &externalData) const
contents of a histogram bin after full contraction (real weights) to be used to export the histogram ...
std::map< size_t, EventUIDGroup > _compressionReverseDict
std::vector< IndexLabel > LabelsList
void read(const Serial::FBHistogram *msgreader, const HistogramDefinition &def)
read the contents of the histogram for serialization
std::vector< EventUID > getEventUIDRepresentatives() const
double sumWi
sum of weights
double sumWi2
sum of squared weights
Histogram operator+(const Histogram &first, const Histogram &second)
Serialization related typedefs and includes.
Histogram * addHistogram(size_t id, std::unique_ptr< Histogram > hist)