13 unsigned short slatid;
21 const char* year =
"17_2_ofl",
22 const char* input =
"fPostMap2.txt")
25 TString option(opt), yr(year), storeTime;
28 std::cout <<
"year = " <<year <<std::endl;
29 if (yr.Contains(
"17sim"))
31 storeTime =
"2016-12-10 00:00:01";
35 else if (yr.Contains(
"17ofl"))
37 storeTime =
"2016-12-20 00:00:01";
41 else if (yr.Contains(
"17_2_ofl"))
43 storeTime =
"2017-05-03 15:40:00";
47 else { std::cout <<
"Please specify valid year tag\n"; exit; }
48 std::cout <<
"Opt =" << opt <<
"\n";
49 std::cout <<
"write = " << option.Contains(
"writedb") <<
"\n";
50 std::cout <<
"storetime = " << storeTime <<
"\n";
51 std::cout <<
"date, time = " << date <<
" "<< time <<
"\n";
53 gROOT->Macro(
"./loadlib.C");
57 const Int_t MAX_DB_INDEX = 241;
58 fpostMap_st in[MAX_DB_INDEX];
60 FILE *FP = fopen(input,
"r");
61 if (!FP) { printf(
"Could not open %s\n", input); exit; }
62 printf(
"\nReading %s\n", input);
66 while (fgets(line, 1000, FP) != NULL)
68 sscanf(line,
"%d %d %d ",
69 &in[n].slatid, &in[n].QTaddr, &in[n].QTch);
70 printf(
"slatId=%3d QTaddr=%d QTch=%2d\n",
71 in[n].slatid, in[n].QTaddr, in[n].QTch);
74 printf(
"Found %d entries\n", n);
79 if (option.Contains(
"writedb"))
81 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
84 StDbTable* dbtable = node->addDbTable(
"fpostMap");
85 mgr->setStoreTime(storeTime.Data());
86 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
87 if (yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
88 mgr->storeDbTable(dbtable);
89 std::cout <<
"INFO: table saved to database" << std::endl;
94 if (option.Contains(
"readdb"))
96 std::cout <<
"INFO: Reading database" << std::endl;
97 gSystem->Unsetenv(
"DB_ACCESS_MODE");
102 dbMk->SetDateTime(date, time);
103 if (yr.Contains(
"ofl")) { dbMk->SetFlavor(
"ofl"); }
104 else if (yr.Contains(
"sim")) { dbMk->SetFlavor(
"sim"); }
109 DB = dbMk->GetDataBase(
"Geometry/fps/fpostMap");
110 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
112 St_fpostMap *dataset = 0;
113 dataset = (St_fpostMap*) DB->
Find(
"fpostMap");
114 if (!dataset) { std::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
return; }
115 Int_t rows = dataset->GetNRows();
116 if (rows > 1) std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
119 dbMk->GetValidity((
TTable*)dataset, val);
120 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
121 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] " << std::endl;
123 fpostMap_st *table = (fpostMap_st*)dataset->GetTable();
124 for (Int_t i = 0; i < rows; i++)
126 std::cout << Form(
"Row=%3d slatid=%3d QTaddr=%d QTch=%2d\n",
127 i, table[i].slatid, table[i].QTaddr, table[i].QTch);
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