StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storevpdTotCorr.C
1 // $Id: storevpdTotCorr.C,v 1.3 2019/01/16 16:18:36 geurts Exp $
2 // macro to upload tofr5 INL tables to database
3 //
4 // based on http://www.star.bnl.gov/STAR/comp/db/StoreDbTable.cc.html
5 //
6 // Xin Dong, 02/18/2005
7 // ---
8 // $Log: storevpdTotCorr.C,v $
9 // Revision 1.3 2019/01/16 16:18:36 geurts
10 // minor updates
11 //
12 // Revision 1.2 2014/11/24 22:18:54 geurts
13 // Add striciter protection against non-existing files (bail out), and reduce excessive std output
14 //
15 // Revision 1.1 2010/12/14 19:27:28 geurts
16 // *** empty log message ***
17 //
18 // --
19 
20 #include <iostream>
21 #include <fstream>
22 #include <string>
23 #include "iomanip.h"
24 using namespace std;
25 
26 
27 void storevpdTotCorr(const Bool_t mTest = 1)
28 {
29  const int mNTray = 120; // for test
30  const int mNTDIG = 8;
31  const int mNVPD = 19;
32 
33  //-- load dBase and Table definition libraries
34  gSystem->Load("St_base");
35  gSystem->Load("StChain");
36  gSystem->Load("StUtilities");
37  gSystem->Load("St_Tables.so");
38 
39  gSystem->Load("StDbLib.so");
40  gSystem->Load("libStDb_Tables.so");
41 
42  //-- get the singleton manager
43  StDbManager* dbManager = StDbManager::Instance();
44 
45  //-- connect to the db & get an empty container
46  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
47 
48  //----------------------------------------
49 // TString StoreTime = "2008-02-01 00:00:03";
50 // TString StoreTime = "2008-03-04 16:00:01";
51 // TString StoreTime = "2009-03-15 00:00:00";
52 // TString StoreTime = "2009-11-01 00:00:00"; // 200 GeV preliminary
53 // TString StoreTime = "2010-03-18 18:00:00"; // 62 GeV preliminary
54 // TString StoreTime = "2010-04-08 15:00:00"; // 39 GeV preliminary
55 // TString StoreTime = "2010-04-24 03:50:00"; // 7.7GeV preliminary
56  int corralgo = 1; // 1:enable self-calibrated BTOF; 0=use VPD
57  ifstream inTime;
58  inTime.open("input/timestamp");
59  string time;
60  if (inTime.is_open()) {
61  getline(inTime, time);
62  inTime.close();
63  } else {
64  cout << " Unable to open the TimeStamp file! EXIT! " << endl;
65  return;
66  }
67  TString StoreTime = time;
68  cout << " Store Time " << StoreTime.Data() << endl;
69 
70  //-- add table to the container with descriptor given by Database
71  StDbTable* vpdTotCorr = configNode->addDbTable("vpdTotCorr");
72 
73  //-- fill structures & store times
74  vpdTotCorr_st *totcorr= new vpdTotCorr_st[2*mNVPD];
75 
76  //=======================================
77  // read in pvpdTot file by file.
78 
79  Double_t diff[mNVPD*2];
80  Double_t toffset;
81  Double_t XS[mNVPD*2][128];
82  Double_t YS[mNVPD*2][128];
83  ifstream infile;
84 
85  infile.open("input/vpdCali_4DB.dat");
86  if (!infile.is_open()){
87  cerr <<" unable to open input/vpdCali_4DB.dat; bailing out ..." << endl;
88  exit(-1);
89  }
90 
91  for(int i=0;i<mNVPD*2;i++) {
92  int tubeId, nbins;
93  infile>>tubeId;
94  infile>>nbins;
95  for(int j=0;j<128;j++) {
96  if(j<nbins+1) infile>>XS[tubeId-1][j];
97  else XS[tubeId-1][j] = 0.0;
98  }
99  for(int j=0;j<128;j++) {
100  if(j<nbins+1) infile>>YS[tubeId-1][j];
101  else YS[tubeId-1][j] = 0.0;
102  }
103  }
104  infile.close();
105 
106  for(int i=0;i<2*mNVPD;i++) {
107  int tubeId = i+1;
108  totcorr[i].tubeId = (Short_t)tubeId;
109  totcorr[i].corralgo = corralgo;
110  for(int j=0;j<128;j++) {
111  totcorr[i].tot[j] = (Float_t)XS[i][j];
112  totcorr[i].corr[j] = (Float_t)YS[i][j];
113  }
114  }
115 
116  int nRow = 2*mNVPD;
117  ofstream outData;
118  outData.open("vpdTotCorr_test.dat");
119  for(int i=0;i<nRow;i++) {
120  outData << setw(6) << totcorr[i].tubeId << endl;
121  cout << totcorr[i].corralgo << " ";
122  for(int j=0;j<128;j++) {
123  if(totcorr[i].tot[j]>1.e-4)
124  outData << setw(15) << totcorr[i].tot[j];
125  }
126  outData << endl;
127  for(int j=0;j<128;j++) {
128  if(totcorr[i].tot[j]>1.e-4)
129  outData << setw(15) << totcorr[i].corr[j];
130  }
131  outData << endl;
132  cout << endl;
133  }
134  outData.close();
135 
136  if(!mTest) {
137  cout<<" prepare to upload data to DB"<<endl;
138  //- store data in table
139  vpdTotCorr->SetTable((char*)totcorr, nRow);
140  //- set store time
141  dbManager->setStoreTime(StoreTime.Data());
142  //- store table in dBase
143  dbManager->storeDbTable(vpdTotCorr);
144  cout<<"uploaded"<<endl;
145  // return 0;
146  }
147 
148 }
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