StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_db_ChannelGeometry.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fms_db_ChannelGeometry(char* opt="readdb", 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 // date = 20140222;
27  time = 0;
28  }
29  else{
30  std::cout << "Please specify year\n";
31  exit;
32  }
33  std::cout << "storetime =" << storeTime << "\n";
34  std::cout << "date,time =" << date <<" "<< time << "\n";
35 
36  gROOT->Macro("LoadLogger.C");
37  gSystem->Load("St_base.so");
38  gSystem->Load("libStDb_Tables.so");
39  gSystem->Load("StDbLib.so");
40 
41  // max index dimensions
42  const Int_t MAXINDEX = 12;
43  int n=0;
44 
45  // structure to fill up
46  fmsChannelGeometry_st g[MAXINDEX];
47  memset(g,0,sizeof(g));
48 
49  gSystem->Load("StChain");
50  gSystem->Load("StBFChain");
51  gSystem->Load("StUtilities");
52  gSystem->Load("StIOMaker");
53  gSystem->Load("StarClassLibrary");
54  gSystem->Load("St_Tables");
55  gSystem->Load("StDbLib");
56  gSystem->Load("StDbBroker");
57  gSystem->Load("St_db_Maker");
58 
59  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
60  dbMk->SetDebug();
61  dbMk->SetDateTime(date,time);
62  dbMk->SetFlavor("ofl"); // for offline calibrations/mapping
63  // dbMk->SetFlavor("simu"); // for simulations
64  dbMk->Init();
65  dbMk->Make();
66 
67  // this is done inside ::Make method
68  TDataSet *DB = 0;
69  // "dbMk->" will NOT be needed.
70  // if done inside your FmsDbMaker. Simply use DB = GetInputDb("Geometry/fms")
71  DB = dbMk->GetInputDB("Geometry/fms/");
72  if (!DB) { std::cout << "ERROR: no db maker?" << std::endl; }
73 
74  if(option.Contains("readdb")){
75  gSystem->Unsetenv("DB_ACCESS_MODE");
76  gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
77  St_fmsChannelGeometry *db = 0;
78  db = (St_fmsChannelGeometry*) DB->Find("fmsChannelGeometry");
79  // fetch data and place it to appropriate structure
80  if (db) {
81  std::cout << "Reading fmsMap table\n";
82  fmsChannelGeometry_st *table = db->GetTable();
83  n = db->GetNRows();
84  memcpy(g,table,sizeof(fmsChannelGeometry_st)*n);
85  } else {
86  std::cout << "WARNING: No data in fmsChannelGeometry table (wrong timestamp?). Nothing to return, then.\n";
87  }
88  }
89 
90  if(option.Contains("writedb")) {
91  gSystem->Setenv("DB_ACCESS_MODE","write");
92  cout << "DB_ACCESS_MODE="<<gSystem->Getenv("DB_ACCESS_MODE")<<endl;
94  StDbConfigNode* node = mgr->initConfig("Geometry_fms");
95  StDbTable* wtable = node->addDbTable("fmsChannelGeometry");
96  mgr->setStoreTime(storeTime.Data());
97 
98  // input data
99  /* Detector Name detectorId ew ns type nX nY */
100  /* FPD-North 0 0 0 0 7 7 */
101  /* FPD-South 1 0 1 0 7 7 */
102  /* FPD-North-Pres 2 0 0 1 7 1 */
103  /* FPD-South-Pres 3 0 1 1 7 1 */
104  /* FPD-North-SMDV 4 0 0 2 48 1 */
105  /* FPD-South-SMDV 5 0 1 2 48 1 */
106  /* FPD-North-SMDH 6 0 0 3 1 48 */
107  /* FPD-South-SMDH 7 0 1 3 1 48 */
108  /* FMS-North-Large 8 1 0 4 17 34 */
109  /* FMS-South-Large 9 1 1 4 17 34 */
110  /* FMS-North-Small 10 1 0 0 12 24 */
111  /* FMS-South-Small 11 1 1 0 12 24 */
112  /* FHC-North 12 1 0 5 9 12 */
113  /* FHC-South 13 1 1 5 9 12 */
114 
115  int n=0;
116  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++;
117  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++;
118  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++;
119  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++;
120  if(year>=9){
121  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++;
122  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++;
123  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++;
124  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++;
125  }
126  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++;
127  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++;
128  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++;
129  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++;
130 
131  // store data in the table
132  wtable->SetTable((char*)&g,n);
133  // store table in dBase
134  mgr->storeDbTable(wtable);
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