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 = "Geometry_fms", const char* fTableName = "fmsChannelGeometry", const char* fFlavorName = "ofl",
18  const char* fRequestTimestamp = "2014-02-22 00:00:00",
19  const char* fStoreTimestamp = "2014-12-20 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->Macro("LoadLogger.C");
37  gSystem->Load("St_base.so");
38  gSystem->Load("libStDb_Tables.so");
39  gSystem->Load("StDbLib.so");
40 
41 
42  // Initialize db manager
44  StDbConfigNode* node = mgr->initConfig(fDbName);
45  StDbTable* dbtable = node->addDbTable(fTableName);
46  dbtable->setFlavor(fFlavorName);
47 
48  // read data for specific timestamp
49  mgr->setRequestTime(fRequestTimestamp);
50  mgr->fetchDbTable(dbtable);
51 
52  // output results
53  std::cout << "READ CHECK: " << dbtable->printCstructName() << " has data: " << (dbtable->hasData() ? "yes" : "no") << " (" << dbtable->GetNRows() << " rows)" << std::endl;
54 
55  if (!dbtable->hasData()) {
56  std::cout << "ERROR: This table has no data to reupload. Please try some other timestamp!";
57  return;
58  }
59 
60  char confirm[255];
61  std::string test_cnf;
62  std::cout << "ATTENTION: please confirm that you want to reupload " << fDbName << " / " << fTableName << ", " << fRequestTimestamp << " data with " << fStoreTimestamp << " timestamp.\n Type YES to proceed: ";
63  std::cin.getline(confirm,256);
64  test_cnf = confirm;
65  if (test_cnf != "YES") {
66  std::cout << "since you've typed \"" << test_cnf << "\" and not \"YES\", data won't be reuploaded." << std::endl;
67  return;
68  }
69 
70  // store data back with new timestamp
71  if (dbtable->hasData()) {
72  mgr->setStoreTime(fStoreTimestamp);
73  if (mgr->storeDbTable(dbtable)) {
74  std::cout << "SUCCESS: Data reupload complete for " << fDbName << " / " << fTableName << " [ flavor : " << fFlavorName << " ]"
75  << "\n" << "Data copied FROM " << fRequestTimestamp << " TO " << fStoreTimestamp << std::endl << std::endl;
76  } else {
77  std::cerr << "ERROR: Something went wrong. Please send error message text to DB Admin!" << std::endl;
78  }
79  }
80 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155