Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JPrintFirmwareVersion.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <sstream>
4#include <iomanip>
5#include <vector>
6#include <algorithm>
7
8#include "JDB/JDB.hh"
9#include "JDB/JSelector.hh"
11#include "JDB/JCLBMap.hh"
13#include "JDB/JDBToolkit.hh"
14
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * \file
21 *
22 * Auxiliary program to print firmware vesion.
23 * \author mdejong
24 */
25int main(int argc, char **argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 JServer server;
31 string usr;
32 string pwd;
33 string cookie;
34 string id;
35 int run;
36 int debug;
37
38 try {
39
40 JParser<> zap("Auxiliary program to print firmware vesion.");
41
42 zap['s'] = make_field(server) = getServernames();
43 zap['u'] = make_field(usr) = "";
44 zap['!'] = make_field(pwd) = "";
45 zap['C'] = make_field(cookie) = "";
46 zap['D'] = make_field(id, "detector identifier") = "";
47 zap['r'] = make_field(run, "run number") = -1;
48 zap['d'] = make_field(debug) = 1;
49
50 zap(argc, argv);
51 }
52 catch(const exception &error) {
53 FATAL(error.what() << endl);
54 }
55
56
57 try {
58 JDB::reset(usr, pwd, cookie);
59 }
60 catch(const exception& error) {
61 FATAL(error.what() << endl);
62 }
63
64 const string detid = getDetector<string>(id);
65
66 vector<JCLBMap> clbmap;
67
68 try {
69
70 ResultSet& rs = getResultSet(getTable<JCLBMap>(), getSelector<JCLBMap>(detid));
71
72 if (! (rs >> clbmap)) {
73 THROW(JDatabaseException, "Error reading " << getTable<JCLBMap>());
74 }
75
76 rs.Close();
77 }
78 catch(const exception& error) {
79 FATAL("Detector " << detid << " - " << error.what() << endl);
80 }
81
82 if (clbmap.empty()) {
83 FATAL("Detector " << detid << " - " << " no data." << endl);
84 }
85
86
87 struct {
88 bool operator()(const JCLBMap& first, const JCLBMap& second) const
89 {
90 if (first.DUID == second.DUID)
91 return first.FLOORID < second.FLOORID;
92 else
93 return first.DUID < second.DUID;
94 }
95 } compare;
96
97 sort(clbmap.begin(), clbmap.end(), compare);
98
99
100 for (const auto& i : clbmap) {
101
102 string version = "?";
103
104 try {
105
106 JSelector selection(&JDatalogNumbers::SOURCE_NAME, i.UPI.toString());
107
108 selection += getSelector<JDatalogNumbers>(detid, run, run);
109
110 ResultSet& rs = getResultSet(getTable<JDatalogNumbers>(), selection);
111
112 for (JDatalogNumbers parameters; rs >> parameters; ) {
113
114 const int value = (int) parameters.DATA_VALUE;
115
116 if (value != 0) {
117
118 const size_t pos = parameters.PARAMETER_NAME.find("BUILD");
119
120 if (pos != string::npos) {
121
122 const size_t ls[] = {
123 parameters.PARAMETER_NAME.find('['),
124 parameters.PARAMETER_NAME.find(']')
125 };
126
127 if (ls[0] < ls[1]) {
128
129 size_t index;
130
131 istringstream(parameters.PARAMETER_NAME.substr(ls[0] + 1, ls[1] - ls[0] + 1)) >> index;
132
133 if (version.size() <= index) {
134 version.append(index - version.size() + 1, ' ');
135 }
136
137 DEBUG(parameters.PARAMETER_NAME << ' ' << ls[0] << ' ' << ls[1] << ' ' << index << ' ' << value << endl);
138
139 version[index] = (char) value;
140 }
141 }
142 }
143 }
144
145 rs.Close();
146 }
147 catch(const exception& error) {
148 FATAL(error.what() << endl);
149 }
150
151 cout << "Firmware: " << FILL(4,'0') << i.DUID << '.' << FILL(2,'0') << i.FLOORID << " " << setw(24) << left << i.UPI << " \"" << version << "\"" << right << endl;
152 }
153
154 return 0;
155}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#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)
Database exception.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Wrapper class for server name.
Definition JDB.hh:54
Template definition for getting table specific selector.
Auxiliary data structure to list files in directory.