12 const char* year =
"17sim",
13 const char* input =
"fPostSlatId.txt")
16 TString option(opt), yr(year), storeTime;
19 std::cout <<
"year = " <<year <<std::endl;
20 if (yr.Contains(
"17sim"))
22 storeTime =
"2016-12-10 00:00:00";
26 else if (yr.Contains(
"17ofl"))
28 storeTime =
"2016-12-20 00:00:01";
32 else { std::cout <<
"Please specify valid year tag\n"; exit; }
33 std::cout <<
"Opt =" << opt <<
"\n";
34 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
35 std::cout <<
"storetime = " << storeTime <<
"\n";
36 std::cout <<
"date, time = " << date <<
" "<< time <<
"\n";
38 gROOT->Macro(
"./loadlib.C");
42 const Int_t MAX_DB_INDEX = 241;
43 fpostSlatId_st in[MAX_DB_INDEX];
45 FILE *FP = fopen(input,
"r");
46 if (!FP) { printf(
"Could not open %s\n", input); exit; }
47 printf(
"\nReading %s\n", input);
51 while (fgets(line, 1000, FP) != NULL)
53 sscanf(line,
"%d %d %d %d ",
54 &in[n].slatid, &in[n].quad, &in[n].layer, &in[n].slat);
55 printf(
"slatId=%3d quad=%2d layer=%2d slat=%2d\n",
56 in[n].slatid, in[n].quad, in[n].layer, in[n].slat);
59 printf(
"Found %d entries\n", n);
63 if (option.Contains(
"writedb"))
65 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
68 StDbTable* dbtable = node->addDbTable(
"fpostSlatId");
69 mgr->setStoreTime(storeTime.Data());
70 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
71 if (yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
72 mgr->storeDbTable(dbtable);
73 std::cout <<
"INFO: table saved to database" << std::endl;
78 if (option.Contains(
"readdb"))
80 std::cout <<
"INFO: Reading database" << std::endl;
81 gSystem->Unsetenv(
"DB_ACCESS_MODE");
86 dbMk->SetDateTime(date, time);
87 if (yr.Contains(
"ofl")) { dbMk->SetFlavor(
"ofl"); }
88 else if (yr.Contains(
"sim")) { dbMk->SetFlavor(
"sim"); }
93 DB = dbMk->GetDataBase(
"Geometry/fps/fpostSlatId");
94 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
96 St_fpostSlatId *dataset = 0;
97 dataset = (St_fpostSlatId*) DB->
Find(
"fpostSlatId");
98 if (!dataset) { std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
return; }
99 Int_t rows = dataset->GetNRows();
100 if (rows > 1) std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
103 dbMk->GetValidity((
TTable*)dataset, val);
104 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
105 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] " << std::endl;
107 fpostSlatId_st *table = (fpostSlatId_st*)dataset->GetTable();
109 for (Int_t i = 0; i < rows; i++)
111 std::cout << Form(
"Row=%3d slatid=%3d quad=%2d layer=%2d slat=%2d\n",
112 i, table[i].slatid, table[i].quad, table[i].layer, table[i].slat);
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