4 void fms_db_pp_qt_merge(
char* opt,
int year) {
7 std::cout <<
"Opt =" << opt <<
"\n";
8 std::cout <<
"merge (read fmsPatchPanelmap and fmsQTmap from DB and merge to create fmsMap) = " << option.Contains(
"merge") <<
"\n";
9 std::cout <<
"readdb (read fmsMap from DB) = " << option.Contains(
"readdb") <<
"\n";
10 std::cout <<
"writedb (write fmsMap from DB) = " << option.Contains(
"writedb") <<
"\n";
11 std::cout <<
"writetext (write fmsMap from DB )= " << option.Contains(
"writetext") <<
"\n";
17 std::cout <<
"year = " << year <<
"\n";
19 storeTime=
"2007-11-09 00:00:01";
23 storeTime=
"2008-11-09 00:00:00";
27 std::cout <<
"Please specify year\n";
30 std::cout <<
"storetime =" << storeTime <<
"\n";
31 std::cout <<
"date,time =" << date <<
" "<< time <<
"\n";
32 if(option.Contains(
"merge")) filename=
"fms_db_pp_qt_merge.txt";
33 if(option.Contains(
"readdb")) filename=
"fms_db_pp_qt_merge.txt_dbout";
36 gROOT->Macro(
"LoadLogger.C");
37 gSystem->Load(
"St_base.so");
38 gSystem->Load(
"libStDb_Tables.so");
39 gSystem->Load(
"StDbLib.so");
42 int maxch[4] = {578,578,288,288};
43 int nsmap[4] = { 0, 1, 0, 1};
44 const Int_t MAX_PP_MAP = 4;
45 const Int_t MAX_QT_MAP = 2;
46 const Int_t MAX_MAP = 578 + 578 + 288 + 288;
50 fmsPatchPanelMap_st ppmap[MAX_PP_MAP];
51 fmsQTMap_st qtmap[MAX_QT_MAP];
52 fmsMap_st map[MAX_MAP];
54 gSystem->Load(
"StChain");
55 gSystem->Load(
"StBFChain");
56 gSystem->Load(
"StUtilities");
57 gSystem->Load(
"StIOMaker");
58 gSystem->Load(
"StarClassLibrary");
59 gSystem->Load(
"St_Tables");
60 gSystem->Load(
"StDbLib");
61 gSystem->Load(
"StDbBroker");
62 gSystem->Load(
"St_db_Maker");
66 dbMk->SetDateTime(date,time);
67 dbMk->SetFlavor(
"ofl");
76 DB = dbMk->GetInputDB(
"Calibrations/fms/mapping");
77 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl;
return 0;}
79 if(option.Contains(
"merge")){
80 gSystem->Unsetenv(
"DB_ACCESS_MODE");
81 gSystem->Unsetenv(
"DB_SERVER_LOCAL_CONFIG");
84 St_fmsPatchPanelMap *dbppmap = 0;
85 dbppmap = (St_fmsPatchPanelMap*) DB->
Find(
"fmsPatchPanelMap");
88 std::cout <<
"Reading fmsPatchPanelMap table\n";
89 fmsPatchPanelMap_st *pptable = dbppmap->GetTable();
90 memcpy(ppmap,pptable,
sizeof(ppmap));
92 std::cout <<
"WARNING: No data in fmsPatchPanelMap table (wrong timestamp?). Nothing to return, then.\n";
96 St_fmsQTMap *dbqtmap = 0;
97 dbqtmap = (St_fmsQTMap*) DB->
Find(
"fmsQTMap");
100 std::cout <<
"Reading fmsQTMap table\n";
101 fmsQTMap_st *qttable = dbqtmap->GetTable();
102 memcpy(qtmap,qttable,
sizeof(qtmap));
104 std::cout <<
"WARNING: No data in fmsQTMap table (wrong timestamp?). Nothing to return, then.\n";
109 for(
int mod=0; mod<4; mod++){
112 printf(
"mod=%d detid=%d ns=%d maxch=%d\n",mod,detid,ns,maxch[mod]);
113 for(
int ch=0; ch<maxch[mod]; ch++){
114 int pp = ppmap[mod].ppPanel[ch];
115 int row = ppmap[mod].ppRow[ch];
116 int col = ppmap[mod].ppColumn[ch];
117 map[nmap].detectorId = detid;
119 if(pp==0 && row==0 && col==0){
120 map[nmap].qtCrate = 0;
121 map[nmap].qtSlot = 0;
122 map[nmap].qtChannel = 0;
124 map[nmap].qtCrate = qtmap[ns].qtCrate[pp-1][row-1][col-1];
125 map[nmap].qtSlot = qtmap[ns].qtSlot[pp-1][row-1][col-1];
126 map[nmap].qtChannel = qtmap[ns].qtChannel[pp-1][row-1][col-1];
135 if(option.Contains(
"readdb")){
136 gSystem->Unsetenv(
"DB_ACCESS_MODE");
137 gSystem->Unsetenv(
"DB_SERVER_LOCAL_CONFIG");
140 St_fmsMap *dbmap = 0;
141 dbmap = (St_fmsMap*) DB->
Find(
"fmsMap");
144 fmsMap_st *table = dbmap->GetTable();
147 std::cout <<
"Reading fmsMap table with nrow = "<<nmap<<
"\n";
148 memcpy(map,table,
sizeof(fmsMap_st)*nmap);
150 std::cout <<
"WARNING: No data in fmsMap table (wrong timestamp?). Nothing to return, then.\n";
154 if(option.Contains(
"writetext")){
155 char* file=filename.Data();
158 cout <<
"Writing "<<file<<
"\n";
159 if(fp=fopen(file,
"w")){
160 fprintf(fp,
"%d\n",nmap);
161 for(
int i=0; i<nmap; i++){
162 fprintf(fp,
"%3d %4d %3d %3d %3d\n",map[i].detectorId,map[i].ch,
163 map[i].qtCrate, map[i].qtSlot, map[i].qtChannel);
168 if(option.Contains(
"writedb")) {
169 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
170 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
173 StDbTable* table = node->addDbTable(
"fmsMap");
174 mgr->setStoreTime(storeTime.Data());
178 mgr->storeDbTable(table);
179 gSystem->Unsetenv(
"DB_ACCESS_MODE");
180 std::cout <<
"Done with database upload \n";
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
static StDbManager * Instance()
strdup(..) is not ANSI
virtual TDataSet * Find(const char *path) const