Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSon/JSupport.hh
Go to the documentation of this file.
1 #ifndef __JSON__JSUPPORT__
2 #define __JSON__JSUPPORT__
3 
4 #include <string>
5 #include <vector>
6 #include <algorithm>
7 
8 #include "JLang/JPredicate.hh"
9 #include "JLang/JException.hh"
10 
11 #include "JSon/JSon.hh"
12 
13 
14 /**
15  * \file
16  * JSon definitions and auxiliaries.
17  *
18  * \author mdejong, bjung, acreusot
19  */
20 
21 namespace JSON {}
22 namespace JPP { using namespace JSON; }
23 
24 /**
25  * Auxiliary classes and methods for detector calibration.
26  */
27 namespace JSON {
28 
30 
31 
32  static const std::string TCAL = "tcal"; //!< PMT time offsets
33  static const std::string PCAL = "pcal"; //!< (optical|base) module positions
34  static const std::string RCAL = "rcal"; //!< optical module orientations
35  static const std::string ACAL = "acal"; //!< acoustic time offsets (piezo sensor or hydrophone)
36  static const std::string CCAL = "ccal"; //!< compass alignment (a.k.a.\ quaternion calibration)
37  static const std::string SCAL = "scal"; //!< (module|PMT) status
38 
39  static const std::string PMT_T0_CALIBRATION_t = "PMT_T0_CALIBRATION"; //!< PMT time offsets
40  static const std::string DOM_POSITION_CALIBRATION_t = "DOM_POSITION_CALIBRATION"; //!< (optical|base) module positions
41  static const std::string DOM_ROTATION_CALIBRATION_t = "DOM_ROTATION_CALIBRATION"; //!< optical module orientations
42  static const std::string ACOUSTIC_T0_CALIBRATION_t = "ACOUSTIC_T0_CALIBRATION"; //!< acoustic time offsets (piezo sensor or hydrophone)
43  static const std::string COMPASS_CALIBRATION_t = "COMPASS_CALIBRATION"; //!< compass alignment (a.k.a.\ quaternion calibration)
44  static const std::string STATUS_CALIBRATION_t = "STATUS_CALIBRATION"; //!< (module|PMT) status
45 
46 
47  /**
48  * Auxiliary data structure for pairwise nick and full name of calibration type.
49  */
51  std::string nick_name; //!< nick name (e.g. "xcal")
52  std::string full_name; //!< full name (e.g. "XXX_YYY_CALIBRATION")
53  };
54 
55 
56  /**
57  * Auxiliary data structure for correspondence between nick and full name of calibration types.
58  */
59  static const struct getCalibrationType :
60  public std::vector<JCalibrationType>
61  {
62  /**
63  * Default constructor.
64  */
66  {
67  this->push_back( { TCAL, PMT_T0_CALIBRATION_t } );
68  this->push_back( { PCAL, DOM_POSITION_CALIBRATION_t } );
69  this->push_back( { RCAL, DOM_ROTATION_CALIBRATION_t } );
70  this->push_back( { ACAL, ACOUSTIC_T0_CALIBRATION_t } );
71  this->push_back( { CCAL, COMPASS_CALIBRATION_t } );
72  this->push_back( { SCAL, STATUS_CALIBRATION_t } );
73  }
74 
75 
76  /**
77  * Has calibration type.
78  *
79  * \param type full name
80  * \return true if available; else false
81  */
82  bool hasNickname(const std::string& type) const
83  {
84  using namespace std;
85  using namespace JPP;
86 
87  return (find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::full_name, type)) != this->end());
88  }
89 
90 
91  /**
92  * Has calibration type.
93  *
94  * \param type nick name
95  * \return full name
96  */
97  bool hasFullname(const std::string& type) const
98  {
99  using namespace std;
100  using namespace JPP;
101 
102  return (find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::nick_name, type)) != this->end());
103  }
104 
105 
106  /**
107  * Get calibration type.
108  *
109  * \param type full name
110  * \return nick name
111  */
112  const std::string& getNickname(const std::string& type) const
113  {
114  using namespace std;
115  using namespace JPP;
116 
117  const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::full_name, type));
118 
119  if (p != this->end())
120  return p->nick_name;
121  else
122  THROW(JValueOutOfRange, "Invalid calibration type <" << type << ">");
123  }
124 
125 
126  /**
127  * Get calibration type.
128  *
129  * \param type nick name
130  * \return full name
131  */
132  const std::string& getFullname(const std::string& type) const
133  {
134  using namespace std;
135  using namespace JPP;
136 
137  const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::nick_name, type));
138 
139  if (p != this->end())
140  return p->full_name;
141  else
142  THROW(JValueOutOfRange, "Invalid calibration type <" << type << ">");
143  }
144 
146 
147 
148  // Meta data
149  static const std::string User_t = "User";
150  static const std::string UserId_t = "UserId";
151  static const std::string TypeId_t = "TypeId";
152  static const std::string Location_t = "Location";
153  static const std::string LocationId_t = "LocId";
154  static const std::string Time_t = "Time";
155  static const std::string Start_t = "Start";
156  static const std::string End_t = "End";
157  static const std::string Comment_t = "Comment";
158  static const std::string Encoding_t = "Encoding";
159  static const std::string Input_t = "Inputs";
160  static const std::string Error_t = "Error";
161  static const std::string Message_t = "Message";
162  static const std::string Code_t = "Code";
163  static const std::string Provenance_t = "Provenance";
164  static const std::string Info_t = "Info";
165  static const std::string Configuration_t = "Configuration";
166  static const std::string Arguments_t = "Arguments";
167  static const std::string Inputs_t = "Inputs";
168  static const std::string UUID_t = "UUID";
169  static const std::string APIVersion_t = "APIVersion";
170  static const std::string Result_t = "Result";
171  static const std::string Status_t = "StatusId";
172  static const std::string Decision_t = "DecisionId";
173  static const std::string OK_t = "OK";
174  static const std::string Fail_t = "FAIL";
175  static const std::string ValidFrom_t = "ValidFrom";
176  static const std::string ValidThrough_t = "ValidThrough";
177  static const std::string StartTime_t = "StartTime";
178  static const std::string EndTime_t = "EndTime";
179  static const std::string Tags_t = "Tags";
180 
181  // Type specifiers
182  static const std::string Type_t = "Type";
183  static const std::string Test_t = "Test";
184  static const std::string Tests_t = "Tests";
185  static const std::string Data_t = "Data";
186  static const std::string URL_t = "URL";
187  static const std::string Name_t = "Name";
188  static const std::string Unit_t = "Unit";
189  static const std::string Values_t = "Values";
190  static const std::string Parameters_t = "Parameters";
191  static const std::string RunNumber_t = "RUN_NUMBER";
192 
193  // Calibration types
194  static const std::string PMTT0s_t = "PMTT0s";
195  static const std::string DOMPositions_t = "DOMPositions";
196  static const std::string DOMRotations_t = "DOMRotations";
197  static const std::string DOMAcousticT0_t = "DOMAcousticT0s";
198  static const std::string DOMCompassRotations_t = "DOMCompassRotations";
199  static const std::string DOMStatusInfo_t = "DOMStatusInfo";
200  static const std::string BasePositions_t = "BasePositions";
201  static const std::string BaseAcousticT0_t = "BaseAcousticT0s";
202  static const std::string BaseCompassRotations_t = "BaseCompassRotations";
203  static const std::string BaseStatusInfo_t = "BaseStatusInfo";
204 
205  // Module map of PMT addresses
206  static const std::string DOMMap_t = "DOMMap";
207 
208  // HV tuning types
209  static const std::string PMTThreshold_t = "PMT_Threshold";
210  static const std::string PMTStatusInfo_t = "PMTStatusInfo";
211  static const std::string PMTSupplyVoltage_t = "PMT_Supply_Voltage";
212  static const std::string PMTGain_t = "PMT_Gain";
213 
214  // Object identifiers
215  static const std::string UPI_t = "UPI";
216  static const std::string PBS_t = "PBS";
217  static const std::string Variant_t = "Variant";
218  static const std::string DetOID_t = "DetOID";
219  static const std::string DetID_t = "DetID";
220  static const std::string Serial_t = "Serial";
221  static const std::string DOMId_t = "DOMId";
222  static const std::string Id_t = "Id";
223 
224  // Variable names
225  static const std::string T0_t = "T0";
226  static const std::string PX_t = "PX";
227  static const std::string PY_t = "PY";
228  static const std::string PZ_t = "PZ";
229  static const std::string Q0_t = "Q0";
230  static const std::string QX_t = "QX";
231  static const std::string QY_t = "QY";
232  static const std::string QZ_t = "QZ";
233  static const std::string STATUS_t = "Status";
234 
235  // Units
236  static const std::string Unitless_t = "-";
237  static const std::string Volt_t = "V";
238 
239 
240  /**
241  * Check validity of JSon data.
242  *
243  * \param js JSon data
244  * \return true if valid; else false
245  */
246  inline bool is_valid(const json& js)
247  {
248  return (js.contains(Error_t) && js[Error_t][Code_t] == OK_t);
249  }
250 }
251 
252 #endif
static const std::string Arguments_t
bool hasNickname(const std::string &type) const
Has calibration type.
static const std::string Volt_t
static const std::string Start_t
const std::string & getFullname(const std::string &type) const
Get calibration type.
Exceptions.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
static const std::string Location_t
static const std::string DOMStatusInfo_t
static const std::string STATUS_t
static const std::string Code_t
static const std::string UserId_t
static const std::string Encoding_t
static const std::string EndTime_t
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string STATUS_CALIBRATION_t
(module|PMT) status
static const std::string Input_t
static const std::string Name_t
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
bool is_valid(const json &js)
Check validity of JSon data.
static const std::string DOM_ROTATION_CALIBRATION_t
optical module orientations
static const std::string PMTT0s_t
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
static const std::string Error_t
static const std::string Parameters_t
static const std::string QX_t
Auxiliary data structure for correspondence between nick and full name of calibration types...
static const std::string Inputs_t
std::string full_name
full name (e.g. &quot;XXX_YYY_CALIBRATION&quot;)
static const std::string T0_t
static const std::string QZ_t
static const std::string BaseStatusInfo_t
static const std::string Unit_t
static const std::string DOMId_t
static const std::string Id_t
static const std::string PBS_t
static const std::string Time_t
static const std::string UPI_t
static const std::string Values_t
std::string nick_name
nick name (e.g. &quot;xcal&quot;)
static const std::string ValidFrom_t
static const std::string Serial_t
static const std::string TCAL
PMT time offsets.
static const std::string Comment_t
static const std::string APIVersion_t
static const std::string RunNumber_t
static const std::string PZ_t
static const std::string ValidThrough_t
static const std::string Tags_t
static const std::string DOMMap_t
static const std::string Configuration_t
static const std::string Test_t
static const std::string Q0_t
static const std::string Unitless_t
static const std::string PMT_T0_CALIBRATION_t
PMT time offsets.
static const std::string COMPASS_CALIBRATION_t
compass alignment (a.k.a. quaternion calibration)
static const std::string StartTime_t
then awk string
static const std::string DOMPositions_t
static const std::string PMTThreshold_t
static const std::string Status_t
static const std::string PX_t
static const std::string End_t
static const std::string Variant_t
static const std::string Result_t
static const std::string RCAL
optical module orientations
static const std::string Info_t
static const std::string DOMCompassRotations_t
static const std::string DOM_POSITION_CALIBRATION_t
(optical|base) module positions
static const std::string Message_t
static const std::string PMTGain_t
Auxiliary data structure for pairwise nick and full name of calibration type.
static const std::string DetOID_t
const std::string & getNickname(const std::string &type) const
Get calibration type.
static const std::string Data_t
static const std::string SCAL
(module|PMT) status
nlohmann::json json
static const std::string BasePositions_t
static const std::string PY_t
static const std::string DOMRotations_t
getCalibrationType()
Default constructor.
static const std::string LocationId_t
static const std::string Type_t
bool hasFullname(const std::string &type) const
Has calibration type.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
static const std::string Provenance_t
static const std::string BaseCompassRotations_t
static const std::string PMTSupplyVoltage_t
static const std::string PMTStatusInfo_t
static const std::string PCAL
(optical|base) module positions
static const std::string ACOUSTIC_T0_CALIBRATION_t
acoustic time offsets (piezo sensor or hydrophone)
static const std::string UUID_t
static const std::string Decision_t
static const std::string DetID_t
static const std::string Tests_t
static const std::string URL_t
static const std::string QY_t
static const std::string DOMAcousticT0_t
static const std::string TypeId_t
static const std::string BaseAcousticT0_t
static const std::string OK_t
static const std::string Fail_t
static const std::string User_t