4 void fpsPosition_db(
char* opt=
"",
char* year=
"15ofl",
char* input=
"fpsgeom_run15_20170925.txt") {
5 TString option(opt), yr(year);
8 std::cout <<
"year = " << year <<
"\n";
9 if(yr.Contains(
"15ofl")){
10 storeTime=
"2014-12-20 00:00:05";
11 date = 20141225; time = 1;
12 }
else if(yr.Contains(
"15sim")){
13 storeTime=
"2014-12-10 00:00:00";
14 date = 20141215; time = 0;
15 }
else if(yr.Contains(
"17ofl")){
16 storeTime=
"2016-12-20 00:00:02";
17 date = 20161225; time = 0;
18 }
else if(yr.Contains(
"17sim")){
19 storeTime=
"2016-12-10 00:00:01";
20 date = 20161210; time = 1;
22 std::cout <<
"Please specify valid year tag\n"; exit;
24 std::cout <<
"Opt =" << opt <<
"\n";
25 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
26 std::cout <<
"storetime =" << storeTime <<
"\n";
27 std::cout <<
"date,time =" << date <<
" "<< time <<
"\n";
29 gROOT->Macro(
"./loadlib.C");
31 const Int_t MAX_DB_INDEX = 252;
32 fpsPosition_st in[MAX_DB_INDEX];
34 FILE *FP = fopen(input,
"r");
35 if(!FP) { printf(
"Could not open %s\n",input); exit;}
36 printf(
"Reading %s\n",input);
39 while(fgets(line,1000,FP)!=NULL){
40 sscanf(line,
"%d %d %d %d %f %f %f %f %f %f",
41 &in[n].slatid,&q,&l,&s,
42 &in[n].xwidth, &in[n].ywidth, &in[n].zwidth,
43 &in[n].xoffset, &in[n].yoffset, &in[n].zoffset);
44 printf(
"Id=%3d Q=%3d L=%3d S=%3d D=%9.4f %9.4f %9.4f X=%9.4f %9.4f %9.4f\n",
46 in[n].xwidth, in[n].ywidth, in[n].zwidth,
47 in[n].xoffset, in[n].yoffset, in[n].zoffset);
50 printf(
"Found %d entries\n",n);
52 if(option.Contains(
"writedb")) {
53 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
56 StDbTable* dbtable = node->addDbTable(
"fpsPosition");
57 mgr->setStoreTime(storeTime.Data());
58 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
59 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
60 mgr->storeDbTable(dbtable);
61 std::cout <<
"INFO: table saved to database" << std::endl;
64 std::cout <<
"INFO: Reading database" << std::endl;
65 gSystem->Unsetenv(
"DB_ACCESS_MODE");
69 dbMk->SetDateTime(date,time);
70 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
71 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
75 DB = dbMk->GetDataBase(
"Geometry/fps/fpsPosition");
76 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
77 St_fpsPosition *dataset = 0;
78 dataset = (St_fpsPosition*) DB->
Find(
"fpsPosition");
80 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
83 Int_t rows = dataset->GetNRows();
85 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
88 dbMk->GetValidity((
TTable*)dataset,val);
89 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
90 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
92 fpsPosition_st *table = dataset->GetTable();
93 for (Int_t i = 0; i < rows; i++) {
94 std::cout << Form(
"Row=%4d slatid=%3d x=%9.4f %9.4f %9.4f d=%9.4f %9.4f %9.4f\n",i,
96 table[i].xwidth,table[i].ywidth,table[i].zwidth,
97 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