4 void fms_db_patchpanelmap(
char* opt =
"readdb writetext") {
9 TString storeTime =
"2007-11-09 00:00:01";
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_PP_MAP = 4;
32 fmsPatchPanelMap_st ppmap[MAX_PP_MAP];
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[rmod-1].ppPanel[ch]=pp;
69 ppmap[rmod-1].ppRow[ch]=row;
70 ppmap[rmod-1].ppColumn[ch]=col;
77 if(option.Contains(
"readdb")){
78 gSystem->Unsetenv(
"DB_ACCESS_MODE");
79 gSystem->Unsetenv(
"DB_SERVER_LOCAL_CONFIG");
81 gSystem->Load(
"StChain");
82 gSystem->Load(
"StBFChain");
83 gSystem->Load(
"StUtilities");
84 gSystem->Load(
"StIOMaker");
85 gSystem->Load(
"StarClassLibrary");
86 gSystem->Load(
"St_Tables");
87 gSystem->Load(
"StDbLib");
88 gSystem->Load(
"StDbBroker");
89 gSystem->Load(
"St_db_Maker");
93 dbMk->SetDateTime(date,time);
94 dbMk->SetFlavor(
"ofl");
103 DB = dbMk->GetInputDB(
"Calibrations/fms/mapping");
104 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
107 St_fmsPatchPanelMap *dbppmap = 0;
108 dbppmap = (St_fmsPatchPanelMap*) DB->
Find(
"fmsPatchPanelMap");
111 std::cout <<
"Reading fmsPatchPanelMap table\n";
112 fmsPatchPanelMap_st *pptable = dbppmap->GetTable();
113 memcpy(ppmap,pptable,
sizeof(ppmap));
115 std::cout <<
"WARNING: No data in fmsPatchPanelMap table (wrong timestamp?). Nothing to return, then.\n";
119 if(option.Contains(
"writetext")){
120 char* file=
"qtmap2pp.txt_dbout";
122 cout <<
"Writing "<<file<<
"\n";
123 if(fp=fopen(file,
"w")){
124 for(
int mod=0; mod<4; mod++){
125 for(
int ch=0; ch<maxch[module[mod]-1]; ch++){
126 fprintf(fp,
"%3d %3d %3d %3d %3d\n",module[mod],ch+1,
127 ppmap[module[mod]-1].ppPanel[ch],
128 ppmap[module[mod]-1].ppRow[ch],
129 ppmap[module[mod]-1].ppColumn[ch]);
136 if(option.Contains(
"writedb")) {
137 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
138 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
141 StDbTable* table = node->addDbTable(
"fmsPatchPanelMap");
143 mgr->setStoreTime(storeTime.Data());
145 table->
SetTable((
char*)&ppmap,MAX_PP_MAP);
147 mgr->storeDbTable(table);
148 gSystem->Unsetenv(
"DB_ACCESS_MODE");
149 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