9 #ifndef __RESULTCONTAINER__
10 #define __RESULTCONTAINER__
22 #include <QtCore/QReadWriteLock>
29 template<
typename T>
struct Axis;
45 serializer.add(axis.nBins);
46 serializer.add(axis.low);
47 serializer.add(axis.up);
48 serializer.add(axis.title);
63 uint16_t version(serializer.
retrieve<uint16_t>());
65 throw std::runtime_error(
"operator>>(serializer,Axis<T>): Version conflict");
88 serializer.
add(result.
_id);
90 serializer.
add(static_cast<size_t>(result.
_axis.size()));
93 serializer.
add(static_cast<size_t>(result.
_storage.size()));
109 template <
typename T>
113 uint16_t version(serializer.
retrieve<uint16_t>());
115 throw std::runtime_error(
"operator>>(serializer,Result<T>): Version conflict");
123 for (
size_t i(0); i <
size; ++i)
128 namespace histogramming
142 template <
typename AxisPrecessionType,
typename ResultValueType>
145 const int xBin(xaxis.
bin(value));
166 template <
typename AxisPrecessionType,
typename coordinate_t>
169 const coordinate_t &coordinate)
172 const int xBin(xAxis.
bin(coordinate.first));
173 const int yBin(yAxis.
bin(coordinate.second));
177 const bool xInRange(!xUnderflow && !xOverflow);
180 const bool yInRange(!yUnderflow && !yOverflow);
181 if (xUnderflow && yUnderflow)
182 return maxSize+result_t::LowerLeft;
183 else if (xUnderflow && yOverflow)
184 return maxSize+result_t::UpperRight;
185 else if (xUnderflow && yOverflow)
186 return maxSize+result_t::UpperLeft;
187 else if (xOverflow && yUnderflow)
188 return maxSize+result_t::LowerRight;
189 else if (xInRange && yUnderflow)
190 return maxSize+result_t::LowerMiddle;
191 else if (xInRange && yOverflow)
192 return maxSize+result_t::UpperMiddle;
193 else if (xUnderflow && yInRange)
194 return maxSize+result_t::Left;
195 else if (xOverflow && yInRange)
196 return maxSize+result_t::Right;
198 return yBin*xAxis.
nBins + xBin;
235 Axis(
size_t nbrBins, value_t lowerLimit, value_t upperLimit, std::string
title=
"Axis Title")
259 int bin(
const value_t &val)
const
261 if (!std::isfinite(val))
283 return (static_cast<int>(
nBins) <= bin);
312 template <
typename T>
350 typedef std::pair<size_type,size_type>
shape_t;
420 Result(
const size_type& cols,
const size_type& rows)
437 Result(
const axe_t& xaxis,
const axe_t& yaxis)
473 if (static_cast<int>(
_axis.size()) <= axis)
474 throw std::invalid_argument(
"Result::axis: the requested axis does not exist");
489 if (static_cast<int>(
_axis.size()) <= axis)
490 throw std::invalid_argument(
"Result::axis: the requested axis does not exist");
547 throw std::logic_error(
"Result::setValue: Try using the result as a value, but it has axis");
562 throw std::logic_error(
"Result::getValue: Try using the result as a value, but it has axis");
581 throw std::logic_error(
"Result::isTrue: Try using the result as a value, but it has axis");
583 return !(std::abs(
_storage.front()) < std::sqrt(std::numeric_limits<value_t>::epsilon()));
651 iterator
histogram(
const value_t& pos,
const value_t& weight=1)
654 if (
_axis.size() != 1)
655 throw std::logic_error(
"Result::histogram(pos): Result doesn't have dimension 1");
660 if (histbin >=
size())
662 std::cout << std:: boolalpha<<
666 axis(xAxis).bin(pos)<<
" " <<
667 "xOverflow:"<<
axis(xAxis).isOverflow(
axis(xAxis).
bin(pos))<<
" " <<
668 "xUnderflow:"<<
axis(xAxis).isUnderflow(
axis(xAxis).
bin(pos))<<
" " <<
670 throw std::out_of_range(
"Result::histogram(pos): calculated bin isn't within the size of the storage");
673 iterator it(
begin() + histbin);
689 iterator
histogram(
const coordinate_t& pos,
const value_t& weight=1)
692 if (
_axis.size() != 2)
693 throw std::logic_error(
"Result::histogram(coordinate): Result doesn't have dimension 2");
697 if (histbin >=
size())
699 std::cout << std:: boolalpha<<
702 pos.first <<
"x"<<pos.second <<
" " <<
703 axis(xAxis).bin(pos.first)<<
" " <<
704 axis(yAxis).bin(pos.second)<<
" " <<
705 "xOverflow:"<<
axis(xAxis).isOverflow(
axis(xAxis).
bin(pos.first))<<
" " <<
706 "xUnderflow:"<<
axis(xAxis).isUnderflow(
axis(xAxis).
bin(pos.first))<<
" " <<
707 "yOverflow:"<<
axis(yAxis).isOverflow(
axis(yAxis).
bin(pos.second))<<
" " <<
708 "yUnderflow:"<<
axis(yAxis).isUnderflow(
axis(yAxis).
bin(pos.second))<<
" " <<
710 throw std::out_of_range(
"Result::histogram(coordinate): calculated bin isn't within the size of the storage");
713 iterator it(
begin() + histbin);
727 if (
_axis.size() != 2)
728 throw std::logic_error(
"Result::appendRows(): Result doesn't have dimension 2");
730 throw std::runtime_error(
"Result::appendRows: The rowsize is not a modulo of the rowsize of the table '");
732 const int nRows(rows.size() /
_axis[
xAxis].nBins);
743 if (
_axis.size() != 2)
744 throw std::logic_error(
"Result::resetTable(): Result doesn't have dimension 2");
759 if (
_axis.size() != 1)
760 throw std::logic_error(
"Result::push_back(): Result doesn't have dimension 1");
774 if (
_axis.size() != 1)
775 throw std::logic_error(
"Result::reset(): Result doesn't have dimension 1");
813 switch (
_axis.size())
816 return std::make_pair(1,1);
819 return std::make_pair(
axis(
xAxis).nBins,1);
825 throw std::logic_error(
"Result::shape(): Result doesn't have dimension 2");
844 switch (
_axis.size())
847 return std::vector<size_t>(1,1);
850 return std::vector<size_t>(1,
axis(
xAxis).nBins);
854 std::vector<size_t> s(2);
861 throw std::logic_error(
"Result::shape(): Result doesn't have dimension 2");
892 shared_pointer sp(
new self_type);
std::vector< axe_t > axis_t
the axis descriptions of this container
storage_t::const_iterator const_iterator
a const iterator on the storage
size_t dim() const
what is the dimension of the result
void clear()
clear the contents of the result
axis_name
which axis one wants to have
iterator histogram(const coordinate_t &pos, const value_t &weight=1)
add the weight at the right bin for the coordinate in the 2d array
reference front()
retrieve reference to the first element
void appendRows(const storage_t &rows)
add row(s) to the result
value_t getValue() const
return the value
Result(const axe_t &xaxis)
1d histogram constructor
storage_t _storage
result storage
const_iterator end() const
retrieve iterator to the end of storage
storage_t::reference reference
a reference to the storage
Axis()
default Constructor
std::string _name
the name of this result
void reset()
clear the appendable 1d like result
void name(const std::string &name)
set the name of the result
const_reference operator[](size_type pos) const
enable accessing elements of the storage directly
std::vector< value_t > storage_t
the storage of this container
int bin(const value_t &val) const
return the bin that a value will fall in
value_t pos(const int bin) const
calculate the position for a given bin
size_t bin(const Axis< AxisPrecessionType > &xAxis, const Axis< AxisPrecessionType > &yAxis, const coordinate_t &coordinate)
calculate the corresponding index in the linearized array of a coordinate
T value_t
the values of this container
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
std::pair< size_type, size_type > shape_t
define the shape of the result
void assign(const self_type &in)
copy the contents of a different result to this result
size_type size() const
return the raw size of the storage
std::string name() const
retrieve the name of the result
an axis of a more than 0 dimensional container
std::string title
the title of the axis
void resetTable()
reset the table like result
size_t bin(const Axis< AxisPrecessionType > &xaxis, const ResultValueType &value)
calculate the index of the lineared array
things written only at end of run H5Dump ProcessorSummary size
size_t nBins
the number of bins in this axis
Axis< double > axe_t
the axis descriptions of this container
uint64_t id() const
retrieve the id of the result
storage_t::size_type size_type
define the size type of the storage
axis_t & axis()
write access to the axis
void setValue(const_reference value)
assign the result container to a value
const_iterator begin() const
retrieve a iterator for read access to beginning
bool isUnderflow(int bin) const
check if a bin is an underflow
storage_t::const_reference const_reference
a const reference to the storage
Result()
default constructor
bool isTrue() const
evaluate whether value is zero
Result(const axe_t &xaxis, const axe_t &yaxis)
2d histogram constructor
shared_pointer clone() const
create a copy of the result
const_reference front() const
retrieve const reference to the first element
self_type & operator=(const self_type &)
prevent self assigment
const axis_t & axis() const
read access to the axis
Result(const size_type &size)
1d array container constructor
file contains base class all serializable classes
storage_t & storage()
write access to the storage
iterator end()
retrieve iterator to the end of storage
QReadWriteLock lock
lock for locking operations on the data of the container
Result(const size_type &cols, const size_type &rows)
2d array container or table constructor
axis_t _axis
the axis of the histogram
void append(const value_t &val)
append a value to the end of the result
void id(uint64_t id)
set the id of the result
bool isOverflow(int bin) const
check if a bin is an overflow
SerializerBackend & operator<<(SerializerBackend &serializer, const Axis< T > &axis)
add an Axis to a stream
storage_t::iterator iterator
a iterator on the storage
value_t low
lower end of the axis
SerializerBackend & operator>>(SerializerBackend &serializer, Axis< T > &axis)
read an Axis from a stream
iterator begin()
retrieve iterator for write access to beginning
value_t up
upper end of the axis
std::vector< size_t > np_shape() const
return the shape of the result as numpy / hdf5 shape
uint64_t _id
the id of the event that the contents reflect
const axe_t & axis(const axis_name &axis) const
read access to a specific axis
iterator histogram(const value_t &pos, const value_t &weight=1)
add the weight at the right bin for the value in the 1d array
Axis(size_t nbrBins, value_t lowerLimit, value_t upperLimit, std::string title="Axis Title")
Constructor.
Type retrieve()
read arbitrary value from stream
OverUnderFlow
the over/underflow bin of 1d histogram
const storage_t & storage() const
read access to the storage
shape_t shape() const
return the shape of the result
Quadrant
over/ underflow of 2d histogram
Result(const Result &in)
copy constructor
check if there is some light in the chamber based upon the GMD value
size_type datasize() const
return the size of the data as determined by the axis
void add(const Type &value)
add arbitrary value to the stream
std::pair< double, double > coordinate_t
a coordinate of a 2d array
reference operator[](size_type pos)
enable accessing elements of the storage directly
axe_t & axis(const axis_name &axis)
write accesss to a specific axis
Result< T > self_type
this classes type
T value_t
the presision type of the axis boundaries