Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JFirmware.cc File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TGraph.h"
#include "TH2D.h"
#include "JROOT/JRootToolkit.hh"
#include "JSystem/JGlob.hh"
#include "JDB/JUPI_t.hh"
#include "JDetector/JLocation.hh"
#include "JLang/JVectorize.hh"
#include "JTools/JRange.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Auxiliary program to plot firmware versions.
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Auxiliary program to plot firmware versions.

Author
mdejong

Definition at line 33 of file JFirmware.cc.

34{
35 using namespace std;
36 using namespace JPP;
37
38 vector<string> inputFile;
39 string outputFile;
40 int debug;
41
42 try {
43
44 JParser<> zap("Auxiliary program to plot firmware versions.");
45
46 zap['f'] = make_field(inputFile);
47 zap['o'] = make_field(outputFile) = "firmware.root";
48 zap['d'] = make_field(debug) = 2;
49
50 zap(argc, argv);
51 }
52 catch(const exception &error) {
53 FATAL(error.what() << endl);
54 }
55
56
57 const char SEPARATOR = '.';
58
59 inputFile = getFilenames(inputFile);
60
61 //
62 // stable index of firmware version
63 //
64 struct :
65 public vector<string>
66 {
67 int operator()(const string& firmware)
68 {
69 using namespace std;
70
71 iterator p = find(this->begin(), this->end(), firmware);
72
73 if (p == this->end()) {
74
75 this->push_back(firmware);
76
77 p = this->rbegin().base();
78 }
79
80 return distance(this->begin(), p);
81 }
82 } version;
83
84
85 struct pair_type {
86 int run;
87 int version;
88 };
89
90
92
94
95
96 for (const string& i : inputFile) {
97
98 STATUS(i << '\r'); DEBUG(endl);
99
100 int run;
101
102 {
103 string::size_type pos = i.find(SEPARATOR);
104
105 if (pos != string::npos)
106 istringstream(i.substr(0,pos)) >> run;
107 else
108 continue;
109 }
110
111 range.include(run);
112
113 ifstream in(i);
114
115 string buffer;
116 string location;
117 string upi;
118 string firmware;
119
120 while (in >> buffer >> location >> upi && getline(in, firmware)) {
121
122 string::size_type pos = location.find(SEPARATOR);
123
124 if (pos != string::npos) {
125
126 const int index = version(firmware);
127
128 int string, floor;
129
130 istringstream(location.substr(0,pos)) >> string;
131 istringstream(location.substr(pos+1)) >> floor;
132
133 DEBUG(FILL(4,'0') << string << '.' << FILL(2,'0') << floor << ' ' << firmware << endl);
134
135 data[JLocation(string,floor)].push_back({run,index});
136
137 } else
138 continue;
139 }
140
141 in.close();
142 }
143 STATUS(endl);
144
145
146 for (size_t i = 0; i != version.size(); ++i) {
147 cout << setw(2) << i << ' ' << version[i] << endl;
148 }
149
150
151 TH2D h2("H2", NULL,
152 range.getLength() + 1, range.getLowerLimit(), range.getUpperLimit() + 1.0,
153 data .size() , 0 , data. size() + 0.0);
154 {
155 int iy = 1;
156
157 for (const auto& i : data) {
158
159 //h2.GetYaxis()->SetBinLabel(iy, MAKE_CSTRING(getLabel(i.first)));
160
161 if (i.first.getFloor() == 0) {
162 h2.GetYaxis()->SetBinLabel(iy, MAKE_CSTRING(i.first.getString()));
163 }
164
165 for (const auto& fs : i.second) {
166
167 const int ix = fs.run - range.getLowerLimit() + 1;
168 const double z = fs.version;
169
170 h2.SetBinContent(ix, iy, z);
171 }
172
173 iy += 1;
174 }
175 }
176
177
178 TFile out(outputFile.c_str(), "recreate");
179
180 for (const auto& i : data) {
181
182 const auto X = make_array(i.second.begin(), i.second.end(), &pair_type::run);
183 const auto Y = make_array(i.second.begin(), i.second.end(), &pair_type::version);
184
185 TGraph g1(i.second.size(), X.data(), Y.data());
186
187 g1.SetName(MAKE_CSTRING(getLabel(i.first)));
188
189 out << g1;
190 }
191
192 out << h2;
193
194 out.Write();
195 out.Close();
196}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:57
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Logical location of module.
Definition JLocation.hh:40
Utility class to parse command line options.
Definition JParser.hh:1697
Range of values.
Definition JRange.hh:42
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289
range_type & include(argument_type x)
Include given value to range.
Definition JRange.hh:397
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition JLocation.hh:247
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
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
Data structure for a pair of indices.