34 template <
typename CONT>
36 out <<
"(" << sv.size() <<
") {";
38 return out <<
" }" << std::flush;
43 template <
typename CONT>
45 std::ostringstream sstr;
56 out <<
"(" << sv.
size() <<
") [" << sv.
get_ranges().size() <<
"] {";
59 while (i++ < range.begin_index())
64 i += range.size() - 1;
66 while (i++ < sv.
size())
68 return out <<
" }" << std::flush;
127 if (ranges.empty()) {
132 auto iNext = ranges.cbegin(), rend = ranges.cend();
133 while (iNext != rend) {
134 auto iRange = iNext++;
135 if (iRange->empty()) {
136 out <<
"[range " << i <<
" is empty]" << std::endl;
140 if (!(*iRange < *iNext)) {
141 out <<
"[range " << i <<
" comes after range " << (i+1) <<
"]"
145 if (!iRange->separate(*iNext)) {
146 out <<
"[range " << i <<
" is overlapping or adjacent to "
147 << (i+1) <<
"]" << std::endl;
153 if (sv.
size() < ranges.back().end_index()) {
154 out <<
"[size is " << sv.
size() <<
", it should be at least "
155 << ranges.back().end_index() <<
"]" << std::endl;
166 unsigned int local_errors = 0;
169 out <<
"*** Mismatch: " << std::string(58,
'*') << std::endl;
172 out << std::string(72,
'*') << std::endl;
202 unsigned int errors =
check();
210 failures.emplace_back(*
this, action, actual_errors);
214 out <<
" *** recovery from error failed ***" << std::endl;
238 out <<
" successfully." << std::endl;
241 out <<
", " <<
nErrors <<
" unexpected errors occurred in "
242 <<
failures.size() <<
" of them:" << std::endl;
244 out <<
" [" <<
info.nAction <<
"] " <<
info.description
245 <<
" => " <<
info.nErrors <<
" errors" << std::endl;
273 template <
typename T>
302 { std::ostringstream sstr;
describe(tc, sstr);
return sstr.str(); }
314 { out <<
"no action"; }
319 template <
typename ITER>
321 template <
typename ITER>
323 template <
typename ITER>
325 template <
typename ITER>
327 template <
typename Vector>
330 if ((pos>= v.size()) ||
isVoid(v[pos]))
331 return std::make_pair(v.end(), v.end());
332 auto rbegin =
rangeStart(v.begin(), v.begin() + pos);
334 return std::make_pair(rbegin, rend);
339 template <
typename ITER>
341 (
Vector_t const& v, std::size_t i, ITER start);
342 template <
typename ITER>
348 template <
typename ITER>
356 template <
typename T>
367 { out <<
"print the vectors"; }
374 template <
typename Vector>
379 template <
typename T>
390 { out <<
"print the sparse vector"; }
398 template <
typename T>
413 { out <<
"print the range at position " <<
position; }
420 << v[
position] <<
" is within range " << range_str
423 catch (std::out_of_range
const&) {
430 template <
typename T>
441 { out <<
"print the elements which are not in the void"; }
447 std::cout <<
"Non-zero elements in vector: "
448 << (v.size() - std::count_if
454 std::cout <<
"Non-void elements in sparse vector: "
455 << v.
count() << std::endl;
461 template <
typename T>
473 { out <<
"clear the vectors"; }
480 template <
typename Vector>
486 template <
typename T>
502 { out <<
"resize to " <<
size <<
" elements"; }
509 template <
typename Vector>
515 template <
typename T>
525 { out <<
"truncate to " <<
Base_t::size <<
" elements"; }
530 template <
typename T>
546 { out <<
"resize to " <<
size <<
" elements, filling with " <<
value; }
553 template <
typename Vector>
559 template <
typename T>
585 template <
typename Vector>
591 template <
typename T>
614 v.
assign(std::move(local));
621 out <<
" into the vector";
627 template <
typename T>
644 size_t max_size = std::max(v.size(),
position +
data.size());
645 v.resize(max_size, 0);
653 out <<
"add data vector ";
655 out <<
" starting at position " <<
position;
661 template <
typename T>
680 size_t max_size = std::max(v.size(),
position +
data.size());
681 v.resize(max_size, 0);
685 [
this](
auto a,
auto b){
return a + ((b == 0)?
baseline: b); }
693 out <<
"increment by data in ";
695 out <<
" with baseline " <<
baseline
696 <<
" starting at position " <<
position;
702 template <
typename T>
719 v.begin() + std::min(
first, v.size()),
720 v.begin() + std::min(
last, v.size()),
729 out <<
"render elements from " <<
first <<
" to " <<
last
736 template <
typename T>
766 { out <<
"void range containing position " <<
position; }
771 template <
typename T>
789 while (rstart < rend) *(rstart++) *=
factor;
800 out <<
"scale data by a factor " <<
factor
801 <<
" starting at position " <<
position;
807 template <
typename T>
808 explicit Scale(
size_t pos, T factor) -> Scale<T>;
811 template <
typename T>
836 { out <<
"scale all data by a factor " <<
factor; }
840 template <
typename T>
explicit ScaleAll(T factor) -> ScaleAll<T>;
843 template <
typename T>
865 { out <<
"set the element " <<
position <<
" to " <<
value; }
870 template <
typename T>
890 { out <<
"turn the element " <<
position <<
" into the void"; }
895 template <
typename T>
910 { v.push_back(
value); }
915 { out <<
"add element " <<
value <<
" (if non-zero)"; }
920 template <
typename T>
943 template <
typename Vector>
949 template <
typename T>
964 { out <<
"change the sign of element " <<
position; }
971 template <
typename Vector>
977 template <
typename T>
999 out <<
"optimize the sparse vector (";
1000 if (
opt_param < 0) out <<
"default settings";
1001 else out <<
"optimization parameter: " <<
opt_param;
1008 template <
typename T>
1019 { v.push_back(
Data_t(v.size())); }
1022 { out <<
"designed failure: changes only vector"; }
1034 template <
typename T>
1035 template <
typename ITER>
1037 for (; start !=
end; ++start)
if (isVoid(*start))
break;
1041 template <
typename T>
1042 template <
typename ITER>
1044 for (; start !=
end; ++start)
if (!isVoid(*start))
break;
1049 template <
typename T>
1050 template <
typename ITER>
1053 if (last == begin)
return begin;
1054 while (--last != begin)
if (isVoid(*last))
break;
1055 return std::next(last);
1058 template <
typename T>
1059 template <
typename ITER>
1061 if (last == begin)
return begin;
1062 while (--last != begin)
if (!isVoid(*last))
break;
1063 return std::next(last);
1067 template <
typename T>
1068 template <
typename ITER>
1072 auto const end = v.cend();
1074 start = skipVoid(start,
end);
1075 while (start !=
end) {
1076 if (i-- == 0)
break;
1077 start = skipRange(start,
end);
1078 start = skipVoid(start,
end);
1083 template <
typename T>
1084 template <
typename ITER>
1088 auto const end = v.cend();
1090 start = skipRange(start,
end);
1091 while (start !=
end) {
1092 if (i-- == 0)
break;
1093 start = skipVoid(start,
end);
1094 start = skipRange(start,
end);
1106 typedef float Data_t;
1137 new_size++, new_size++ * 0, new_size++,
1138 new_size++, new_size++ * 0, new_size++
1181 for (
size_t i = 13; i < 16; ++i)
1224 (5, { 20, 20, 20, 20, 8, 7, 8, 7, 8, 7, 8, 7 }, 30));
1285 #ifdef SPARSE_VECTOR_TEST_FAIL
1289 #endif // SPARSE_VECTOR_TEST_FAIL
virtual void actionOnVector(Vector_t &v) const override
Base class for testing actions.
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
std::string VectorToString(const CONT &sv)
Converts a container into a string.
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
std::ostream & out
output stream
unsigned int nAction
number of actions taken so far
std::vector< Data_t > Vector_t
size_type n_ranges() const
Returns the internal list of non-void ranges.
void describe(TestClass_t &tc) const
Print a description of this action in the test class stream.
static ITER findRangeStart(Vector_t const &v, std::size_t i, ITER start)
Returns iterator to the first element of the i-th range after start.
Data structure to document failure of a single action.
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
unsigned int operator()(const Action_t &action)
virtual void actionOnSparseVector(SparseVector_t &v) const override
size_type size() const
Returns the size of the vector.
TestClass_t::Data_t Data_t
type stored
bool validate() const
Checks if the sparse vector is valid.
TestClass_t::Data_t Data_t
type stored
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
void recover()
Set the sparse vector as a copy of the vector (lossy!)
static constexpr value_type value_zero
a representation of 0
void operator()(Vector_t &v) const
Action performed on a STL vector.
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void actionOnVector(Vector_t &v) const override
TestClass_t::Data_t Data_t
type stored
void Test(TFile *pFile=nullptr, bool statChecks=true)
unsigned int perform(const Action_t &action, bool autoCorrect=true)
Perform the specified action and evaluate the result.
const_iterator cend() const
virtual void actionOnVector(Vector_t &v) const override
TestManagerClass(std::ostream &output_stream=std::cout)
Constructor, specify an output stream.
virtual void actionOnVector(Vector_t &v) const override
auto range_data(std::size_t i)
Provides direct access to data of i-th non-void range (zero-based)
std::ostream & PrintVectorRanges(const lar::sparse_vector< T > &sv, std::ostream &out=std::cout)
Prints a sparse vector highlighting the ranges.
Scale(size_t pos, T factor) -> Scale< T >
static ITER skipRange(ITER start, ITER const end)
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnVector(Vector_t &v) const override
static void doClearVector(Vector &v)
virtual void doDescribe(TestClass_t &, std::ostream &out) const
value_type & set_at(size_type index, value_type value)
Writes into an element (creating or expanding a range if needed)
Data_t value_type
type of the stored values
virtual void actionOnVector(Vector_t &v) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
This_t & set_expected_errors(int exp_err)
auto iterate_ranges() -> decltype(auto)
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
TestClass_t::SparseVector_t SparseVector_t
type of sparse vector
virtual void actionOnSparseVector(SparseVector_t &v) const override
TestClass_t::Data_t Data_t
type stored
ScaleAll(T factor) -> ScaleAll< T >
TestManagerClass< T > TestClass_t
lar::sparse_vector< Data_t > SparseVector_t
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnVector(Vector_t &v) const override
void mirror()
Set the vector as a copy of the sparse vector.
Insert(size_t pos, Vector_t new_data)
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
SetValue(size_t pos, Data_t val)
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
static bool isVoid(Data_t value)
virtual void actionOnSparseVector(SparseVector_t &v) const override
static ITER rangeStart(ITER const begin, ITER last)
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnVector(Vector_t &v) const override
static ITER voidStart(ITER const begin, ITER last)
void make_void(iterator first, iterator last)
Makes all the elements from first and before last void.
auto end(FixedBins< T, C > const &) noexcept
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
int summary() const
Print a summary of the failures.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
virtual void actionOnSparseVector(SparseVector_t &v) const override
SetElement(size_t pos, Data_t new_value)
void describe(TestClass_t &tc, std::ostream &out) const
Print a description of this action into the specified steam.
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnVector(Vector_t &v) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
Vector_t v
vector to operate on
static ITER findRangeStart(Vector_t const &v, std::size_t i)
int quietness
verbosity level (larger is less verbose)
static value_type is_zero(value_type v)
Returns whether the value is exactly zero.
virtual void actionOnVector(Vector_t &v) const override
const datarange_t & combine_range(size_type offset, ITER first, ITER last, OP &&op, value_type void_value=value_zero)
Combines a sequence of elements as a range with data at offset.
AssignMove(Vector_t new_data)
unsigned int nErrors
number of errors accumulated
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
void doAssignValue(Vector &v) const
TestClass_t::Data_t Data_t
type stored
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
void doResizeVector(Vector &v) const
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
std::vector< FailureInfo_t > failures
documentation of the failures
std::string description(TestClass_t &tc) const
Returns a string with a description of this action.
auto begin(FixedBins< T, C > const &) noexcept
size_t current_vector_size() const
Returns the current size of the STL vector.
datarange_t make_void_around(size_type index)
Casts the whole range with the specified item into the void.
bool equal(double a, double b)
Comparison tolerance, in centimeters.
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
void doResizeVector(Vector &v) const
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
unsigned int nErrors
number of detected errors
int expected_errors
number of errors expected for this action
const datarange_t & find_range(size_type index) const
Returns the range containing the specified index.
Erase(size_t from, size_t to)
static ITER skipVoid(ITER start, ITER const end)
TestClass_t::Vector_t Vector_t
type of STL vector
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
actions::BaseAction< Data_t > Action_t
void unset_at(size_type index)
Casts the element with the specified index into the void.
virtual void actionOnVector(Vector_t &v) const override
std::size_t find_range_number(size_type index) const
Returns the number (0-based) of range containing index.
iterator begin()
Standard iterators interface.
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnVector(Vector_t &v) const override
unsigned int nAction
ID of the action.
static void doPrintVector(Vector const &v)
TestManagerClass< Data_t > This_t
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
Scale(size_t pos, Data_t factor)
void push_back(value_type value)
const_iterator cbegin() const
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
void doFlipValue(Vector &v) const
TestClass_t::Data_t Data_t
type stored
Class defining a sparse vector (holes are zeroes)
int main(int argc, char **argv)
Assign(Vector_t new_data)
virtual void actionOnVector(Vector_t &) const
void doAssignVector(Vector &v) const
Truncate(size_t new_size=0)
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
bool optimize()
Performs internal optimization, returns whether the object was changed.
virtual void actionOnSparseVector(SparseVector_t &v) const override
TestClass_t::Data_t Data_t
type stored
void assign(ITER first, ITER last)
Copies data from a sequence between two iterators.
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
recob::tracking::Vector_t Vector_t
void run(const Action_t &action)
void PrintVector(std::ostream &out, Array const &v, std::string name="Vector")
static ITER findVoidStart(Vector_t const &v, std::size_t i, ITER start)
virtual void actionOnSparseVector(SparseVector_t &) const
virtual void actionOnVector(Vector_t &v) const override
std::string description
description of the failed action
typename Vector_t::const_iterator v_citer_t
BEGIN_PROLOG could also be cout
static auto findRangeBorders(Vector &v, std::size_t pos)
virtual void actionOnVector(Vector_t &v) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
Resize(size_t new_size=0)
virtual void doDescribe(TestClass_t &, std::ostream &out) const override
virtual void actionOnSparseVector(SparseVector_t &v) const override
ResizeWith(size_t new_size, Data_t val)
TestClass_t::Data_t Data_t
type stored
size_type count() const
Returns the number of non-void cells.