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_fmsgainB(
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;
29 }
else if(opt.Contains(
"17sim")){
30 TString storeTime =
"2016-12-10 00:00:01"; readDate = 20161215; readTime = 0; isSim=1;
31 }
else if(opt.Contains(
"17ofl")){
32 TString storeTime =
"2016-12-20 00:00:00"; readDate = 20161225; readTime = 0;
34 else std::cout<<
"Invalid year range"<<std::endl;
36 std::cout <<
"Opt =" << option <<
"\n";
37 std::cout <<
"testinput = " << opt.Contains(
"testinput") <<
"\n";
38 std::cout <<
"readtext = " << opt.Contains(
"readtext") <<
"\n";
39 std::cout <<
"readdb = " << opt.Contains(
"readdb") <<
"\n";
40 std::cout <<
"writedb = " << opt.Contains(
"writedb") <<
"\n";
41 std::cout <<
"writetext = " << opt.Contains(
"writetext") <<
"\n";
43 gROOT->Macro(
"LoadLogger.C");
44 gSystem->Load(
"St_base.so");
45 gSystem->Load(
"libStDb_Tables.so");
46 gSystem->Load(
"StDbLib.so");
50 memset(&gain,0,
sizeof(gain));
52 if(opt.Contains(
"readtext")){
57 cout <<
"Reading "<<dataspec<<
"\n";
58 if(fp=fopen(dataspec,
"r")){
59 while(fscanf(fp,
"%d %d %d %f",&rew,&rnstb,&rch,&rgain) != EOF){
60 int detid=getDetectorId(rew,rnstb);
61 gain.detectorId[nread]=detid;
63 gain.gain[nread] =rgain;
69 printf(
"read %d channels of gain\n",nread);
72 if(opt.Contains(
"writedb")) {
73 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
79 StDbTable* table = node->addDbTable(
"fmsGainB");
80 mgr->setStoreTime(storeTime.Data());
85 if(isSim) table->setFlavor(
"sim");
86 mgr->storeDbTable(table);
89 gSystem->Unsetenv(
"DB_ACCESS_MODE");
91 std::cout <<
"Done with database upload \n";
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");
109 if(isSim) dbMk->SetFlavor(
"sim");
117 DB = dbMk->GetInputDB(
"Calibrations/fms");
118 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
121 St_fmsGainB *dbppmap = 0;
122 dbppmap = (St_fmsGainB*) DB->
Find(
"fmsGainB");
126 std::cout <<
"Reading fmsGainB table\n";
127 fmsGainB_st *pptable = dbppmap->GetTable();
128 for(
int i=0; i<MAX; i++){
130 printf(
"%3d%8d%8d%8.4f\n",
131 int(pptable.detectorId[i]/8+1),
int(pptable.detectorId[i]%8+1),
132 int(pptable.ch[i]),
float(pptable.gain[i]) );
136 memcpy(gain,pptable,
sizeof(gain));
138 std::cout <<
"WARNING: No data in fmsGain table (wrong timestamp?). Nothing to return, then.\n";
142 if(opt.Contains(
"writetext")){
143 int ii =
data.Length();
144 data.Insert(ii-4,
"_out");
145 char* file=
data.Data();
147 cout <<
"Writing "<<file<<
"\n";
149 if(fp=fopen(file,
"w")){
150 for(
int i=0; i<MAX; i++){
152 int detid=gain.detectorId[i];
153 int iew=int(gain.detectorId[i]/8+1);
154 int instb=int(gain.detectorId[i]%8+1);
155 fprintf(fp,
"%d %d %d %5.3f\n",iew,instb,
156 gain.ch[i],gain.gain[i]);
162 printf(
"Write %d channels\n",ngain);
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