11 #include <framework/database/DBImportObjPtr.h>
12 #include <trg/cdc/dbobjects/CDCTriggerNeuroConfig.h>
20 for (
int i = 1; i < argc; ++i)
21 this->tokens.push_back(std::string(argv[i]));
23 const std::string& getCmdOption(
const std::string& option)
const
25 std::vector<std::string>::const_iterator itr;
26 itr = std::find(this->tokens.begin(), this->tokens.end(), option);
27 if (itr != this->tokens.end() && ++itr != this->tokens.end()) {
30 static const std::string empty_string(
"");
33 bool cmdOptionExists(
const std::string& option)
const
35 return std::find(this->tokens.begin(), this->tokens.end(), option)
36 != this->tokens.end();
39 std::vector <std::string> tokens;
44 int main(
int argc,
char** argv)
51 std::vector<CDCTriggerNeuroConfig::B2FormatLine> b2lines;
52 std::string configfilename =
"";
63 if (input.cmdOptionExists(
"-h")) {
64 std::cout <<
"A small tool to create ConDB payloads for the Neurotrigger." << std::endl;
65 std::cout <<
"Usage: \% trg-cdc-neurotrigger-writedb -f example.conf" << std::endl;
67 const std::string&
filename = input.getCmdOption(
"-f");
76 std::ifstream confile;
78 confile.open(configfilename, std::ifstream::in);
80 std::cout <<
"ERROR! While opening file: " << configfilename <<
" Error code: " <<
e << std::endl;
84 if (!confile.is_open()) {
85 std::cout <<
"ERROR! While opening file: " << configfilename << std::endl;
88 while (std::getline(confile, line_all)) {
89 std::size_t hashtag = line_all.find(
'#');
90 std::string line = line_all.substr(0, hashtag);
94 if (line.length() < 3) {
98 if (line.find(
'=') == std::string::npos) {
101 par = line.substr(0, line.find(
'='));
102 par.erase(std::remove(par.begin(), par.end(),
' '), par.end());
104 if (par ==
"nniov_run_start") {
105 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
106 nniov_run_start = std::stoi(key);
109 if (par ==
"nniov_run_end") {
110 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
111 nniov_run_end = std::stoi(key);
114 if (par ==
"nniov_exp_start") {
115 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
116 nniov_exp_start = std::stoi(key);
119 if (par ==
"nniov_exp_end") {
120 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
121 nniov_exp_end = std::stoi(key);
124 if (par ==
"nnname") {
126 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
131 if (par ==
"nnnote") {
133 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
138 if (par ==
"nnpath") {
140 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
145 if (par ==
"fwname") {
147 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
152 if (par ==
"fwnote") {
154 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
160 if (par ==
"ppnote") {
162 key = line.substr((line.find(
'"') + 1), (line.find(
'"', line.find(
'"') + 1) - 1 - line.find(
'"')));
167 if (par ==
"ppbool") {
168 if (line.find(
"alse") != std::string::npos) {
170 }
else if (line.find(
"rue") != std::string::npos) {
173 std::cout <<
"ERROR!: Wrong key argument for parameter ppbool:" << line << std::endl;
178 if (par ==
"addb2formatline") {
180 std::stringstream ss;
181 ss << line.substr((line.find(
'(') + 1), (line.find(
')') - 1 - line.find(
'(')));
183 std::string startstr;
185 std::string offsetstr;
186 std::string description;
187 std::getline(ss, uid,
',');
188 std::getline(ss, startstr,
',');
189 std::getline(ss, endstr,
',');
190 std::getline(ss, offsetstr,
',');
191 std::getline(ss, description,
'\n');
192 nc->
addB2FormatLine(std::stoi(startstr), std::stoi(endstr), std::stoi(offsetstr), uid.substr((uid.find(
'"') + 1), (uid.find(
'"',
193 uid.find(
'"') + 1) - 1 - uid.find(
'"'))), description.substr((description.find(
'"') + 1), (description.find(
'"',
194 description.find(
'"') + 1) - 1 - description.find(
'"'))));
200 IntervalOfValidity iov(nniov_exp_start, nniov_run_start, nniov_exp_end, nniov_run_end);