StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofINLSCorrStep1.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 storetofINLSCorrStep1(int i1=0, int i2=300)
23 //int main(int argc, char *argv[])
24 
25 {
26 
27  const Int_t NMAX = 1400;
28  const Int_t NTDC = 3; // # of tdcs per board
29  const Int_t NCHAN = 8; // # of channels per tdc
30 
31  //-- load dBase and Table definition libraries
32  gSystem->Load("St_base");
33  gSystem->Load("StChain");
34  gSystem->Load("StUtilities");
35  gSystem->Load("St_Tables.so");
36 
37  gSystem->Load("StDbLib.so");
38  gSystem->Load("libStDb_Tables.so");
39 
40  //-- get the singleton manager
41  StDbManager* dbManager = StDbManager::Instance();
42 
43  //-- connect to the db & get an empty container
44  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
45 
46  //----------------------------------------
47  TString ZStoreTime = "2009-09-01 00:00:00";
48 
49  //-- add table to the container with descriptor given by Database
50  StDbTable* tofINLSCorr = configNode->addDbTable("tofINLSCorr");
51 
52  //-- fill structures & store times
53  tofINLSCorr_st *inlcorr= new tofINLSCorr_st[NMAX*NTDC*NCHAN];
54 
55  Int_t NFILL = 0;
56  Int_t NBOARD = 0;
57  // read in inltable file by file.
58 
59  TH1S *hINLSCorr[NMAX][NTDC][NCHAN];
60  Bool_t *hFlag[NMAX];
61  for(int i=0;i<NMAX;i++) hFlag[i] = false;
62 
63  ofstream testData;
64  char testname[100];
65  sprintf(testname,"write_%d_%d.list",i1,i2);
66  testData.open(testname);
67 
68  ofstream inputData;
69  char inputname[100];
70  sprintf(inputname,"input_%d_%d.list",i1,i2);
71  inputData.open(inputname);
72 // for(int iboard=0;iboard<NMAX;iboard++) {
73  for(int iboard=i1;iboard<i2;iboard++) {
74 
75  //char *dirpfx = "/gpfs01/star/scratch/geurts/inl/Run10/dbase/INL";
76  //char *dirpfx = "/gpfs01/star/i_rice/geurts/database/Run13/INL";
77  char *dirpfx = "/gpfs01/star/i_rice/geurts/database/Run15/";
78  char fulldir[200];
79  char dirname[100];
80  char sfx[9][10] = {"",".R",".RC",".RRC",".redo",".n","redo","n",".RRR"};
81 
82  int iv = -1;
83  for(int j=0;j<9;j++) {
84  sprintf(dirname,"tdig-ser%d%s",iboard,sfx[j]);
85  sprintf(fulldir,"%s/%s",dirpfx,dirname);
86  void *dir = gSystem->OpenDirectory(gSystem->ExpandPathName(fulldir));
87  if(!dir) continue;
88 
89  iv = j;
90  break;
91  }
92 
93  if(iv<0||iv>=9) {
94  cout << " No available table for board # " << iboard << endl;
95  continue;
96  }
97  sprintf(dirname,"tdig-ser%d%s",iboard,sfx[iv]);
98  sprintf(fulldir,"%s/%s",dirpfx,dirname);
99 
100  cout << " Opening directory " << dirname << " for input... " << endl;
101  inputData << iboard << "\t" << dirname << endl;
102 
103  Short_t corr[NTDC*NCHAN*1024];
104 
105  for(int itdc=0;itdc<NTDC;itdc++){
106  for(int ichan=0;ichan<NCHAN;ichan++) {
107 
108  char filename[512];
109  sprintf(filename,"%s/inl/%s.tdc%d.ch%d.inl",fulldir,dirname,itdc,ichan);
110 
111  char hisname[512];
112  sprintf(hisname,"b_%d_tdc_%d_chan_%d",iboard,itdc,ichan);
113  hINLSCorr[iboard][itdc][ichan] = new TH1S(hisname,hisname,1024,0.,1024.);
114 
115  inlcorr[NFILL].tdigId = (Short_t)iboard;
116  inlcorr[NFILL].tdcChanId = (Short_t)(itdc*NCHAN+ichan);
117 
118  ifstream infile(filename);
119  if(!infile) {
120  cout<<"Can not open "<<filename<<" Please check!!!"<<endl;
121  return -1;
122  }
123  cout << " +++ Open file " << filename << " for input " << endl;
124 
125  for(int j=0;j<1024;j++) {
126  float bin, data;
127  infile >> bin >> data;
128  inlcorr[NFILL].INLCorr[j]=(Short_t)(data*100.);
129  corr[itdc*NCHAN*1024+ichan*1024+j] = (Short_t)(data*100.);
130  if(fabs(j-bin)>0.6) {
131  cout << " weird!!! " << endl;
132  return;
133  }
134  // cout<<"readin bin="<<bin<<" ibin="<<j<<" data="<<data<<endl;
135  hINLSCorr[iboard][itdc][ichan]->SetBinContent(j+1,inlcorr[NFILL].INLCorr[j]);
136  }
137 
138  infile.close();
139 
140  NFILL++;
141  } // end of loop channel
142  } // end of loop TDC
143 
144  char outname[200];
145  sprintf(outname,"%s/inl/%s_24.inl",fulldir,dirname);
146  ofstream outfile(outname);
147  cout << " Writing to file " << outname << endl;
148  for(int ic=0;ic<1024;ic++) {
149  for(int it=0;it<NTDC*NCHAN;it++) {
150  outfile << setw(10) << corr[it*1024+ic];
151  }
152  outfile << endl;
153  }
154 
155  outfile.close();
156 
157  cout<<"================================================="<<endl;
158  NBOARD++;
159  hFlag[iboard] = true;
160  testData << iboard << "\t" << dirname << endl;
161 
162  } // end of loop board
163  testData.close();
164  inputData.close();
165  cout<<" prepare to upload data to DB NFILL="<<NFILL<<" NBOARD="<<NBOARD<<endl;
166 
167  char rootname[100];
168  sprintf(rootname,"INL_test_%d_%d.root",i1,i2);
169  TFile *fout = new TFile(rootname,"recreate");
170  int index = 0;
171  for(int iboard=0;iboard<NMAX;iboard++) {
172  if(!hFlag[iboard]) continue;
173 
174  for(int itdc=0;itdc<NTDC;itdc++){
175  for(int ichan=0;ichan<NCHAN;ichan++) {
176  if(!hINLSCorr[iboard][itdc][ichan]) continue;
177  hINLSCorr[iboard][itdc][ichan]->Write();
178 /*
179  cout << " Ids = " << iboard << " " << itdc << " " << ichan << endl;
180  cout << " IN Ids = " << inlcorr[index].tdigId << " " << inlcorr[index].tdcChanId << endl;
181  for(int j=0;j<1024;j++) {
182  if(j%100==0)
183  cout << " INL j = " << j << " " << inlcorr[index].INLCorr[j] << endl;
184  }
185 */
186  index++;
187  }
188  }
189  }
190  fout->Close();
191 
192  //- store data in table
193 /*
194  tofINLSCorr->SetTable((char*)inlcorr, NFILL);
195  //- set store time
196  dbManager->setStoreTime(ZStoreTime.Data());
197  //- store table in dBase
198  cout<<" here "<<endl;
199  dbManager->storeDbTable(tofINLSCorr);
200  cout<<"uploaded"<<endl;
201  // return 0;
202 */
203 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155