Installation.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/Hardware/Installation.h>
2 #include <cstdlib>
3 
4 namespace dbutils {
5  namespace hw {
6 
7  //**********************************************************************
8 
10  {
12  if (detid == novadaq::cnv::kNDOS) {
13  t = new nova::database::Table();
14  t->CreateFromDB("public","hardware_position","ifdbprod.fnal.gov",
15  "nova_hardware","5432","nova_reader");
16  t->SetIgnoreEnvVar(true);
18  t->SetValidityRange("detector",detName);
19  }
20 
21  return t;
22  }
23 
24  bool FEB::Installed(int detid, std::string dcmName, int dcmPort,
25  std::string& id, std::string ts)
26  {
28 
29  if (detid == novadaq::cnv::kNDOS) {
30  t->SetValidityRange("hw_type","FEB");
31  t->SetValidityRange("dcm_name",dcmName);
32  t->SetValidityRange("dcm_port",dcmPort);
33  std::string vld = "install_date < '" + ts + "' and (remove_date is NULL or remove_date > '" + ts + "')";
34  t->SetValiditySQL(vld);
35  t->LoadFromDB();
36  if (t->NRow() != 1) return false;
37  nova::database::Row* r = t->GetRow(0);
38  bool ok = r->Col("hw_id")->Get(id);
39  delete t;
40  return ok;
41  }
42 
43  return false;
44  }
45 
46  bool FEB::GetAllInstalled(int detid,
47  std::vector<std::string>& dcmName,
48  std::vector<int>& dcmPort,
49  std::vector<std::string>& febid, std::string ts)
50  {
52 
53  if (detid == novadaq::cnv::kNDOS) {
54  t->SetValidityRange("hw_type","FEB");
55  std::string vld = "install_date < '" + ts + "' and (remove_date is NULL or remove_date > '" + ts + "')";
56  t->SetValiditySQL(vld);
57  t->LoadFromDB();
58  if (t->NRow() == 0) return false;
60 
61  std::string dName;
63  int dPort;
64  bool ok=true;
65  for (int i=0; i<t->NRow(); ++i) {
66  r = t->GetRow(i);
67  ok &= r->Col("hw_id")->Get(id);
68  ok &= r->Col("dcm_name")->Get(dName);
69  ok &= r->Col("dcm_port")->Get(dPort);
70  if (ok) {
71  dcmName.push_back(dName);
72  dcmPort.push_back(dPort);
73  febid.push_back(id);
74  }
75  }
76  delete t;
77  return ok;
78  }
79 
80  return false;
81  }
82 
83  bool APD::Installed(int detid, std::string dcmName, int dcmPort,
84  std::string& id, std::string ts)
85  {
87 
88  if (detid == novadaq::cnv::kNDOS) {
89  t->SetValidityRange("hw_type","APD");
90  t->SetValidityRange("dcm_name",dcmName);
91  t->SetValidityRange("dcm_port",dcmPort);
92  std::string vld = "install_date < '" + ts + "' and (remove_date is NULL or remove_date > '" + ts + "')";
93  t->SetValiditySQL(vld);
94  t->LoadFromDB();
95  if (t->NRow() != 1) return false;
96  nova::database::Row* r = t->GetRow(0);
97  bool ok = r->Col("hw_id")->Get(id);
98  delete t;
99  return ok;
100  }
101 
102  return false;
103  }
104 
105  bool APD::GetAllInstalled(int detid,
106  std::vector<std::string>& dcmName,
107  std::vector<int>& dcmPort,
108  std::vector<std::string>& febid, std::string ts)
109  {
111 
112  if (detid == novadaq::cnv::kNDOS) {
113  t->SetValidityRange("hw_type","APD");
114  std::string vld = "install_date < '" + ts + "' and (remove_date is NULL or remove_date > '" + ts + "')";
115  t->SetValiditySQL(vld);
116  t->LoadFromDB();
117  if (t->NRow() == 0) return false;
119 
120  std::string dName;
121  std::string id;
122  int dPort;
123  bool ok=true;
124  for (int i=0; i<t->NRow(); ++i) {
125  r = t->GetRow(i);
126  ok &= r->Col("hw_id")->Get(id);
127  ok &= r->Col("dcm_name")->Get(dName);
128  ok &= r->Col("dcm_port")->Get(dPort);
129  if (ok) {
130  dcmName.push_back(dName);
131  dcmPort.push_back(dPort);
132  febid.push_back(id);
133  }
134  }
135  delete t;
136  return ok;
137  }
138 
139  return false;
140  }
141 
142  }
143 }
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
static std::string GetName(int id)
static nova::database::Table * PositionTable(int detid)
Definition: Installation.cpp:9
static bool GetAllInstalled(int detid, std::vector< std::string > &dcmName, std::vector< int > &dcmPort, std::vector< std::string > &id, std::string ts="now")
static bool Installed(int detid, std::string dcmName, int dcmPort, std::string &id, std::string ts="now")
Row * GetRow(int i)
Definition: Table.cpp:804
bool CreateFromDB(const char *schemaName, const char *tableName, const char *dbhost=0, const char *dbname=0, const char *dbport=0, const char *dbuser=0)
Definition: Table.cpp:104
bool SetValidityRange(std::string cname, T start, T end)
Definition: Table.h:206
static bool Installed(int detid, std::string dcmName, int dcmPort, std::string &id, std::string ts="now")
void SetValiditySQL(std::string cmd)
Definition: Table.h:195
static bool GetAllInstalled(int detid, std::vector< std::string > &dcmName, std::vector< int > &dcmPort, std::vector< std::string > &id, std::string ts="now")
Prototype Near Detector on the surface at FNAL.
void SetIgnoreEnvVar(bool f)
Definition: Table.h:56
bool Get(T &val) const
Definition: Column.h:53
struct Table Table
Definition: TexBuilder.h:2
TRandom3 r(0)
detName
Definition: mkDefs.py:107
Column & Col(int i)
Definition: Row.h:51
enum BeamMode string