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_fmsgaincorr(
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;
34 std::cout <<
"Opt =" << option <<
"\n";
35 std::cout <<
"testinput = " << opt.Contains(
"testinput") <<
"\n";
36 std::cout <<
"readtext = " << opt.Contains(
"readtext") <<
"\n";
37 std::cout <<
"readdb = " << opt.Contains(
"readdb") <<
"\n";
38 std::cout <<
"writedb = " << opt.Contains(
"writedb") <<
"\n";
39 std::cout <<
"writetext = " << opt.Contains(
"writetext") <<
"\n";
40 std::cout <<
"dataspec = " << dataspec << endl;
41 std::cout <<
"storeTime = " << storeTime << endl;
42 std::cout <<
"readData = " << readDate <<
" readTime="<<readTime<<endl;
43 std::cout <<
"isSim = " << isSim << endl;
45 gROOT->Macro(
"LoadLogger.C");
46 gSystem->Load(
"St_base.so");
47 gSystem->Load(
"libStDb_Tables.so");
48 gSystem->Load(
"StDbLib.so");
51 fmsGainCorrection_st corr[MAX];
53 memset(idx,-1,
sizeof(idx));
54 for(
int i=0; i<MAX; i++){
55 corr[i].detectorId=-1;
60 int detId[MAXD] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
61 int detType[MAXD]= { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5};
62 int detNx[MAXD] = { 7, 7, 7, 7, 48, 48, 1, 1, 17, 17, 12, 12, 9, 9};
63 int detNy[MAXD] = { 7, 7, 1, 1, 1, 1, 48, 48, 34, 34, 24, 24, 12, 12};
64 int ew[MAXD] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
65 int nstb[MAXD] = { 1, 2, 5, 6, 3, 4, 7, 8, 1, 2, 3, 4, 1, 2};
66 int maxch[MAXD] = {49, 49, 7, 7, 48, 48, 48, 48, 578, 578, 288, 288, 108, 108};
69 for(
int det=0; det<MAXD; det++){
70 for(
int ch=0; ch<maxch[det]; ch++){
71 corr[index].detectorId=det;
73 corr[index].corr =0.0;
75 if(
data.Contains(
"allone")) corr[index].corr=1.0;
80 if(opt.Contains(
"readtext")){
85 cout <<
"Reading "<<dataspec<<
"\n";
86 if(fp=fopen(dataspec,
"r")){
87 while(fscanf(fp,
"%d %d %d %f",&rew,&rnstb,&rch,&rcorr) != EOF){
88 int detid=getDetectorId(rew,rnstb);
89 int index=idx[detid][rch-1];
90 printf(
"EW=%5d NSTB=%5d CH=%5d Gain=%6.4f | det=%2d idx=%4d\n",rew,rnstb,rch,rcorr,detid,index);
92 if(detid != corr[index].detectorId) printf(
"ERR DetId %d != %d\n",detid,corr[index].detectorId);
93 if(rch != corr[index].ch) printf(
"ERR Ch %d != %d\n",rch,corr[index].ch);
94 corr[index].corr=rcorr;
99 printf(
"read %d channels of gain corr\n",nread);
102 if(opt.Contains(
"readdb")){
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(readDate,readTime);
116 dbMk->SetFlavor(
"ofl");
125 DB = dbMk->GetInputDB(
"Calibrations/fms");
126 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
129 St_fmsGainCorrection *dbppmap = 0;
130 dbppmap = (St_fmsGainCorrection*) DB->
Find(
"fmsGainCorrection");
134 std::cout <<
"Reading fmsGainCorrection table\n";
135 fmsGainCorrection_st *pptable = dbppmap->GetTable();
136 for(
int iew=0; iew<2; iew++){
137 for(
int mod=0; mod<4; mod++){
138 for(
int ch0=0; ch0<maxch[mod+iew*4]; ch0++){
139 printf(
"%3d%8d%8d%8.4f\n",
int(pptable[ngain].detectorId/8+1),
int(pptable[ngain].detectorId%8+1),
140 int(pptable[ngain].ch),
float(pptable[ngain].corr) );
145 memcpy(corr,pptable,
sizeof(corr));
148 std::cout <<
"WARNING: No data in fmsGain table (wrong timestamp?). Nothing to return, then.\n";
152 if(opt.Contains(
"writetext")){
153 int ii =
data.Length();
154 data.Insert(ii-4,
"_out");
155 char* file=
data.Data();
157 cout <<
"Writing "<<file<<
"\n";
159 if(fp=fopen(file,
"w")){
160 for(
int i=0; i<MAX; i++){
161 if(corr[i].corr>=0.0){
162 int detid=corr[i].detectorId;
163 int iew=getEW(detid);
164 int instb=getNSTB(detid);
165 fprintf(fp,
"%d %d %d %5.3f\n",iew,instb,
166 corr[i].ch,corr[i].corr);
172 printf(
"Write %d channels\n",ngain);
175 if(opt.Contains(
"writedb")) {
176 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
182 StDbTable* table = node->addDbTable(
"fmsGainCorrection");
183 mgr->setStoreTime(storeTime.Data());
185 table->
SetTable((
char*)&corr,index+1);
188 if(isSim) table->setFlavor(
"sim");
189 mgr->storeDbTable(table);
192 gSystem->Unsetenv(
"DB_ACCESS_MODE");
194 std::cout <<
"Done with database upload with nrow=" << index+1 << endl;
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