5 static const Int_t MAX = 2500;
6 static const Int_t MAXD = 14;
7 static const Int_t MAXCH= 578;
9 int getDetectorId(
int ew,
int nstb) {
return (ew-1)*8+nstb-1;}
10 int getEW(
int detid) {
return detid/8 + 1;}
11 int getNSTB(
int detid) {
return detid%8 + 1;}
13 void fms_db_fmsgaincorrB(
char* option =
"writetext 15sim",
char* dataspec=
"allone",
14 char* storetime=
"2007-11-09 12:00:00",
15 int readDate=20071210,
int readTime=0,
int isSim=0) {
19 TString
data(dataspec);
20 TString storeTime(storetime);
21 if(opt.Contains(
"run8") && opt.Contains(
"dAu200")){
22 storeTime =
"2007-11-09 12:00:00";
23 }
else if(opt.Contains(
"run8") && opt.Contains(
"pp200")){
24 storeTime =
"2008-01-28 12:00:00";
25 }
else if(opt.Contains(
"run9") && opt.Contains(
"pp200")){
26 storeTime =
"2009-01-16 00:00:00";
27 }
else if(opt.Contains(
"15sim")){
28 storeTime =
"2014-12-10 00:00:01"; readDate = 20141215; readTime = 0; isSim=1;
29 }
else if(opt.Contains(
"15ofl")){
30 storeTime =
"2014-12-20 00:00:00"; readDate = 20141225; readTime = 0;
31 }
else if(opt.Contains(
"17sim")){
32 storeTime =
"2016-12-10 00:00:01"; readDate = 20161215; readTime = 0; isSim=1;
33 }
else if(opt.Contains(
"17ofl")){
34 storeTime =
"2016-12-20 00:00:00"; readDate = 20161225; readTime = 0;
36 std::cout<<
"Invalid year range"<<std::endl;
39 std::cout <<
"Opt =" << option <<
"\n";
40 std::cout <<
"testinput = " << opt.Contains(
"testinput") <<
"\n";
41 std::cout <<
"readtext = " << opt.Contains(
"readtext") <<
"\n";
42 std::cout <<
"readdb = " << opt.Contains(
"readdb") <<
"\n";
43 std::cout <<
"writedb = " << opt.Contains(
"writedb") <<
"\n";
44 std::cout <<
"writetext = " << opt.Contains(
"writetext") <<
"\n";
45 std::cout <<
"dataspec = " << dataspec << endl;
46 std::cout <<
"storeTime = " << storeTime << endl;
47 std::cout <<
"readData = " << readDate <<
" readTime="<<readTime<<endl;
48 std::cout <<
"isSim = " << isSim << endl;
50 gROOT->Macro(
"LoadLogger.C");
51 gSystem->Load(
"St_base.so");
52 gSystem->Load(
"libStDb_Tables.so");
53 gSystem->Load(
"StDbLib.so");
56 fmsGainCorrectionB_st corr;
57 memset(&corr,0,
sizeof(corr));
59 if(
data.Contains(
"allone")){
60 int maxch[MAXD] = {49, 49, 7, 7, 48, 48, 48, 48, 578, 578, 288, 288, 108, 108};
62 for(
int det=8; det<=11; det++){
63 for(
int ch=0; ch<maxch[det]; ch++){
64 corr.detectorId[index]=det;
66 corr.corr [index]=1.0;
67 printf(
"n=%4d det=%2d ch=%3d corr=%8.6f\n",
68 index,corr.detectorId[index],corr.ch[index],corr.corr[index]);
74 if(opt.Contains(
"readtext")){
79 cout <<
"Reading "<<dataspec<<
"\n";
80 if(fp=fopen(dataspec,
"r")){
81 while(fscanf(fp,
"%d %d %d %f",&rew,&rnstb,&rch,&rcorr) != EOF){
82 int detid=getDetectorId(rew,rnstb);
83 if(detid<0 || rch<1) {
84 printf(
"Invalid ch#: det=%d ew=%d nstb=%d rch=%d\n",detid,rew,rnstb,rch,rcorr);
88 corr.detectorId[nread]=detid;
90 corr.corr[nread]=rcorr;
91 printf(
"n=%4d det=%2d ew=%1d nstb=%1d ch=%3d corr=%8.6f\n",nread,detid,rew,rnstb,rch,rcorr);
96 printf(
"read %d channels of gain corr\n",nread);
99 if(opt.Contains(
"writedb")) {
100 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
106 StDbTable* table = node->addDbTable(
"fmsGainCorrectionB");
107 mgr->setStoreTime(storeTime.Data());
112 if(isSim) table->setFlavor(
"sim");
113 mgr->storeDbTable(table);
116 gSystem->Unsetenv(
"DB_ACCESS_MODE");
118 std::cout <<
"Done with database upload"<< endl;
121 if(opt.Contains(
"readdb")){
122 gSystem->Load(
"StChain");
123 gSystem->Load(
"StBFChain");
124 gSystem->Load(
"StUtilities");
125 gSystem->Load(
"StIOMaker");
126 gSystem->Load(
"StarClassLibrary");
127 gSystem->Load(
"St_Tables");
128 gSystem->Load(
"StDbLib");
129 gSystem->Load(
"StDbBroker");
130 gSystem->Load(
"St_db_Maker");
134 dbMk->SetDateTime(readDate,readTime);
135 dbMk->SetFlavor(
"ofl");
136 if(isSim) dbMk->SetFlavor(
"sim");
144 DB = dbMk->GetInputDB(
"Calibrations/fms");
145 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
148 St_fmsGainCorrectionB *dbppmap = 0;
149 dbppmap = (St_fmsGainCorrectionB*) DB->
Find(
"fmsGainCorrectionB");
153 std::cout <<
"Reading fmsGainCorrectionB table\n";
154 fmsGainCorrectionB_st *pptable = dbppmap->GetTable();
155 for(
int i=0; i<MAX; i++){
156 if(pptable[0].ch[i]>0){
157 printf(
"%3d%8d%8d%8.4f\n",
158 int(pptable[0].detectorId[i]/8+1),
int(pptable[0].detectorId[i]%8+1),
159 int(pptable[0].ch[i]),
float(pptable[0].corr[i]) );
164 std::cout <<
"WARNING: No data in fmsGain table (wrong timestamp?). Nothing to return, then.\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