forked from marc1uk/GDConcMeasure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_pure_ref.cpp
More file actions
65 lines (58 loc) · 2.14 KB
/
make_pure_ref.cpp
File metadata and controls
65 lines (58 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "TFile.h"
#include "TGraphErrors.h"
#include <iostream>
int main(int argc, const char** argv){
if(argc<3){
std::cerr<<"usage: "<<argv[0]<<" <file> <ledname> <date>"<<std::endl;
return 0;
}
TFile* f = TFile::Open(argv[1]);
if(f==nullptr){
std::cerr<<"couldn't open file "<<argv[1]<<std::endl;
return 1;
}
TGraph* g = (TGraph*)f->Get("Graph");
if(g==nullptr){
std::cerr<<"no graph named 'Graph' in file "<<argv[1]<<std::endl;
return 2;
}
std::string ledname = argv[2];
std::string date = (argc >3) ? argv[3] : "now()";
std::cout<<"# This script only generates the psql command to run; it does not make the database entry.\n"
<<"# Please validate the below printout and run the command if everything looks good\n"<<std::endl;
std::string psqlstring = "psql -c \"INSERT INTO data (timestamp, tool, ledname, name, values) VALUES "
"( '"+date+"', 'MarcusAnalysis', '" +ledname + "', 'pure_curve', '{ \\\"xvals\\\":[";
for(int i=0; i<g->GetN(); ++i){
psqlstring += std::to_string(g->GetX()[i]) + ",";
}
psqlstring.pop_back(); // remove trailing ','
psqlstring += "], \\\"yvals\\\":[";
for(int i=0; i<g->GetN(); ++i){
psqlstring += std::to_string(g->GetY()[i]) + ",";
}
psqlstring.pop_back(); // remove trailing ','
psqlstring += "]";
TGraphErrors* ge = dynamic_cast<TGraphErrors*>(g);
if(ge!=nullptr){
// add errors if we have them
psqlstring += ", \\\"xerrs\\\":[";
for(int i=0; i<g->GetN(); ++i){
psqlstring += std::to_string(g->GetEX()[i]) + ",";
}
psqlstring.pop_back(); // remove trailing ','
psqlstring += "], \\\"yerrs\\\":[";
for(int i=0; i<g->GetN(); ++i){
psqlstring += std::to_string(g->GetEY()[i]) + ",";
}
psqlstring.pop_back(); // remove trailing ','
psqlstring += "]";
}
psqlstring += ", \\\"version\\\":"; //+ version
// inline next version number by querying for it
std::string cmd = "psql -At -c \"SELECT MAX((values->>'version')::integer)+1 FROM data WHERE name='pure_curve' "
"AND ledname='" + ledname + "'\" | tr -d '\n' ";
std::cout<<psqlstring<<std::flush;
system(cmd.c_str());
std::cout<<"}' );\" "<<std::endl;
return 0;
}