All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
KeyedCSVparser_test.cc File Reference

Unit test for KeyedCSVparser.h header. More...

#include "icaruscode/Decode/DecoderTools/details/KeyedCSVparser.h"
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include <cstdint>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( KeyedCSVparser_test )
 

Functions

void KeyedCSVparser_documentation_test ()
 
 BOOST_AUTO_TEST_CASE (KeyedCSVparser_documentation_testcase)
 

Detailed Description

Unit test for KeyedCSVparser.h header.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
March 4, 2022
See Also
icaruscode/Decode/DecoderTools/details/KeyedCSVparser.h

Definition in file KeyedCSVparser_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( KeyedCSVparser_test )

Definition at line 14 of file KeyedCSVparser_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( KeyedCSVparser_documentation_testcase  )

Definition at line 162 of file KeyedCSVparser_test.cc.

162  {
163 
165 
166 } // BOOST_AUTO_TEST_CASE(KeyedCSVparser_documentation_testcase)
void KeyedCSVparser_documentation_test()
void KeyedCSVparser_documentation_test ( )

Definition at line 27 of file KeyedCSVparser_test.cc.

27  {
28 
29  /*
30  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31  * using namespace std::string_view_literals;
32  * icarus::details::KeyedCSVparser parser;
33  * parser.addPatterns({
34  * { "Trigger Type", 1U } // expect one value (even if contains letters)
35  * , { "TriggerWindows", 1U } // expect one value (even if contains letters)
36  * , { "TPChitTimes", icarus::details::KeyedCSVparser::FixedSize }
37  * // the first value is an integer, count of how many other values
38  * });
39  *
40  * icarus::KeyValuesData data = parser(
41  * "TriggerType, S5, Triggers, TriggerWindows, 0C0B,"
42  * " TPChits, 12, 130, 0, 0, TPChitTimes, 3, -1.1, -0.3, 0.1, PMThits, 8"sv
43  * );
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  */
46 
47  using namespace std::string_literals;
49  parser.addPatterns({
50  { "TriggerType", 1U } // expect one value (even if contains letters)
51  , { "TriggerWindows", 1U } // expect one value (even if contains letters)
53  // the first value is an integer, count of how many other values
54  });
55 
57  "TriggerType, S5, Triggers, TriggerWindows, 0C0B,"
58  " TPChits, 12, 130, 0, 0, TPChitTimes, 3, -1.1, -0.3, 0.1, PMThits, 8"s
59  );
60 
61  // deep test:
62  std::vector<int> const expectedTPChits { 12, 130, 0, 0 };
63  std::vector<float> const expectedTPCtimes { -1.1, -0.3, 0.1 };
64 
65  icarus::KeyValuesData::Item const* item = nullptr;
66 
67  std::cout << data << std::endl;
68 
69  BOOST_TEST(data.hasItem("TriggerType"));
70  item = data.findItem("TriggerType");
71  BOOST_TEST(item);
72  BOOST_TEST(&(data.getItem("TriggerType")) == item);
73  BOOST_TEST(item->nValues() == 1);
74  BOOST_TEST(item->value() == "S5");
75 
76  BOOST_TEST(data.hasItem("Triggers"));
77  item = data.findItem("Triggers");
78  BOOST_TEST(item);
79  BOOST_TEST(&(data.getItem("Triggers")) == item);
80  BOOST_TEST(item->values().empty());
81  BOOST_TEST(item->getVector<int>().empty());
82 
83  BOOST_TEST(data.hasItem("TriggerWindows"));
84  item = data.findItem("TriggerWindows");
85  BOOST_TEST(item);
86  BOOST_TEST(&(data.getItem("TriggerWindows")) == item);
87  BOOST_TEST(item->nValues() == 1);
88  BOOST_TEST(item->value(0) == "0C0B");
89  BOOST_TEST(item->getNumber<std::uint32_t>(0, 16) == 0x0C0B);
90 
91  BOOST_TEST(data.hasItem("TPChits"));
92  item = data.findItem("TPChits");
93  BOOST_TEST(item);
94  BOOST_TEST(&(data.getItem("TPChits")) == item);
95  BOOST_TEST(item->nValues() == 4);
96  BOOST_TEST(item->value(0) == "12");
97  BOOST_TEST(item->value(1) == "130");
98  BOOST_TEST(item->value(2) == "0");
99  BOOST_TEST(item->value(3) == "0");
100  BOOST_TEST(item->getVector<int>() == expectedTPChits);
101 
102  BOOST_TEST(data.hasItem("TPChitTimes"));
103  item = data.findItem("TPChitTimes");
104  BOOST_TEST(item);
105  BOOST_TEST(&(data.getItem("TPChitTimes")) == item);
106  BOOST_TEST(item->nValues() == 4);
107  BOOST_TEST(item->value(0) == "3");
108  BOOST_TEST(item->value(1) == "-1.1");
109  BOOST_TEST(item->value(2) == "-0.3");
110  BOOST_TEST(item->value(3) == "0.1");
111  BOOST_TEST(item->getSizedVector<float>() == expectedTPCtimes);
112 
113  BOOST_TEST(!data.hasItem("CRThits"));
114  item = data.findItem("CRThits");
115  BOOST_TEST(!item);
116 
117  /*
118  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119  * std::string triggerType = data.getItem("TriggerType").value(0);
120  * std::vector<int> triggers = data.getItem("Triggers").getVector<int>();
121  * std::uint32_t triggerWindowBits
122  * = data.getItem("TriggerWindows").getNumber<std::uint32_t>(0, 16); // base 16
123  * std::vector<int> TPChits = data.getItem("TPChits").getVector<int>();
124  * std::vector<float> TPCtimes
125  * = data.getItem("TPChitTimes").getSizedVector<float>();
126  * std::vector<int> CRThits;
127  * if (auto const* item = data.findItem("CRThits"))
128  * CRThits = item->getVector<int>();
129  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130  */
131 
132  std::string triggerType = data.getItem("TriggerType").value(0);
133  BOOST_TEST(triggerType == "S5");
134 
135  std::vector<int> triggers = data.getItem("Triggers").getVector<int>();
136  BOOST_TEST(triggers.empty());
137 
138  std::uint32_t triggerWindowBits
139  = data.getItem("TriggerWindows").getNumber<std::uint32_t>(0, 16); // base 16
140  BOOST_TEST(triggerWindowBits == 0x0C0B);
141 
142  std::vector<int> TPChits = data.getItem("TPChits").getVector<int>();
143  BOOST_TEST(TPChits == expectedTPChits);
144 
145  std::vector<float> TPCtimes
146  = data.getItem("TPChitTimes").getSizedVector<float>();
147  BOOST_TEST(TPCtimes == expectedTPCtimes);
148 
149  std::vector<int> CRThits;
150  BOOST_TEST(!data.hasItem("CRThits"));
151  BOOST_TEST(!data.findItem("CRThits"));
152  if (auto const* item = data.findItem("CRThits"))
153  CRThits = item->getVector<int>();
154  BOOST_TEST(CRThits.empty());
155 
156 } // KeyedCSVparser_documentation_test()
static constexpr unsigned int FixedSize
Expected values are missing.
Parser to fill a KeyValuesData structure out of a character buffer.
Representation of a single item of data: a key and several values.
triggerType
Type representing the type(s) of this trigger.
Definition: BeamBits.h:128
Collection of items with key/values structure.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
BEGIN_PROLOG could also be cout