Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPrintPMTParameters.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <vector>
6
7#include "JLang/JVectorize.hh"
8
12
13#include "Jeep/JParser.hh"
14#include "Jeep/JMessage.hh"
15
16
17namespace {
18
19 using namespace JPP;
20
21 static const int WILDCARD = -1; //<! Wild card for PMT identifier.
22 static const char SEPARATOR = '.'; //<! PMT identifier separator.
23 static const std::string DEFAULT_ID = "%"; //<! PMT identifier for default PMT parameters.
24
25
26 /**
27 * Compare PMT identifiers taking into account wild cards.
28 *
29 * \param first first PMT identifier
30 * \param second second PMT identifier
31 * \return true if addresses are equal; else false
32 */
33 inline bool compare(const JPMTIdentifier& first, const JPMTIdentifier& second)
34 {
35 return (((first == second)) ||
36 ((first.getID() == WILDCARD || second.getID() == WILDCARD) && first.getTDC() == second.getTDC()) ||
37 ((first.getTDC() == WILDCARD || second.getTDC() == WILDCARD) && first.getID() == second.getID()) ||
38 ((first.getID() == WILDCARD || second.getID() == WILDCARD) &&
39 (first.getTDC() == WILDCARD || second.getTDC() == WILDCARD)));
40 }
41
42
43 /**
44 * Print PMT parameters.
45 *
46 * \param out output stream
47 * \param id id
48 * \param parameters PMT parameters
49 * \param __begin begin list of keys
50 * \param __end end list of keys
51 */
52 template<class T>
53 inline void print(std::ostream& out, const std::string& id, const JPMTParameters& parameters, T __begin, T __end)
54 {
55 using namespace std;
56 using namespace JPP;
57
58 out << LEFT(12) << id;
59
60 for (T i = __begin; i != __end; ++i) {
61
62 out << ' ' << FIXED(7,3);
63
64 parameters.getProperties()[*i]->write(out);
65 }
66
67 out << endl;
68 }
69}
70
71
72/**
73 * \file
74 *
75 * Auxiliary program to print PMT parameters.
76 *
77 * NOTE: PMT identifiers need to be specified as <module>.<channel> or as "%" in case the default PMT parameters need to be printed.
78 * \author mdejong, bjung
79 */
80int main(int argc, char **argv)
81{
82 using namespace std;
83 using namespace JPP;
84
85 JPMTParametersMap parameters;
86 vector<string> pmts;
87 vector<string> keys;
88 int debug;
89
90 try {
91
92 const JPMTParameters& buffer = parameters.getDefaultPMTParameters();
93 const JProperties properties = buffer.getProperties();
94
95 JParser<> zap("Auxiliary program to print PMT parameters.");
96
97 zap['P'] = make_field(parameters, "PMT simulation data (or corresponding file name)") = JPMTParametersMap();
98 zap['p'] = make_field(pmts, "PMT identifier, e.g. <module identifier>.<PMT> or \"%\"") = JPARSER::initialised();
99 zap['k'] = make_field(keys, "parameters:" << endl << get_keys(properties)) = JPARSER::initialised();
100 zap['d'] = make_field(debug) = 3;
101
102 zap(argc, argv);
103 }
104 catch(const exception &error) {
105 FATAL(error.what() << endl);
106 }
107
108
109 for (vector<string>::const_iterator i = pmts.cbegin(); i != pmts.cend(); ++i) {
110
111 if ((*i) != DEFAULT_ID) { // Print PMT-specific parameters
112
113 const size_t pos = i->find(SEPARATOR);
114
115 if (pos == string::npos) {
116 FATAL("Invalid PMT specifier " << *i << endl);
117 }
118
119 const JPMTIdentifier id(stoi(i->substr(0, pos)), stoi(i->substr(pos + 1)));
120
121 for (JPMTParametersMap::const_iterator ps = parameters.cbegin(); ps != parameters.cend(); ++ps) {
122 if (compare(ps->first, id)) {
123 print(cout, *i, ps->second, keys.cbegin(), keys.cend());
124 }
125 }
126
127 } else { // Print default PMT parameters
128
129 print(cout, *i, parameters.getDefaultPMTParameters(), keys.cbegin(), keys.cend());
130 }
131 }
132
133 return 0;
134}
135
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Auxiliary class for map of PMT parameters.
const JPMTParameters & getDefaultPMTParameters() const
Get default PMT parameters.
Data structure for PMT parameters.
JProperties getProperties(const JEquationParameters &equation=JPMTParameters::getEquationParameters())
Get properties of this class.
Utility class to parse parameter values.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
@ LEFT
Definition JTwosome.hh:18
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68