4 void fpsMap_db(
char* opt=
"",
char* year=
"15sim",
char* input=
"fpsmap.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:3";
11 date = 20141221; time = 0;
12 }
else if(yr.Contains(
"15sim")){
13 storeTime=
"2014-12-10 00:00:01";
14 date = 20141210; time = 1;
15 }
else if(yr.Contains(
"17ofl")){
16 storeTime=
"2016-12-20 00:00:00";
17 date = 20161220; time = 0;
18 }
else if(yr.Contains(
"17sim")){
19 storeTime=
"2016-12-10 00:00:00";
20 date = 20161210; time = 0;
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 fpsMap_st in[MAX_DB_INDEX];
33 for(
int i=0; i<MAX_DB_INDEX; i++){
39 FILE *FP = fopen(input,
"r");
40 if(!FP) { printf(
"Could not open %s\n",input); exit;}
41 printf(
"Reading %s\n",input);
42 char line[1000], nw[10], dc[10], posi[10];
43 int id,q,l,s,sipm,sipmbd,feebd,tbox,tgrp,qtaddr,qtch,cbl;
45 while(fgets(line,1000,FP)!=NULL){
46 sscanf(line,
"%d %d %d %d %d %s %d %d %d %d",
56 for(
int i=0; i<MAX_DB_INDEX; i++){
57 printf(
"Id=%3d QTaddr=%1d QTch=%2d\n",in[i].slatid,in[i].QTaddr,in[i].QTch);
59 printf(
"Found %d entries\n",n);
61 if(option.Contains(
"writedb")) {
62 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
65 StDbTable* dbtable = node->addDbTable(
"fpsMap");
66 mgr->setStoreTime(storeTime.Data());
67 dbtable->
SetTable((
char*)&in, MAX_DB_INDEX);
68 if(yr.Contains(
"sim")) dbtable->setFlavor(
"sim");
69 mgr->storeDbTable(dbtable);
70 std::cout <<
"INFO: table saved to database" << std::endl;
73 std::cout <<
"INFO: Reading database" << std::endl;
74 gSystem->Unsetenv(
"DB_ACCESS_MODE");
78 dbMk->SetDateTime(date,time);
79 if(yr.Contains(
"ofl")) {dbMk->SetFlavor(
"ofl");}
80 else if(yr.Contains(
"sim")) {dbMk->SetFlavor(
"sim");}
84 DB = dbMk->GetDataBase(
"Geometry/fps/fpsMap");
85 if (!DB) std::cout <<
"ERROR: no table found in db, or malformed local db config" << std::endl;
86 St_fpsMap *dataset = 0;
87 dataset = (St_fpsMap*) DB->
Find(
"fpsMap");
89 td::cout <<
"ERROR: dataset does not contain requested table" << std::endl;
92 Int_t rows = dataset->GetNRows();
94 std::cout <<
"INFO: found INDEXED table with " << rows <<
" rows" << std::endl;
97 dbMk->GetValidity((
TTable*)dataset,val);
98 std::cout <<
"Dataset validity range: [ " << val[0].GetDate() <<
"." << val[0].GetTime() <<
" - "
99 << val[1].GetDate() <<
"." << val[1].GetTime() <<
" ] "
101 fpsMap_st *table = dataset->GetTable();
102 for (Int_t i = 0; i < rows; i++) {
103 std::cout << Form(
"Row=%4d slatid=%3d QTaddr=%2d QTch=%2d\n",i,
105 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