StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
table_reupload.C
1 //
2 // Script to re-upload database data from timestamp X to timestamp Y, also
3 // known as "annual db initialization procedure"
4 //
5 // Input parameters:
6 // - database name; typically Calibrations_{subsystem_name} or Geometry_{subsystem_name}. Ex: Calibrations_tpc
7 // - table name; please check http://www.star.bnl.gov/Browser/STAR/ for the list of your tables
8 // - flavor name; could be "ofl", "simu" and something else, specific to your subsystem
9 // - request timestamp; "FROM" timestamp
10 // - store timestamp; "TO" timestamp
11 //
12 // contact : "Dmitry Arkhipkin" <arkhipkin@bnl.gov>
13 // BNL office: (631) 344 4922
14 // skype: dmitry.arkhipkin
15 //
16 
17 void table_reupload(const char* fDbName = 0, const char* fTableName = 0, const char* fFlavorName = "ofl",
18  const char* fRequestTimestamp = "2011-01-01 00:00:00",
19  const char* fStoreTimestamp = "2012-01-01 00:00:00" ) {
20 
21  // real-life example :
22  // fDbName = "Calibrations_tpc";
23  // fTableName = "tpcGas";
24  // fFlavorName = "ofl"; // "ofl", "simu", other..
25  // fRequestTimestamp = "2010-05-05 00:00:00";
26  // fStoreTimestamp = "2011-05-05 00:00:00";
27 
28  if (!fDbName || !fTableName || !fFlavorName || !fRequestTimestamp || ! fStoreTimestamp) {
29  std::cerr << "ERROR: Missing initialization data, please check input parameters!\n";
30  return;
31  }
32 
33  gSystem->Setenv("DB_ACCESS_MODE", "write");
34 
35  // Load all required libraries
36  gROOT->Reset();
37  // moved this line to the calling script
38  //gROOT->Macro("LoadLogger.C");
39  gSystem->Load("St_base.so");
40  gSystem->Load("libStDb_Tables.so");
41  gSystem->Load("StDbLib.so");
42 
43 
44  // Initialize db manager
46  StDbConfigNode* node = mgr->initConfig(fDbName);
47  StDbTable* dbtable = node->addDbTable(fTableName);
48  //dbtable->setFlavor(fFlavorName);
49 
50  // read data for specific timestamp
51  mgr->setRequestTime(fRequestTimestamp);
52  mgr->fetchDbTable(dbtable);
53 
54  // output results
55  std::cout << "READ CHECK: " << dbtable->printCstructName() << " has data: " << (dbtable->hasData() ? "yes" : "no") << " (" << dbtable->GetNRows() << " rows)" << std::endl;
56 
57  if (!dbtable->hasData()) {
58  std::cout << "ERROR: This table has no data to reupload. Please try some other timestamp!";
59  return;
60  }
61 
62  char confirm[255];
63  std::string test_cnf;
64  std::cout << "ATTENTION: please confirm that you want to reupload " << fDbName << " / " << fTableName << ", " << fRequestTimestamp << " data with " << fStoreTimestamp << " timestamp.\n Type YES to proceed: ";
65  std::cin.getline(confirm,256);
66  test_cnf = confirm;
67  if (test_cnf != "YES") {
68  std::cout << "since you've typed \"" << test_cnf << "\" and not \"YES\", data won't be reuploaded." << std::endl;
69  return;
70  }
71 
72  // store data back with new timestamp
73  if (dbtable->hasData()) {
74  mgr->setStoreTime(fStoreTimestamp);
75  if (mgr->storeDbTable(dbtable)) {
76  std::cout << "SUCCESS: Data reupload complete for " << fDbName << " / " << fTableName << " [ flavor : " << fFlavorName << " ]"
77  << "\n" << "Data copied FROM " << fRequestTimestamp << " TO " << fStoreTimestamp << std::endl << std::endl;
78  } else {
79  std::cerr << "ERROR: Something went wrong. Please send error message text to DB Admin!" << std::endl;
80  }
81  }
82 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155