StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpsMap_db.C
1 #include <iostream.h>
2 #include <fstream.h>
3 
4 void fpsMap_db(char* opt="", char* year="15sim", char* input="fpsmap.txt") {
5  TString option(opt), yr(year);
6  TString storeTime; // storetime is begin time for validity range for WRITING DB
7  int date,time; // time for READING DB
8  std::cout << "year = " << year << "\n";
9  if(yr.Contains("15ofl")){
10  storeTime="2014-12-20 00:00:3";
11  date = 20141221; time = 0;
12  }else if(yr.Contains("15sim")){
13  storeTime="2014-12-10 00:00:01";
14  date = 20141210; time = 1;
15  }else if(yr.Contains("17ofl")){
16  storeTime="2016-12-20 00:00:00";
17  date = 20161220; time = 0;
18  }else if(yr.Contains("17sim")){
19  storeTime="2016-12-10 00:00:00";
20  date = 20161210; time = 0;
21  }else{
22  std::cout << "Please specify valid year tag\n"; exit;
23  }
24  std::cout << "Opt =" << opt << "\n";
25  std::cout << "write = " << option.Contains("writedb") << "\n";
26  std::cout << "storetime =" << storeTime << "\n";
27  std::cout << "date,time =" << date <<" "<< time << "\n";
28 
29  gROOT->Macro("./loadlib.C");
30 
31  const Int_t MAX_DB_INDEX = 252;
32  fpsMap_st in[MAX_DB_INDEX];
33  for(int i=0; i<MAX_DB_INDEX; i++){
34  in[i].slatid=i;
35  in[i].QTaddr=-1;
36  in[i].QTch=-1;
37  }
38 
39  FILE *FP = fopen(input,"r");
40  if(!FP) { printf("Could not open %s\n",input); exit;}
41  printf("Reading %s\n",input);
42  char line[1000], nw[10], dc[10], posi[10];
43  int id,q,l,s,sipm,sipmbd,feebd,tbox,tgrp,qtaddr,qtch,cbl;
44  int n=0;
45  while(fgets(line,1000,FP)!=NULL){
46  sscanf(line,"%d %d %d %d %d %s %d %d %d %d",
47  &id,&q,&l,&s,
48  &sipm,nw,
49  &tbox,&tgrp,
50  &qtaddr,&qtch);
51  //printf("Id=%3d Q=%3d L=%3d S=%3d QTaddr=%1d QTch=%2d\n",id,q,l,s,qtaddr,qtch);
52  in[id].QTaddr=qtaddr;
53  in[id].QTch=qtch;
54  n++;
55  }
56  for(int i=0; i<MAX_DB_INDEX; i++){
57  printf("Id=%3d QTaddr=%1d QTch=%2d\n",in[i].slatid,in[i].QTaddr,in[i].QTch);
58  }
59  printf("Found %d entries\n",n);
60 
61  if(option.Contains("writedb")) {
62  gSystem->Setenv("DB_ACCESS_MODE","write");
64  StDbConfigNode* node = mgr->initConfig("Geometry_fps");
65  StDbTable* dbtable = node->addDbTable("fpsMap");
66  mgr->setStoreTime(storeTime.Data());
67  dbtable->SetTable((char*)&in, MAX_DB_INDEX);
68  if(yr.Contains("sim")) dbtable->setFlavor("sim");
69  mgr->storeDbTable(dbtable);
70  std::cout << "INFO: table saved to database" << std::endl;
71  }
72 
73  std::cout << "INFO: Reading database" << std::endl;
74  gSystem->Unsetenv("DB_ACCESS_MODE");
75  //gSystem->Unsetenv("DB_SERVER_LOCAL_CONFIG");
76  St_db_Maker *dbMk=new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
77  dbMk->SetDebug();
78  dbMk->SetDateTime(date,time); // event or run start time, set to your liking
79  if(yr.Contains("ofl")) {dbMk->SetFlavor("ofl");}
80  else if(yr.Contains("sim")) {dbMk->SetFlavor("sim");}
81  dbMk->Init();
82  dbMk->Make();
83  TDataSet *DB = 0;
84  DB = dbMk->GetDataBase("Geometry/fps/fpsMap");
85  if (!DB) std::cout << "ERROR: no table found in db, or malformed local db config" << std::endl;
86  St_fpsMap *dataset = 0;
87  dataset = (St_fpsMap*) DB->Find("fpsMap");
88  if (!dataset) {
89  td::cout << "ERROR: dataset does not contain requested table" << std::endl;
90  return;
91  }
92  Int_t rows = dataset->GetNRows();
93  if (rows > 1) {
94  std::cout << "INFO: found INDEXED table with " << rows << " rows" << std::endl;
95  }
96  TDatime val[2];
97  dbMk->GetValidity((TTable*)dataset,val);
98  std::cout << "Dataset validity range: [ " << val[0].GetDate() << "." << val[0].GetTime() << " - "
99  << val[1].GetDate() << "." << val[1].GetTime() << " ] "
100  << std::endl;
101  fpsMap_st *table = dataset->GetTable();
102  for (Int_t i = 0; i < rows; i++) {
103  std::cout << Form("Row=%4d slatid=%3d QTaddr=%2d QTch=%2d\n",i,
104  table[i].slatid,
105  table[i].QTaddr,table[i].QTch);
106  }
107 }
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
Definition: TTable.h:48
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362