21 namespace MD = MultiDimensional;
24 bool shouldCompress,
bool keepErrors)
25 : _indexing{numBins, binEdges, hasUOFlow}, _compressHistograms{shouldCompress}, _keepErrors{keepErrors} {
29 bool shouldCompress,
bool keepErrors)
30 : _indexing{numBins, ranges, hasUOFlow}, _compressHistograms{shouldCompress}, _keepErrors{keepErrors} {
34 : _indexing{binEdges, hasUOFlow}, _compressHistograms{shouldCompress}, _keepErrors{keepErrors} {
49 MSG_WARNING(
"Fixed data already present for label " + to_string(lab) +
". Overwriting. ");
64 vector<pair<MD::SharedTensorData, bool>> pTlist;
65 for(
auto& elem: tensorLabels) {
68 pTlist.push_back({itt->second,
false});
73 pTlist.push_back({itt->second,
true});
76 Tensor t{
"FixedData",move(pTlist)};
77 auto res =
_fixedData.insert({{id, FFscheme}, t});
79 return res.first->second;
82 throw Error(
"Unable to build fixed Data for histogram");
109 const string& name)
const {
110 vector<uint16_t> dims;
113 copy(fullDimensions.begin(), fullDimensions.end(), back_inserter(dims));
114 vector<flatbuffers::Offset<Serial::FBVecDouble>> vecsedges;
116 for (
auto& elem : edges) {
117 auto serialedges1d = msgwriter->CreateVector(elem);
118 Serial::FBVecDoubleBuilder serialBuilder{*msgwriter};
119 serialBuilder.add_value(serialedges1d);
120 vecsedges.push_back(serialBuilder.Finish());
122 vector<int16_t> labels;
124 vector<flatbuffers::Offset<Serial::FBSingleTensor>> vectensor;
127 labels.push_back(static_cast<int16_t>(elem.first));
128 auto res = elem.second->write(msgwriter);
131 auto serialedges = msgwriter->CreateVector(vecsedges);
132 auto serialdims = msgwriter->CreateVector(dims);
133 auto seriallabels = msgwriter->CreateVector(labels);
134 auto serialtensors = msgwriter->CreateVector(vectensor);
135 auto serialname = msgwriter->CreateString(name);
136 Serial::FBHistoDefinitionBuilder serialDefHisto{*msgwriter};
137 serialDefHisto.add_name(serialname);
138 serialDefHisto.add_dims(serialdims);
140 serialDefHisto.add_edges(serialedges);
143 serialDefHisto.add_fixedlabels(seriallabels);
144 serialDefHisto.add_fixeddata(serialtensors);
145 auto out = serialDefHisto.Finish();
146 msgwriter->Finish(out);
151 if (msgreader !=
nullptr) {
153 auto sDims = msgreader->dims();
154 for (
unsigned int j = 0; j < sDims->size(); ++j) {
155 dims.push_back(sDims->Get(j));
158 auto sEdges = msgreader->edges();
159 for (
unsigned int j = 0; j < sEdges->size(); ++j) {
161 auto sEdge = sEdges->Get(j)->value();
162 for (
unsigned int k = 0; k < sEdge->size(); ++k) {
163 edge.push_back(sEdge->Get(k));
165 edges.push_back(edge);
170 auto sLabs = msgreader->fixedlabels();
171 auto sTens = msgreader->fixeddata();
172 for (
unsigned int j = 0; j < sLabs->size(); ++j) {
177 MSG_ERROR(
"Invalid record for histogram definition");
182 if (msgreader !=
nullptr) {
183 auto sDims = msgreader->dims();
187 for (
unsigned int j = 0; j < sDims->size() && result; ++j) {
190 auto sEdges = msgreader->edges();
191 for (
IndexType j = 0; j < sEdges->size() && result; ++j) {
193 auto sEdge = sEdges->Get(j)->value();
194 for (
unsigned int k = 0; k < sEdge->size() && result; ++k) {
195 result &=
isZero(fabs(edge[k] - sEdge->Get(k)));
198 auto sLabs = msgreader->fixedlabels();
199 auto sTens = msgreader->fixeddata();
201 for (
unsigned int j = 0; j < sLabs->size() && result; ++j) {
202 auto it =
_fixedDataPool.find(static_cast<IndexLabel>(sLabs->Get(j)));
206 result &= t.
compare(*(it->second));
std::set< ProcessUID > EventUID
Log & getLog() const
logging facility
const MD::BinnedIndexing< MD::SequentialIndexing > & getIndexing() const
bool compare(const IContainer &other) const override
void setKeepErrors(bool value)
MD::BinnedIndexing< MD::SequentialIndexing > _indexing
void write(flatbuffers::FlatBufferBuilder *msgwriter, const std::string &name) const
Non-sparse tensor data container.
const BinEdgeList & edges() const
get the labels of all the indices at once
std::vector< std::vector< double >> BinEdgeList
const IndexList & dims() const
get the dimensions of all the indices at once
UMap< FixedKey, Tensor > _fixedData
Message logging routines.
bool shouldKeepErrors() const
bool hasUnderOverFlow() const
void read(const Serial::FBHistoDefinition *msgreader)
std::shared_ptr< IContainer > SharedTensorData
static Log & getLog(const std::string &name)
Get a logger with the given name.
size_t rank() const
rank of the tensor
HistogramDefinition(bool hasUnderOverFlow, const IndexList &numBins, const MD::BinEdgeList &binEdges, bool shouldCompress, bool keepErrors)
std::vector< IndexType > IndexList
const BinValue & edge(IndexType pos) const
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
Histogram definition class.
const Tensor & getFixedData(EventUID id, const std::string &schemeName, LabelsList tensorLabels) const
Multidimensional tensor class with complex numbers as elements.
bool isZero(const std::complex< double > val)
bool shouldCompress() const
std::map< IndexLabel, MultiDimensional::SharedTensorData > _fixedDataPool
std::vector< IndexLabel > LabelsList
bool checkDefinition(const Serial::FBHistoDefinition *msgreader) const
std::vector< BinRange > BinRangeList
Serialization related typedefs and includes.
std::vector< double > BinValue
void setCompression(bool value)
void addFixedData(MultiDimensional::SharedTensorData data)