43 #include <TSQLServer.h>
44 #include <TSQLResult.h>
59 Bool_t
HarpoRunConfig::GetRunConfig(Long_t nrun, const TString *DbUrl)
61 const char *tables[] = {
67 const char *dburl_default =
"mysql://llrharpo.in2p3.fr/harpo";
69 printf(
"GetRunConfig %ld\n",nrun);
71 TSQLServer *db = NULL;
72 if ( DbUrl == NULL ) {
73 const char *dburl = gSystem->Getenv(
"HARPO_DB_URL");
74 if ( dburl == NULL || strlen(dburl) == 0 )
75 dburl = dburl_default;
77 db = TSQLServer::Connect(dburl,
"reader",
"ro");
78 }
else if ( DbUrl->IsNull() ) {
79 std::cout <<
" NO database" << std::endl;
82 db = TSQLServer::Connect(DbUrl->Data(),
"reader",
"ro");
85 std::cout <<
" Error acess a database" << std::endl;
122 res = db->GetColumns(
"harpo", tables[itbl]);
124 while ((row = res->Next())) {
131 if ( fields.find(row->GetField(0)) == fields.end() ) {
133 pf->
ftype = row->GetField(1);
134 fields[row->GetField(0)] = *pf;
137 std::cout <<
"key " << row->GetField(0) <<
" exist" << std::endl;
143 }
while (tables[itbl] != NULL );
146 sprintf(sql,
"select * from %s t0 left join %s t1 on t0.run = t1.run where t0.run = %ld;",tables[0],tables[1],nrun);
148 if ( db->SelectDataBase(
"harpo") != 0 )
return rec_found;
149 res = db->Query(sql);
151 int nrows = res->GetRowCount();
154 if (nrows != 1)
return rec_found;
158 int nfields = res->GetFieldCount();
165 for (
int j = 0; j < nfields; j++) {
167 if (row->GetFieldLength(j) > 0 )
168 fields[res->GetFieldName(j)].fval = row->GetField(j);
186 printf(
"No run info or DB read error\n");
188 for (dbFields::iterator it=
fields.begin(); it!=
fields.end(); ++it) {
189 std::cout << it->first <<
" ("<< it->second.ftype <<
")" << std::endl;
197 printf(
"No run info or DB read error\n");
199 for (dbFields::iterator it=
fields.begin(); it!=
fields.end(); ++it) {
200 std::cout << it->first <<
" = " << it->second.fval << std::endl;
214 return Lookup(TString(field));
219 dbFields::iterator it =
fields.find(field);
220 if ( it !=
fields.end() ) {
221 val = it->second.fval;
229 return GetVal(TString(field),val);
234 dbFields::iterator it =
fields.find(field);
235 if ( it !=
fields.end() ) {
236 type = it->second.ftype;
244 return GetType(TString(field),type);
252 printf(
"UpdateRunConfig NO IMPLEMENTED\n");
void list()
list all filds found which his types
Get Run Configuration info by run number. The class query MySQL databe use GetRunConfig Method Only t...
void print()
Print values of all founded fields.
Bool_t Lookup(const TString field)
Lookup filed exist.
Bool_t GetVal(const TString field, TString &val)
Return value of existing field in Tstring.
Bool_t GetType(const TString field, TString &type)
Return Type of field in Tstring.