StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_db_ChannelGeometry_akio.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fms_db_ChannelGeometry_akio(char* opt="writedb", int year=15) {
5 
6  TString option(opt);
7  std::cout << "Opt =" << opt << "\n";
8  std::cout << "readdb = " << option.Contains("readdb") << "\n";
9  std::cout << "writedb = " << option.Contains("writedb") << "\n";
10  std::cout << "\n";
11 
12  TString storeTime; // storetime is begin time for validity range for WRITING DB
13  int date,time; // time for READING DB
14  std::cout << "year = " << year << "\n";
15  if(year==8){
16  storeTime="2007-11-09 00:00:02";
17  date = 20080301;
18  time = 0;
19  }else if(year==9){
20  storeTime="2008-11-09 00:00:01";
21  date = 20090301;
22  time = 0;
23  }else if(year==15){
24  storeTime="2014-12-20 00:00:00";
25  date = 20141220;
26  time = 0;
27  }else{
28  std::cout << "Please specify year\n";
29  exit;
30  }
31  std::cout << "storetime =" << storeTime << "\n";
32  std::cout << "date,time =" << date <<" "<< time << "\n";
33 
34  gROOT->Macro("LoadLogger.C");
35  gSystem->Load("St_base.so");
36  gSystem->Load("libStDb_Tables.so");
37  gSystem->Load("StDbLib.so");
38 
39  // max index dimensions
40  const Int_t MAXINDEX = 20;
41  int n=0;
42 
43  // structure to fill up
44  fmsChannelGeometry_st g[MAXINDEX];
45  memset(g,0,sizeof(g));
46 
47  gSystem->Load("StChain");
48  gSystem->Load("StBFChain");
49  gSystem->Load("StUtilities");
50  gSystem->Load("StIOMaker");
51  gSystem->Load("StarClassLibrary");
52  gSystem->Load("St_Tables");
53  gSystem->Load("StDbLib");
54  gSystem->Load("StDbBroker");
55  gSystem->Load("St_db_Maker");
56 
57  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
58  dbMk->SetDebug();
59  dbMk->SetDateTime(date,time);
60  dbMk->SetFlavor("ofl"); // for offline calibrations/mapping
61  // dbMk->SetFlavor("simu"); // for simulations
62  dbMk->Init();
63  dbMk->Make();
64 
65  // this is done inside ::Make method
66  TDataSet *DB = 0;
67  // "dbMk->" will NOT be needed.
68  // if done inside your FmsDbMaker. Simply use DB = GetInputDb("Geometry/fms")
69  DB = dbMk->GetInputDB("Geometry/fms/");
70  if (!DB) { std::cout << "ERROR: no db maker?" << std::endl; }
71 
72  if(option.Contains("readdb")){
73  gSystem->Unsetenv("DB_ACCESS_MODE");
74  gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
75  St_fmsChannelGeometry *db = 0;
76  db = (St_fmsChannelGeometry*) DB->Find("fmsChannelGeometry");
77  // fetch data and place it to appropriate structure
78  if (db) {
79  std::cout << "Reading fmsMap table\n";
80  fmsChannelGeometry_st *table = db->GetTable();
81  n = db->GetNRows();
82  memcpy(g,table,sizeof(fmsChannelGeometry_st)*n);
83  } else {
84  std::cout << "WARNING: No data in fmsChannelGeometry table (wrong timestamp?). Nothing to return, then.\n";
85  }
86  }
87 
88  if(option.Contains("writedb")) {
89  gSystem->Setenv("DB_ACCESS_MODE","write");
90  cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
92  StDbConfigNode* node = mgr->initConfig("Geometry_fms");
93  StDbTable* table = node->addDbTable("fmsChannelGeometry");
94  mgr->setStoreTime(storeTime.Data());
95 
96  // input data
97  /* Detector Name detectorId ew ns type nX nY */
98  /* FPD-North 0 0 0 0 7 7 */
99  /* FPD-South 1 0 1 0 7 7 */
100  /* FPD-North-Pres 2 0 0 1 7 1 */
101  /* FPD-South-Pres 3 0 1 1 7 1 */
102  /* FPD-North-SMDV 4 0 0 2 48 1 */
103  /* FPD-South-SMDV 5 0 1 2 48 1 */
104  /* FPD-North-SMDH 6 0 0 3 1 48 */
105  /* FPD-South-SMDH 7 0 1 3 1 48 */
106  /* FMS-North-Large 8 1 0 4 17 34 */
107  /* FMS-South-Large 9 1 1 4 17 34 */
108  /* FMS-North-Small 10 1 0 0 12 24 */
109  /* FMS-South-Small 11 1 1 0 12 24 */
110  /* FHC-North 12 1 0 5 9 12 */
111  /* FHC-South 13 1 1 5 9 12 */
112  /* FHC-South 15 1 0 6 0 0 See fpsChannelGeometry for more details*/
113 
114  int n=0;
115  g[n].detectorId = 0; g[n].type=0; g[n].ew=0; g[n].ns=0; g[n].nX= 7; g[n].nY= 7; n++;
116  g[n].detectorId = 1; g[n].type=0; g[n].ew=0; g[n].ns=1; g[n].nX= 7; g[n].nY= 7; n++;
117  g[n].detectorId = 2; g[n].type=1; g[n].ew=0; g[n].ns=0; g[n].nX= 7; g[n].nY= 1; n++;
118  g[n].detectorId = 3; g[n].type=1; g[n].ew=0; g[n].ns=1; g[n].nX= 7; g[n].nY= 1; n++;
119  if(year>=9){
120  g[n].detectorId = 4; g[n].type=2; g[n].ew=0; g[n].ns=0; g[n].nX=48; g[n].nY= 1; n++;
121  g[n].detectorId = 5; g[n].type=2; g[n].ew=0; g[n].ns=1; g[n].nX=48; g[n].nY= 1; n++;
122  g[n].detectorId = 6; g[n].type=3; g[n].ew=0; g[n].ns=0; g[n].nX= 1; g[n].nY=48; n++;
123  g[n].detectorId = 7; g[n].type=3; g[n].ew=0; g[n].ns=1; g[n].nX= 1; g[n].nY=48; n++;
124  }
125  g[n].detectorId = 8; g[n].type=4; g[n].ew=1; g[n].ns=0; g[n].nX=17; g[n].nY=34; n++;
126  g[n].detectorId = 9; g[n].type=4; g[n].ew=1; g[n].ns=1; g[n].nX=17; g[n].nY=34; n++;
127  g[n].detectorId =10; g[n].type=0; g[n].ew=1; g[n].ns=0; g[n].nX=12; g[n].nY=24; n++;
128  g[n].detectorId =11; g[n].type=0; g[n].ew=1; g[n].ns=1; g[n].nX=12; g[n].nY=24; n++;
129  g[n].detectorId =15; g[n].type=6; g[n].ew=1; g[n].ns=0; g[n].nX= 0; g[n].nY= 0; n++;
130 
131  // store data in the table
132  table->SetTable((char*)&g,n);
133  // store table in dBase
134  mgr->storeDbTable(table);
135  gSystem->Unsetenv("DB_ACCESS_MODE");
136  std::cout << "Done with database upload \n";
137  }
138 
139  printf("n = %d\n",n);
140  printf(" Id Typ ew ns nX nY\n");
141  for(int i=0; i<n; i++){
142  printf("%3d %3d %3d %3d %3d %3d\n",g[i].detectorId,g[i].type,g[i].ew,g[i].ns,g[i].nX,g[i].nY);
143  }
144 }
145 
virtual Int_t Make()
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362