source: trunk/FACT++/src/PixelMap.cc@ 18232

Last change on this file since 18232 was 15264, checked in by tbretz, 12 years ago
Moved back to FACT++/src
File size: 1.9 KB
Line 
1#include "externals/PixelMap.h"
2
3using namespace std;
4
5#include <boost/regex.hpp>
6#include <mysql++/mysql++.h>
7
8void BiasMap::Retrieve(const std::string &database)
9{
10 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
11 // 2: user
12 // 4: pass
13 // 5: server
14 // 7: port
15 // 9: db
16
17 boost::smatch what;
18 if (!boost::regex_match(database, what, expr, boost::match_extra))
19 throw runtime_error("Couldn't parse '"+database+"'.");
20
21 if (what.size()!=10)
22 throw runtime_error("Error parsing '"+database+"'.");
23
24 const string user = what[2];
25 const string passwd = what[4];
26 const string server = what[5];
27 const string db = what[9];
28 const int port = atoi(string(what[7]).c_str());
29
30 mysqlpp::Connection conn(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port);
31
32 const mysqlpp::StoreQueryResult res =
33 conn.query("SELECT fPatchNumber, AVG(fVoltageNom), fOffset "
34 " FROM GapdVoltages "
35 " LEFT JOIN BiasOffsets USING(fPatchNumber) "
36 " GROUP BY fPatchNumber").store();
37
38 clear();
39
40 int l = 0;
41 for (vector<mysqlpp::Row>::const_iterator v=res.begin(); v<res.end(); v++)
42 {
43 const int id = (*v)[0];
44
45 if (id<0 || id>416)
46 {
47 ostringstream str;
48 str << "Invalid channel id " << id << " received from database.";
49 throw runtime_error(str.str());
50 }
51
52 BiasMapEntry entry;
53
54 entry.hv_board = id/32;
55 entry.hv_channel = id%32;
56 entry.Vnom = (*v)[1];
57 entry.Voff = (*v)[2];
58
59 (*this)[id] = entry;
60
61 l++;
62 }
63
64 if (l!=416)
65 throw runtime_error("Number of rows retrieved from the database does not match 416.");
66
67 if (size()!=416)
68 throw runtime_error("Number of entries retrived from database does not match 416.");
69}
Note: See TracBrowser for help on using the repository browser.