13 unsigned short slatid;
24 void fPostPosition_db(
26 const char* year =
"17sim",
27 const char* input =
"fPostPosition.txt")
30 TString option(opt), yr(year), storeTime;
33 std::cout <<
"year = " <<year <<std::endl;
34 if (yr.Contains(
"17sim"))
36 storeTime =
"2016-12-10 00:00:01";
40 else if (yr.Contains(
"17ofl"))
42 storeTime =
"2016-12-20 00:00:01";
46 else { std::cout <<
"Please specify valid year tag\n"; exit; }
47 std::cout <<
"Opt =" << opt <<
"\n";
48 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
49 std::cout <<
"storetime = " << storeTime <<
"\n";
50 std::cout <<
"date, time = " << date <<
" "<< time <<
"\n";
52 gROOT->Macro(
"./loadlib.C");
56 const Int_t MAX_DB_INDEX = 241;
57 fpostPosition_st in[MAX_DB_INDEX];
59 FILE *FP = fopen(input,
"r");
60 if (!FP) { printf(
"Could not open %s\n", input); exit; }
61 printf(
"\nReading %s\n", input);
65 while (fgets(line, 1000, FP) != NULL)
67 sscanf(line,
"%d %f %f %f %f %f %f %f ",
69 &in[n].length, &in[n].width, &in[n].thickness, &in[n].angle_xy,
70 &in[n].xoffset, &in[n].yoffset, &in[n].zoffset);
71 printf(
"Id=%3d D=%9.4f %9.4f %9.4f %9.4f X=%9.4f %9.4f %9.4f\n",
73 in[n].length, in[n].width, in[n].thickness, in[n].angle_xy,
74 in[n].xoffset, in[n].yoffset, in[n].zoffset);
77 printf(
"Found %d entries\n", n);
82 if (option.Contains(
"writedb"))
84 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
87 StDbTable* dbtable = node->addDbTable(
"fpostPosition");
88 mgr->setStoreTime(storeTime.Data());
89 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
90 if (yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
91 mgr->storeDbTable(dbtable);
92 std::cout <<
"INFO: table saved to database" << std::endl;
97 if (option.Contains(
"readdb"))
99 std::cout <<
"INFO: Reading database" << std::endl;
100 gSystem->Unsetenv(
"DB_ACCESS_MODE");
105 dbMk->SetDateTime(date, time);
106 if (yr.Contains(
"ofl")) { dbMk->SetFlavor(
"ofl"); }
107 else if (yr.Contains(
"sim")) { dbMk->SetFlavor(
"sim"); }
112 DB = dbMk->GetDataBase(
"Geometry/fps/fpostPosition");
113 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
115 St_fpostPosition* dataset = 0;
116 dataset = (St_fpostPosition*) DB->
Find(
"fpostPosition");
117 if (!dataset) { std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
return; }
118 Int_t rows = dataset->GetNRows();
119 if (rows > 1) std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
122 dbMk->GetValidity((
TTable*)dataset, val);
123 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
124 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] " << std::endl;
126 fpostPosition_st *table = dataset->GetTable();
127 for (Int_t i = 0; i < rows; i++)
129 std::cout << Form(
"Row=%3d slatid=%3d dim=%9.4f %9.4f %9.4f %9.4f offset=%9.4f %9.4f %9.4f\n",
131 table[i].length, table[i].width, table[i].thickness, table[i].angle_xy,
132 table[i].xoffset, table[i].yoffset, table[i].zoffset);
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
static StDbManager * Instance()
strdup(..) is not ANSI
virtual TDataSet * Find(const char *path) const