4 void fms_db_detectorposition(
char* opt =
"readtext",
char* dataspec) {
7 TString
data(dataspec);
10 if(
data.Contains(
"run8") &&
data.Contains(
"dAu200")){
11 storeTime =
"2007-11-09 12:00:00";
14 }
else if(
data.Contains(
"run8") &&
data.Contains(
"pp200")){
15 storeTime =
"2008-01-28 12:00:00";
18 }
else if(
data.Contains(
"run9") &&
data.Contains(
"pp200")){
19 storeTime =
"2009-01-16 00:00:00";
22 }
else if(
data.Contains(
"run15ppsim")){
23 storeTime =
"2014-12-16 00:00:00";
26 }
else if(
data.Contains(
"run15pAsim")){
27 storeTime =
"2014-12-17 00:00:00";
30 }
else if(
data.Contains(
"run17sim")){
31 storeTime =
"2016-12-10 00:00:01";
35 std::cout<<
"Invalid year range"<<std::endl;
40 std::cout <<
"Opt =" << opt <<
"\n";
41 std::cout <<
"testinput = " << option.Contains(
"testinput") <<
"\n";
42 std::cout <<
"readtext = " << option.Contains(
"readtext") <<
"\n";
43 std::cout <<
"readdb = " << option.Contains(
"readdb") <<
"\n";
44 std::cout <<
"writedb = " << option.Contains(
"writedb") <<
"\n";
45 std::cout <<
"writetext = " << option.Contains(
"writetext") <<
"\n";
46 std::cout <<
"StoreTime="<<storeTime<<endl;
47 std::cout <<
"ReadTime="<<readDate<<
" "<<readTime<<endl;
49 gROOT->Macro(
"LoadLogger.C");
50 gSystem->Load(
"St_base.so");
51 gSystem->Load(
"libStDb_Tables.so");
52 gSystem->Load(
"StDbLib.so");
58 fmsDetectorPosition_st detposition[MAX];
60 if(option.Contains(
"testinput")){
62 detposition[0].detectorId = 2;
63 detposition[0].xwidth = 7;
64 detposition[0].ywidth = .15;
65 detposition[1].detectorId = 2;
66 detposition[1].xwidth = 7;
67 detposition[1].ywidth = .15;
70 if(option.Contains(
"readtext")){
73 float rzoffset, rxoffset, ryoffset, rxwidth, rywidth;
74 cout <<
"Reading "<<dataspec<<
"\n";
75 if(fp=fopen(dataspec,
"r")){
76 for(
int i=0; i<MAX; i++){
77 if(!feof(fp)) fscanf(fp,
"%d %f %f %f %f %f",&rdetid,&rzoffset, &rxoffset, &ryoffset, &rxwidth, &rywidth);
78 detposition[i].detectorId=rdetid;
79 detposition[i].xwidth=rxwidth;
80 detposition[i].ywidth=rywidth;
81 detposition[i].xoffset=rxoffset;
82 detposition[i].yoffset=ryoffset;
83 detposition[i].zoffset=rzoffset;
84 cout << Form(
"%2d zoff=%10.4f xoff=%10.4f yoff=%10.4f wx=%10.4f wy%10.4f\n",rdetid,rzoffset,rxoffset, ryoffset, rxwidth, rywidth);
90 if(option.Contains(
"readdb")){
91 gSystem->Load(
"StChain");
92 gSystem->Load(
"StBFChain");
93 gSystem->Load(
"StUtilities");
94 gSystem->Load(
"StIOMaker");
95 gSystem->Load(
"StarClassLibrary");
96 gSystem->Load(
"St_Tables");
97 gSystem->Load(
"StDbLib");
98 gSystem->Load(
"StDbBroker");
99 gSystem->Load(
"St_db_Maker");
103 dbMk->SetDateTime(readDate,readTime);
104 dbMk->SetFlavor(
"ofl");
113 DB = dbMk->GetInputDB(
"Geometry/fms");
114 if (!DB) { std::cout <<
"ERROR: no db maker?" << std::endl; }
117 St_fmsDetectorPosition *dbppmap = 0;
118 dbppmap = (St_fmsDetectorPosition*) DB->
Find(
"fmsDetectorPosition");
121 std::cout <<
"Reading fmsDetectorPosition table\n";
122 fmsDetectorPosition_st *pptable = dbppmap->GetTable();
123 Int_t rows = dbppmap->GetNRows();
124 for(
int i=0; i<rows; i++)
125 printf(
"%2d %8.1f %6.1f %5.1f %6.3f %6.3f\n",
126 pptable[i].detectorId,pptable[i].zoffset,pptable[i].xoffset,
127 pptable[i].yoffset,pptable[i].xwidth,pptable[i].ywidth);
128 memcpy(detposition,pptable,
sizeof(detposition));
131 std::cout <<
"WARNING: No data in fmsDetposition table (wrong timestamp?). Nothing to return, then.\n";
135 if(option.Contains(
"writetext")){
136 int ii =
data.Length();
137 data.Insert(ii-4,
"_out");
138 char* file=
data.Data();
140 cout <<
"Writing "<<file<<
"\n";
141 if(fp=fopen(file,
"w"))
142 for(
int i=0; i<MAX; i++){
143 fprintf(fp,
"%8d%10.1f%10.2f%8.1f%10.3f%10.3f\n", detposition[i].detectorId, detposition[i].zoffset, detposition[i].xoffset,
144 detposition[i].yoffset, detposition[i].xwidth, detposition[i].ywidth);
149 if(option.Contains(
"writedb")) {
150 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
154 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
157 StDbTable* table = node->addDbTable(
"fmsDetectorPosition");
158 mgr->setStoreTime(storeTime.Data());
160 table->
SetTable((
char*)&detposition,MAX);
163 mgr->storeDbTable(table);
166 gSystem->Unsetenv(
"DB_ACCESS_MODE");
168 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