13 unsigned short slatid;
20 const char* year =
"17sim",
21 const char* input =
"fPostGain.txt")
24 TString option(opt), yr(year), storeTime;
27 std::cout <<
"year = " <<year <<std::endl;
28 if (yr.Contains(
"17sim"))
30 storeTime =
"2016-12-10 00:00:00";
34 else if (yr.Contains(
"17ofl"))
36 storeTime =
"2016-12-20 00:00:00";
40 else { std::cout <<
"Please specify valid year tag\n"; exit; }
41 std::cout <<
"Opt =" << opt <<
"\n";
42 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
43 std::cout <<
"storetime = " << storeTime <<
"\n";
44 std::cout <<
"date, time = " << date <<
" "<< time <<
"\n";
46 gROOT->Macro(
"./loadlib.C");
50 const Int_t MAX_DB_INDEX = 241;
51 fpostGain_st in[MAX_DB_INDEX];
53 FILE *FP = fopen(input,
"r");
54 if (!FP) { printf(
"Could not open %s\n", input); exit; }
55 printf(
"\nReading %s\n", input);
59 while (fgets(line, 1000, FP) != NULL)
61 sscanf(line,
"%d %f ", &in[n].slatid, &in[n].MIP);
62 printf(
"slatId=%3d MIP=%f\n", in[n].slatid, in[n].MIP);
65 printf(
"Found %d entries\n", n);
70 if (option.Contains(
"writedb"))
72 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
75 StDbTable* dbtable = node->addDbTable(
"fpostGain");
76 mgr->setStoreTime(storeTime.Data());
77 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
78 if (yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
79 mgr->storeDbTable(dbtable);
80 std::cout <<
"INFO: table saved to database" << std::endl;
85 if (option.Contains(
"readdb"))
87 std::cout <<
"INFO: Reading database" << std::endl;
88 gSystem->Unsetenv(
"DB_ACCESS_MODE");
93 dbMk->SetDateTime(date, time);
94 if (yr.Contains(
"ofl")) { dbMk->SetFlavor(
"ofl"); }
95 else if (yr.Contains(
"sim")) { dbMk->SetFlavor(
"sim"); }
100 DB = dbMk->GetDataBase(
"Calibrations/fps/fpostGain");
101 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
103 St_fpostGain *dataset = 0;
104 dataset = (St_fpostGain*) DB->
Find(
"fpostGain");
105 if (!dataset) { std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
return; }
106 Int_t rows = dataset->GetNRows();
107 if (rows > 1) std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
110 dbMk->GetValidity((
TTable*)dataset, val);
111 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
112 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] " << std::endl;
114 fpostGain_st *table = (fpostGain_st*)dataset->GetTable();
115 for (Int_t i = 0; i < rows; i++)
117 std::cout << Form(
"Row=%3d slatid=%3d MIP=%f\n", i, table[i].slatid, table[i].MIP);
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