StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
read_table_fgt.cc
1 #include <ctime>
2 #include <iostream>
3 
4 #include "fgtGain.h"
5 
6 #include "StDbManager.hh"
7 #include "StDbConfigNode.hh"
8 #include "StDbTable.h"
9 
10 int main () {
11 
12  const char* fDbName = "Calibrations_fgt"; // Database bame
13  const char* fTableName = "fgtGain"; // c-structure name that is same as table in database
14  const char* fFlavorName = "ofl"; // flavor name, like 'ofl', 'sim'
15  time_t funixTime = time(0); // requested timestamp
16  int fDebug = 0; // debug mode..
17 
18  if ( funixTime==0 ) {
19  std::cout << " No timestamp specified " << std::endl;
20  return 0;
21  }
22 
23  if ( fDbName == 0 ){
24  std::cout << "No database name specified" << std::endl;
25  return 0;
26  }
27 
28  if ( fTableName == 0 ){
29  std::cout << "No table name specified" << std::endl;
30  return 0;
31  }
32 
33  StDbManager* mgr = StDbManager::Instance(); // Get the singleton manager
34  if ( fDebug == 1 ){
35  mgr->setVerbose(fDebug); // Set verbose mode for debuging for fDebug=1
36  }
37 
38  StDbConfigNode* configNode = mgr->initConfig(fDbName); // Connect to the db & get an empty container
39 
40  StDbTable* dbtable = configNode->addDbTable(fTableName);
41 
42  if ( dbtable == 0 ){ // If table asigned by fTableName does not exist in Dababase
43  std::cout << " No Table : " << fTableName << std::endl; // program is stoped and exit from this function.
44  return 0;
45  }
46 
47  if ( fFlavorName != 0 ){
48  dbtable->setFlavor(fFlavorName);
49  std::cout << "Flavor is set as " << fFlavorName << " by StDbTable::setFlavor." << std::endl;
50  } else {
51  std::cout << "Flavor is NOT assigned. Default value is set as 'ofl'. " << std::endl;
52  dbtable->setFlavor("ofl");
53  }
54 
55  mgr->setRequestTime(funixTime);
56 
57  mgr->fetchDbTable(dbtable); // Fetch the data from Database
58 
59  fgtGain_st* gain = (fgtGain_st*)dbtable->GetTable();
60  std::cout << gain->Gain[0] << std::endl;
61 
62  return 1;
63 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155