4 void fms_db_qtmap(
char* opt =
"readdb writetext",
int year = 15) {
7 std::cout <<
"Opt =" << opt <<
"\n";
8 std::cout <<
"testinput = " << option.Contains(
"testinput") <<
"\n";
9 std::cout <<
"readtext = " << option.Contains(
"readtext") <<
"\n";
10 std::cout <<
"readdb = " << option.Contains(
"readdb") <<
"\n";
11 std::cout <<
"writedb = " << option.Contains(
"writedb") <<
"\n";
12 std::cout <<
"writetext = " << option.Contains(
"writetext") <<
"\n";
18 std::cout <<
"year = " << year <<
"\n";
20 filename=
"qtmap_run8.txt";
21 storeTime=
"2007-11-09 00:00:00";
25 filename=
"qtmap2009V1.txt";
26 storeTime=
"2008-11-09 00:00:00";
30 filename=
"qtmap2009V1.txt";
31 storeTime=
"2014-12-20 00:00:00";
37 std::cout <<
"Please specify year\n";
40 std::cout <<
"filename =" << filename <<
"\n";
41 std::cout <<
"storetime =" << storeTime <<
"\n";
42 std::cout <<
"date,time =" << date <<
" "<< time <<
"\n";
44 gROOT->Macro(
"LoadLogger.C");
45 gSystem->Load(
"St_base.so");
46 gSystem->Load(
"libStDb_Tables.so");
47 gSystem->Load(
"StDbLib.so");
50 const Int_t MAX_QT_MAP = 2;
53 fmsQTMap_st qtmap[MAX_QT_MAP];
55 if(option.Contains(
"testinput")){
57 qtmap[0].qtCrate[0][0][0] = 15;
58 qtmap[0].qtSlot[0][0][0] = 15;
59 qtmap[0].qtChannel[0][0][0] = 15;
61 qtmap[1].qtCrate[0][0][0] = 17;
62 qtmap[1].qtSlot[0][0][0] = 17;
63 qtmap[1].qtChannel[0][0][0] = 17;
66 if(option.Contains(
"readtext")){
67 char* file=filename.Data();
69 int rns,rpp,rrow,rcol,rqt,rcrt,rch;
70 cout <<
"Reading "<<file<<
"\n";
71 if(fp=fopen(file,
"r")){
72 for(
int ns=0; ns<2; ns++){
73 for(
int pp=0; pp<2; pp++){
74 for(
int row=0; row<20; row++){
75 for(
int col=0; col<16; col++){
76 if(!feof(fp)) fscanf(fp,
"%d %d %d %d %d %d %d",&rns,&rpp,&rrow,&rcol,&rqt,&rcrt,&rch);
78 if(rns == -1 && rpp == -1 && rrow == -1 && rcol == -1){
79 qtmap[ns].qtCrate[pp][row][col] = 0;
80 qtmap[ns].qtSlot[pp][row][col] = 0;
81 qtmap[ns].qtChannel[pp][row][col] = 0;
83 if(rns !=ns +1) cout <<
"Error ns# ="<<rns <<
" "<<ns +1<<
"\n";
84 if(rpp !=pp +1) cout <<
"Error pp# ="<<rpp <<
" "<<pp +1<<
"\n";
85 if(rrow!=row+1) cout <<
"Error row# ="<<rrow<<
" "<<row+1<<
"\n";
86 if(rcol!=col+1) cout <<
"Error col# ="<<rcol<<
" "<<col+1<<
"\n";
87 qtmap[ns].qtCrate[pp][row][col] = rqt;
88 qtmap[ns].qtSlot[pp][row][col] = rcrt;
89 qtmap[ns].qtChannel[pp][row][col] = rch;
99 if(option.Contains(
"readdb")){
100 gSystem->Unsetenv(
"DB_ACCESS_MODE");
101 gSystem->Unsetenv(
"DB_SERVER_LOCAL_CONFIG");
103 gSystem->Load(
"StChain");
104 gSystem->Load(
"StBFChain");
105 gSystem->Load(
"StUtilities");
106 gSystem->Load(
"StIOMaker");
107 gSystem->Load(
"StarClassLibrary");
108 gSystem->Load(
"St_Tables");
109 gSystem->Load(
"StDbLib");
110 gSystem->Load(
"StDbBroker");
111 gSystem->Load(
"St_db_Maker");
115 dbMk->SetDateTime(date,time);
116 dbMk->SetFlavor(
"ofl");
125 DB = dbMk->GetInputDB(
"Calibrations/fms/mapping");
126 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
129 St_fmsQTMap *dbmap = 0;
130 dbmap = (St_fmsQTMap*) DB->
Find(
"fmsQTMap");
133 std::cout <<
"Reading fmsQTMap table\n";
134 fmsQTMap_st *qttable = dbmap->GetTable();
135 memcpy(qtmap,qttable,
sizeof(qtmap));
137 std::cout <<
"WARNING: No data in fmsQTMap table (wrong timestamp?). Nothing to return, then.\n";
141 if(option.Contains(
"writetext")){
143 char* file=filename.Data();
146 cout <<
"Writing "<<file<<
"\n";
147 if(fp=fopen(file,
"w")){
148 for(
int ns=0; ns<2; ns++){
149 for(
int pp=0; pp<2; pp++){
150 for(
int row=0; row<20; row++){
151 for(
int col=0; col<16; col++){
152 if(qtmap[ns].qtCrate[pp][row][col] ==0 &&
153 qtmap[ns].qtSlot[pp][row][col] ==0 &&
154 qtmap[ns].qtChannel[pp][row][col] ==0 ){
155 if(year==8) fprintf(fp,
"%3d %2d %3d %3d %3d %3d %3d\n",-1,-1,-1,-1,-1,-1,-1);
156 if(year==9) fprintf(fp,
"%3d %3d %4d %4d %4d %4d %4d\n",-1,-1,-1,-1,-1,-1,-1);
158 if(year==8) fprintf(fp,
"%3d %2d %3d %3d %3d %3d %3d\n",ns+1,pp+1,row+1,col+1,
159 qtmap[ns].qtCrate[pp][row][col],
160 qtmap[ns].qtSlot[pp][row][col],
161 qtmap[ns].qtChannel[pp][row][col]);
162 if(year==9||year==15) fprintf(fp,
"%3d %3d %4d %4d %4d %4d %4d\n",ns+1,pp+1,row+1,col+1,
163 qtmap[ns].qtCrate[pp][row][col],
164 qtmap[ns].qtSlot[pp][row][col],
165 qtmap[ns].qtChannel[pp][row][col]);
175 if(option.Contains(
"writedb")) {
176 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
177 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
180 StDbTable* table = node->addDbTable(
"fmsQTMap");
181 mgr->setStoreTime(storeTime.Data());
183 table->
SetTable((
char*)&qtmap,MAX_QT_MAP);
186 mgr->storeDbTable(table);
187 gSystem->Unsetenv(
"DB_ACCESS_MODE");
188 std::cout <<
"Done with database upload \n";
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