4 void fms_db_map(
char* opt =
"readdb") {
8 TString storeTime =
"2007-11-09 00:00:00";
11 int readDate = 20141220;
16 std::cout <<
"Opt =" << opt <<
"\n";
17 std::cout <<
"testinput = " << option.Contains(
"testinput") <<
"\n";
18 std::cout <<
"readtext = " << option.Contains(
"readtext") <<
"\n";
19 std::cout <<
"readdb = " << option.Contains(
"readdb") <<
"\n";
20 std::cout <<
"writedb = " << option.Contains(
"writedb") <<
"\n";
21 std::cout <<
"writetext = " << option.Contains(
"writetext") <<
"\n";
23 gROOT->Macro(
"LoadLogger.C");
24 gSystem->Load(
"St_base.so");
25 gSystem->Load(
"libStDb_Tables.so");
26 gSystem->Load(
"StDbLib.so");
29 const Int_t MAX = 2000;
34 if(option.Contains(
"testinput")){
36 ppmap[0].ppPanel[0] = 2;
37 ppmap[0].ppColumn[0] = 7;
38 ppmap[0].ppRow[0] = 15;
40 ppmap[1].ppPanel[0] = 1;
41 ppmap[1].ppColumn[0] = 3;
42 ppmap[1].ppRow[0] = 7;
44 ppmap[2].ppPanel[0] = 2;
45 ppmap[2].ppColumn[0] = 20;
46 ppmap[2].ppRow[0] = 15;
48 ppmap[3].ppPanel[0] = 1;
49 ppmap[3].ppColumn[0] = 13;
50 ppmap[3].ppRow[0] = 9;
53 int module[4] = {1,3,2,4};
54 int maxch[4] = {578,578,288,288};
56 if(option.Contains(
"readtext")){
57 char* file=
"qtmap2pp.txt";
59 int rmod,rch,pp,col,row;
60 cout <<
"Reading "<<file<<
"\n";
61 if(fp=fopen(file,
"r")){
62 for(
int mod=0; mod<4; mod++){
63 for(
int ch=0; ch<maxch[module[mod]-1]; ch++){
64 if(!feof(fp)) fscanf(fp,
"%d %d %d %d %d",&rmod,&rch,&pp,&row,&col);
66 if(rmod!=module[mod]) cout <<
"Error mod# ="<<rmod<<
" "<<module[mod]<<
"\n";
67 if(rch !=ch +1) cout <<
"Error ch# ="<<rch <<
" "<<ch+1<<
"\n";
68 ppmap[mod].ppPanel[ch]=pp;
69 ppmap[mod].ppRow[ch]=row;
70 ppmap[mod].ppColumn[ch]=col;
77 if(option.Contains(
"readdb")){
78 gSystem->Load(
"StChain");
79 gSystem->Load(
"StBFChain");
80 gSystem->Load(
"StUtilities");
81 gSystem->Load(
"StIOMaker");
82 gSystem->Load(
"StarClassLibrary");
83 gSystem->Load(
"St_Tables");
84 gSystem->Load(
"StDbLib");
85 gSystem->Load(
"StDbBroker");
86 gSystem->Load(
"St_db_Maker");
90 dbMk->SetDateTime(readDate,readTime);
91 dbMk->SetFlavor(
"ofl");
100 DB = dbMk->GetInputDB(
"Calibrations/fms/mapping");
101 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
104 St_fmsPatchPanelMap *dbppmap = 0;
105 dbppmap = (St_fmsPatchPanelMap*) DB->
Find(
"fmsPatchPanelMap");
108 std::cout <<
"Reading fmsPatchPanelMap table\n";
109 fmsPatchPanelMap_st *pptable = dbppmap->GetTable();
110 for(
int mod=0; mod<4; mod++){
111 for(
int ch=0; ch<maxch[module[mod]-1]; ch++){
112 printf(
"%3d %3d %3d %3d %3d\n",module[mod],ch+1,
113 int(pptable[mod].ppPanel[ch]),
114 int(pptable[mod].ppRow[ch]),
115 int(pptable[mod].ppColumn[ch]) );
118 memcpy(ppmap,pptable,
sizeof(ppmap));
120 std::cout <<
"WARNING: No data in fmsPatchPanelMap table (wrong timestamp?). Nothing to return, then.\n";
124 if(option.Contains(
"writetext")){
125 char* file=
"qtmap2pp_out.txt";
127 cout <<
"Writing "<<file<<
"\n";
128 if(fp=fopen(file,
"w")){
129 for(
int mod=0; mod<4; mod++){
130 for(
int ch=0; ch<maxch[module[mod]-1]; ch++){
131 fprintf(fp,
"%3d %3d %3d %3d %3d\n",module[mod],ch+1,
132 ppmap[mod].ppPanel[ch],
133 ppmap[mod].ppRow[ch],
134 ppmap[mod].ppColumn[ch]);
141 if(option.Contains(
"writedb")) {
147 StDbTable* table = node->addDbTable(
"fmsPatchPanelMap");
148 mgr->setStoreTime(storeTime.Data());
150 table->
SetTable((
char*)&ppmap,MAX_PP_MAP);
153 mgr->storeDbTable(table);
155 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