13 unsigned short slatid;
14 unsigned short status;
20 const char* year =
"17sim",
21 const char* input =
"fPostStatus.txt",
26 TString option(opt), yr(year), storeTime;
29 std::cout <<
"year = " <<year <<std::endl;
30 if (yr.Contains(
"17sim"))
32 storeTime =
"2016-12-10 00:00:00";
36 else if (yr.Contains(
"17ofl"))
38 storeTime =
"2016-12-20 00:00:00";
42 else { std::cout <<
"Please specify valid year tag\n"; exit; }
44 if (readdate > 0) date = readdate;
45 if (readtime > 0) time = readtime;
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 fpostStatus_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,
"%hu %hu", &in[n].slatid, &in[n].status);
68 printf(
"slatId=%3d status=%1d\n", in[n].slatid, in[n].status);
71 printf(
"Found %d entries\n", n);
73 printf(
"File Closed\n", n);
78 if (option.Contains(
"writedb"))
80 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
83 StDbTable* dbtable = node->addDbTable(
"fpostStatus");
84 mgr->setStoreTime(storeTime.Data());
85 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
86 if (yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
87 mgr->storeDbTable(dbtable);
88 std::cout <<
"INFO: table saved to database" << std::endl;
93 if (option.Contains(
"readdb"))
95 std::cout <<
"INFO: Reading database" << std::endl;
96 gSystem->Unsetenv(
"DB_ACCESS_MODE");
101 dbMk->SetDateTime(date, time);
102 if (yr.Contains(
"ofl")) { dbMk->SetFlavor(
"ofl"); }
103 else if (yr.Contains(
"sim")) { dbMk->SetFlavor(
"sim"); }
108 DB = dbMk->GetDataBase(
"Calibrations/fps/fpostStatus");
109 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
111 St_fpostStatus *dataset = 0;
112 dataset = (St_fpostStatus*) DB->
Find(
"fpostStatus");
113 if (!dataset) { std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
return; }
114 Int_t rows = dataset->GetNRows();
115 if (rows > 1) std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
118 dbMk->GetValidity((
TTable*)dataset, val);
119 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
120 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] " << std::endl;
122 fpostStatus_st *table = (fpostStatus_st*)dataset->GetTable();
123 for (Int_t i = 0; i < rows; i++)
125 std::cout << Form(
"Row=%3d slatid=%3d status=%1d\n", i, table[i].slatid, table[i].status);
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