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_fmsgain(
char* option =
"readtext writetext 15sim",
char* dataspec=
"FmsPtGainR16.txt") {
17 TString
data(dataspec);
18 int readDatte=20071210, readTime=0, isSim=0;
19 if(opt.Contains(
"run8") && opt.Contains(
"dAu200")){
20 TString storeTime =
"2007-11-09 12:00:00";
21 }
else if(opt.Contains(
"run8") && opt.Contains(
"pp200")){
22 TString storeTime =
"2008-01-28 12:00:00";
23 }
else if(opt.Contains(
"run9") && opt.Contains(
"pp200")){
24 TString storeTime =
"2009-01-16 00:00:00";
25 }
else if(opt.Contains(
"15sim")){
26 TString storeTime =
"2014-12-10 00:00:01"; readDate = 20141215; readTime = 0; isSim=1;
27 }
else if(opt.Contains(
"15ofl")){
28 TString storeTime =
"2014-12-20 00:00:00"; readDate = 20141225; readTime = 0;
30 else std::cout<<
"Invalid year range"<<std::endl;
32 std::cout <<
"Opt =" << option <<
"\n";
33 std::cout <<
"testinput = " << opt.Contains(
"testinput") <<
"\n";
34 std::cout <<
"readtext = " << opt.Contains(
"readtext") <<
"\n";
35 std::cout <<
"readdb = " << opt.Contains(
"readdb") <<
"\n";
36 std::cout <<
"writedb = " << opt.Contains(
"writedb") <<
"\n";
37 std::cout <<
"writetext = " << opt.Contains(
"writetext") <<
"\n";
39 gROOT->Macro(
"LoadLogger.C");
40 gSystem->Load(
"St_base.so");
41 gSystem->Load(
"libStDb_Tables.so");
42 gSystem->Load(
"StDbLib.so");
47 memset(idx,-1,
sizeof(idx));
48 for(
int i=0; i<MAX; i++){
49 gain[i].detectorId=-1;
54 int detId[MAXD] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
55 int detType[MAXD]= { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5};
56 int detNx[MAXD] = { 7, 7, 7, 7, 48, 48, 1, 1, 17, 17, 12, 12, 9, 9};
57 int detNy[MAXD] = { 7, 7, 1, 1, 1, 1, 48, 48, 34, 34, 24, 24, 12, 12};
58 int ew[MAXD] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
59 int nstb[MAXD] = { 1, 2, 5, 6, 3, 4, 7, 8, 1, 2, 3, 4, 1, 2};
60 int maxch[MAXD] = {49, 49, 7, 7, 48, 48, 48, 48, 578, 578, 288, 288, 108, 108};
63 for(
int det=0; det<MAXD; det++){
64 for(
int ch=0; ch<maxch[det]; ch++){
65 gain[index].detectorId=det;
72 if(opt.Contains(
"readtext")){
78 cout <<
"Reading "<<dataspec<<
"\n";
79 if(fp=fopen(dataspec,
"r")){
80 while(fscanf(fp,
"%d %d %d %f",&rew,&rnstb,&rch,&rgain) != EOF){
81 int detid=getDetectorId(rew,rnstb);
82 int index=idx[detid][rch-1];
84 if(detid != gain[index].detectorId) printf(
"ERR DetId %d != %d\n",detid,gain[index].detectorId);
85 if(rch != gain[index].ch) printf(
"ERR Ch %d != %d\n",rch,gain[index].ch);
86 gain[index].gain=rgain;
91 printf(
"read %d channels of gain\n",nread);
94 if(opt.Contains(
"readdb")){
95 gSystem->Load(
"StChain");
96 gSystem->Load(
"StBFChain");
97 gSystem->Load(
"StUtilities");
98 gSystem->Load(
"StIOMaker");
99 gSystem->Load(
"StarClassLibrary");
100 gSystem->Load(
"St_Tables");
101 gSystem->Load(
"StDbLib");
102 gSystem->Load(
"StDbBroker");
103 gSystem->Load(
"St_db_Maker");
107 dbMk->SetDateTime(readDate,readTime);
108 dbMk->SetFlavor(
"ofl");
117 DB = dbMk->GetInputDB(
"Calibrations/fms");
118 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
121 St_fmsGain *dbppmap = 0;
122 dbppmap = (St_fmsGain*) DB->
Find(
"fmsGain");
126 std::cout <<
"Reading fmsGain table\n";
127 fmsGain_st *pptable = dbppmap->GetTable();
128 for(
int iew=0; iew<2; iew++){
129 for(
int mod=0; mod<4; mod++){
130 for(
int ch0=0; ch0<maxch[mod+iew*4]; ch0++){
131 printf(
"%3d%8d%8d%8.4f\n",
int(pptable[ngain].detectorId/8+1),
int(pptable[ngain].detectorId%8+1),
132 int(pptable[ngain].ch),
float(pptable[ngain].gain) );
137 memcpy(gain,pptable,
sizeof(gain));
140 std::cout <<
"WARNING: No data in fmsGain table (wrong timestamp?). Nothing to return, then.\n";
144 if(opt.Contains(
"writetext")){
145 int ii =
data.Length();
146 data.Insert(ii-4,
"_out");
147 char* file=
data.Data();
149 cout <<
"Writing "<<file<<
"\n";
151 if(fp=fopen(file,
"w")){
152 for(
int i=0; i<MAX; i++){
153 if(gain[i].gain>=0.0){
154 int detid=gain[i].detectorId;
155 int iew=getEW(detid);
156 int instb=getNSTB(detid);
157 fprintf(fp,
"%d %d %d %5.3f\n",iew,instb,
158 gain[i].ch,gain[i].gain);
164 printf(
"Write %d channels\n",ngain);
167 if(opt.Contains(
"writedb")) {
168 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
174 StDbTable* table = node->addDbTable(
"fmsGain");
175 mgr->setStoreTime(storeTime.Data());
177 table->
SetTable((
char*)&gain,index+1);
180 if(isSim) table->setFlavor(
"sim");
181 mgr->storeDbTable(table);
184 gSystem->Unsetenv(
"DB_ACCESS_MODE");
186 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