StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofTDIGOnTray.C
1 // macro to upload tofr5 INL tables to database
2 //
3 // based on
4 // http://www.star.bnl.gov/STAR/comp/db/StoreDbTable.cc.html
5 //
6 // Jing Liu, 02/18/2005
7 //
8 
9 
10 // #include "StDbLib/StDbManager.hh"
11 // #include "StDbLib/StDbConfigNode.hh"
12 // #include "StDbLib/StDbTable.h"
13 // #include "StDbLib/StDbDefs.hh"
14 
15 #include <iostream>
16 #include <fstream>
17 #include <string>
18 #include <iomanip>
19 using namespace std;
20 
21 
22 void storetofTDIGOnTray()
23 //int main(int argc, char *argv[])
24 
25 {
26 
27  const Int_t NBOARD = 8;
28 // year8
29 // const Int_t NTRAY = 5;
30 // year9
31  const Int_t NTRAY = 94;
32  const Int_t NVPDTRAY = 2;
33  const Int_t NMAX = 120;
34 
35  //-- load dBase and Table definition libraries
36  gSystem->Load("St_base");
37  gSystem->Load("StChain");
38  gSystem->Load("StUtilities");
39  gSystem->Load("St_Tables.so");
40 
41  gSystem->Load("StDbLib.so");
42  gSystem->Load("libStDb_Tables.so");
43 
44  //-- get the singleton manager
45  StDbManager* dbManager = StDbManager::Instance();
46 
47  //-- connect to the db & get an empty container
48  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
49 
50  //----------------------------------------
51 // TString ZStoreTime = "2007-11-01 00:00:03";
52  TString ZStoreTime = "2008-11-01 00:00:00";
53 
54  //-- add table to the container with descriptor given by Database
55  StDbTable* tofTDIGOnTray = configNode->addDbTable("tofTDIGOnTray");
56 
57  //-- fill structures & store times
58  tofTDIGOnTray_st *tdig = new tofTDIGOnTray_st[NMAX+NVPDTRAY];
59 
60 // year8
61 /*
62  Short_t trayId[NTRAY+NVPDTRAY] = {76, 77, 78, 79, 80, 121, 122};
63  Short_t tdigId[NTRAY+NVPDTRAY][NBOARD] = {
64  36, 26, 27, 29, 25, 23, 22, 21,
65  30, 31, 33, 35, 28, 32, 34, 37,
66  74, 63, 49, 72, 64, 53, 59, 52,
67  70, 51, 75, 65, 66, 50, 71, 68,
68  46, 62, 72, 69, 61, 58, 42, 43,
69  89, 91, 0, 0, 84, 82, 0, 0,
70  85, 79, 0, 0, 80, 83, 0, 0
71  };
72 */
73 // year9
74  Short_t validtrayId[NTRAY+NVPDTRAY] =
75  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
76  11, 12, 15, 16, 17, 18, 19, 20,
77  21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
78  31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
79  41, 44, 45, 46, 47, 48, 49, 50,
80  51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
81  61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
82  71, 72, 75, 76, 77, 78,
83 
84  97, 98, 99, 100,
85  101, 104, 105, 106, 107, 108, 109, 110,
86  111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
87  121, 122};
88  Short_t trayId[NMAX] = { 68, 58, 63, 6, 71, 67, 61, 50, 57, 60,
89  47, 46, 0, 0, 64, 72, 62, 42, 14, 11,
90  28, 7, 25, 33, 19, 17, 37, 21, 30, 35,
91  8, 20, 31, 27, 12, 9, 10, 29, 34, 13,
92  16, 0, 0, 36, 39, 23, 32, 15, 24, 18,
93  59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
94  84, 75, 94, 91, 95, 48, 65, 22, 40, 49,
95  5, 2, 0, 0, 1, 4, 3, 51, 0, 0,
96  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97  0, 0, 0, 0, 0, 0, 77, 89, 87, 90,
98  93, 0, 0, 73, 76, 83, 69, 80, 82, 74,
99  123, 79, 43, 86, 85,122, 81, 92, 96, 78};
100  // B-122; C-123 renamed
101 
102  Short_t tdigId[NMAX][NBOARD];
103  Short_t tdigId_Vpd[NVPDTRAY][NBOARD] = { 89, 91, 1102, 0, 885, 82, 0, 0,
104  85, 79, 1101, 0, 80, 83, 0, 0};
105 
106  ifstream infile("TDIGMap");
107  Short_t tId[NTRAY], boardId[NTRAY][NBOARD];
108  for(int i=0;i<NTRAY;i++) {
109  for(int j=0;j<NBOARD;j++) {
110  int trayNum, iboard, boardNum;
111  infile >> trayNum >> iboard >> boardNum;
112  cout << trayNum << " " << boardNum << endl;
113  tId[i] = (Short_t)trayNum;
114  boardId[i][iboard-1] = (Short_t)boardNum;
115  }
116  }
117  infile.close();
118 
119  for(int i=0;i<NMAX;i++) {
120  for(int j=0;j<NBOARD;j++) {
121  tdigId[i][j] = 0;
122  }
123 
124  Short_t thisTray = trayId[i];
125  int index = -1;
126  for(int j=0;j<NTRAY;j++) {
127  if(thisTray==tId[j]) {
128  index = j;
129  break;
130  }
131  }
132 
133  cout << "tray = " << thisTray << " index = " << index << endl;
134  if(index<0||index>=NTRAY) continue;
135  for(int j=0;j<NBOARD;j++) {
136  tdigId[i][j] = boardId[index][j];
137  }
138  }
139 
140 /*
141  {
142  89, 91, 0, 0, 84, 82, 0, 0,
143  85, 79, 0, 0, 80, 83, 0, 0
144  };
145 */
146 
147  for(int i=0;i<NMAX+NVPDTRAY;i++) {
148  tdig[i].trayId = i+1;
149  for(int j=0;j<NBOARD;j++) {
150  if(i<NMAX) {
151  tdig[i].tdigId[j] = tdigId[i][j];
152  } else {
153  tdig[i].tdigId[j] = tdigId_Vpd[i-NMAX][j];
154  }
155  }
156  }
157 
158  ofstream outData("testTDIGMap.dat");
159  for(int i=0;i<NMAX+NVPDTRAY;i++) {
160  for(int j=0;j<NBOARD;j++) {
161  outData << setw(5) << tdig[i].tdigId[j];
162  }
163  outData << endl;
164  }
165  outData.close();
166 
167  //- store data in table
168  tofTDIGOnTray->SetTable((char*)tdig, NMAX+NVPDTRAY);
169  //- set store time
170  dbManager->setStoreTime(ZStoreTime.Data());
171  //- store table in dBase
172  cout<<" here "<<endl;
173  dbManager->storeDbTable(tofTDIGOnTray);
174  cout<<"uploaded"<<endl;
175  // return 0;
176 }
177 
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155