LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
tagConditionsTableInDB.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <cstdlib>
5 #include <ctime>
6 #include <getopt.h>
7 #include <string>
8 
10 
11 std::string dbHost = "";
12 std::string dbName = "";
13 std::string dbPort = "";
14 std::string tableName = "";
15 std::string detectorName = "";
16 std::string tagName = "";
17 bool override=false;
18 
19 void PrintUsage()
20 {
21  std::cout << "Usage: tagConditionsTableInDB [options]" << std::endl;
22  std::cout << "options:\n";
23  std::cout << "\t -h (--host) [dB host, REQUIRED]" << std::endl;
24  std::cout << "\t -n (--name) [dB name, REQUIRED]" << std::endl;
25  std::cout << "\t -p (--port) [dB port, REQUIRED]" << std::endl;
26  std::cout << "\t -d (--detector) [detector name, REQUIRED]" << std::endl;
27  std::cout << "\t -T (--tablename) [table name, REQUIRED]" << std::endl;
28  std::cout << "\t -t (--tag) [tag name, REQUIRED]" << std::endl;
29  std::cout << "\t -o (--override)" << std::endl;
30 }
31 
32 //------------------------------------------------------------
33 bool ParseCLArgs(int argc, char* argv[])
34 {
35  if (argc == 1) {
36  PrintUsage();
37  exit(0);
38  }
39 
40  struct option long_options[] = {
41  {"host", 1, 0, 'h'},
42  {"port", 1, 0, 'p'},
43  {"name", 1, 0, 'n'},
44  {"detector", 1, 0, 'd'},
45  {"tablename", 1, 0, 'T'},
46  {"tag", 1, 0, 't'},
47  {"override", 1, 0, 'o'},
48  {0,0,0,0}
49  };
50 
51  while (1) {
52  int optindx;
53  int c = getopt_long(argc,argv,"t:h:p:n:d:f:o",long_options,&optindx);
54 
55  if (c==-1) break;
56 
57  switch(c) {
58  case 'h':
59  dbHost = optarg;
60  break;
61  case 'p':
62  dbPort = optarg;
63  break;
64  case 'n':
65  dbName = optarg;
66  break;
67  case 'd':
68  detectorName = optarg;
69  break;
70  case 'T':
71  tableName = optarg;
72  break;
73  case 't':
74  tagName = optarg;
75  break;
76  case 'o':
77  override=true;
78  break;
79  default:
80  break;
81  }
82 
83  }
84 
85  if (optind<argc) {
86  std::cerr << "Unrecognized argument." << std::endl;
87  PrintUsage();
88  exit(0);
89  }
90 
91  if (tagName == "") {
92  std::cerr << "No tag name provided. Aborting." << std::endl;
93  exit(1);
94  }
95 
96  if (dbHost == "") {
97  std::cerr << "No value set for dB host. Aborting." << std::endl;
98  exit(0);
99  }
100  if (dbPort == "") {
101  std::cerr << "No value set for dB port. Aborting." << std::endl;
102  exit(0);
103  }
104  if (dbName == "") {
105  std::cerr << "No value set for dB name. Aborting." << std::endl;
106  exit(0);
107  }
108  if (tableName == "") {
109  std::cerr << "No value set for table name. Aborting." << std::endl;
110  exit(0);
111  }
112 
113  return true;
114 }
115 
116 //------------------------------------------------------------
117 
118 int main(int argc, char *argv[])
119 {
120  ParseCLArgs(argc, argv);
121 
122  nutools::dbi::Table* dbt;
123  try {
127  }
128  catch (std::runtime_error& e) {
129  std::cerr << e.what() << std::endl;
130  exit(1);
131  }
132 
133  std::cerr << "Tagging validity dB table " << dbName << " in database with tag "
134  << tagName << std::endl;
135 
136  if (!dbt->Tag(tagName,override))
137  std::cerr << "Tag failed!" << std::endl;
138 
139  return 0;
140 }
141 
bool ParseCLArgs(int argc, char *argv[])
std::string dbPort
void PrintUsage()
std::string dbName
std::string detectorName
std::string tagName
std::string dbHost
int main(int argc, char *argv[])
bool Tag(std::string tn="", bool override=false)
Definition: Table.cpp:2053
Float_t e
Definition: plot.C:35
std::string tableName
map< int, array< map< int, double >, 2 >> Table
Definition: plot.C:18