StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofINLSCorrStep2.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 using namespace std;
19 
20 
21 void storetofINLSCorrStep2()
22 //int main(int argc, char *argv[])
23 
24 {
25 
26  const Int_t NMAX = 1200;
27  const Int_t NTDC = 3; // # of tdcs per board
28  const Int_t NCHAN = 8; // # of channels per tdc
29 
30  //-- load dBase and Table definition libraries
31  gSystem->Load("St_base");
32  gSystem->Load("StChain");
33  gSystem->Load("StUtilities");
34  gSystem->Load("St_Tables.so");
35 
36  gSystem->Load("StDbLib.so");
37  gSystem->Load("libStDb_Tables.so");
38 
39  //-- get the singleton manager
40  StDbManager* dbManager = StDbManager::Instance();
41 
42  //-- connect to the db & get an empty container
43  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
44 
45  //----------------------------------------
46  TString ZStoreTime = "2009-09-01 00:00:00";
47 
48  //-- add table to the container with descriptor given by Database
49  StDbTable* tofINLSCorr = configNode->addDbTable("tofINLSCorr");
50 
51  //-- fill structures & store times
52  tofINLSCorr_st *inlcorr= new tofINLSCorr_st[NMAX*NTDC*NCHAN];
53 
54  Int_t NFILL = 0;
55  Int_t NBOARD = 0;
56  // read in inltable file by file.
57 
58  TH1S *hINLSCorr[NMAX][NTDC][NCHAN];
59  Bool_t *hFlag[NMAX];
60  for(int i=0;i<NMAX;i++) hFlag[i] = false;
61 
62  TFile *f1 = new TFile("INL_test_0_300.root");
63  TFile *f2 = new TFile("INL_test_300_600.root");
64  TFile *f3 = new TFile("INL_test_600_900.root");
65  TFile *f4 = new TFile("INL_test_900_1200.root");
66 
67  for(int iboard=0;iboard<NMAX;iboard++) {
68  if(iboard%100==0) cout << " Processing board Id = " << iboard << endl;
69 
70  for(int itdc=0;itdc<NTDC;itdc++){
71  for(int ichan=0;ichan<NCHAN;ichan++) {
72 
73  char hisname[512];
74  sprintf(hisname,"b_%d_tdc_%d_chan_%d",iboard,itdc,ichan);
75 
76  if(iboard<300) {
77  hINLSCorr[iboard][itdc][ichan] = (TH1S *)f1->Get(hisname);
78  } else if(iboard<600) {
79  hINLSCorr[iboard][itdc][ichan] = (TH1S *)f2->Get(hisname);
80  } else if(iboard<900) {
81  hINLSCorr[iboard][itdc][ichan] = (TH1S *)f3->Get(hisname);
82  } else {
83  hINLSCorr[iboard][itdc][ichan] = (TH1S *)f4->Get(hisname);
84  }
85 
86  if(!hINLSCorr[iboard][itdc][ichan]) {
87 // cout << " Histogram board " << iboard << " itdc " << itdc << " ichan " << ichan << " doesn't exist!" << endl;
88  continue;
89  }
90 
91  inlcorr[NFILL].tdigId = (Short_t)iboard;
92  inlcorr[NFILL].tdcChanId = (Short_t)(itdc*NCHAN+ichan);
93 
94 
95  for(int j=0;j<1024;j++) {
96  inlcorr[NFILL].INLCorr[j]=(Short_t)(hINLSCorr[iboard][itdc][ichan]->GetBinContent(j+1));
97  }
98 
99 
100  NFILL++;
101  } // end of loop channel
102  } // end of loop TDC
103 
104  NBOARD++;
105  hFlag[iboard] = true;
106 
107  } // end of loop board
108  cout<<" prepare to upload data to DB NFILL="<<NFILL<<" NBOARD="<<NBOARD<<endl;
109 
110  char rootname[100];
111  sprintf(rootname,"INL_test.root");
112  TFile *fout = new TFile(rootname,"recreate");
113  int index = 0;
114  for(int iboard=0;iboard<NMAX;iboard++) {
115  if(!hFlag[iboard]) continue;
116 
117  for(int itdc=0;itdc<NTDC;itdc++){
118  for(int ichan=0;ichan<NCHAN;ichan++) {
119  if(!hINLSCorr[iboard][itdc][ichan]) continue;
120  hINLSCorr[iboard][itdc][ichan]->Write();
121 
122 /*
123  cout << " Ids = " << iboard << " " << itdc << " " << ichan << endl;
124  cout << " IN Ids = " << inlcorr[index].tdigId << " " << inlcorr[index].tdcChanId << endl;
125  for(int j=0;j<1024;j++) {
126  if(j%100==0)
127  cout << " INL j = " << j << " " << inlcorr[index].INLCorr[j] << endl;
128  }
129 */
130  index++;
131  }
132  }
133  }
134  fout->Close();
135 
136  //- store data in table
137 /*
138  tofINLSCorr->SetTable((char*)inlcorr, NFILL);
139  //- set store time
140  dbManager->setStoreTime(ZStoreTime.Data());
141  //- store table in dBase
142  cout<<" here "<<endl;
143  dbManager->storeDbTable(tofINLSCorr);
144  cout<<"uploaded"<<endl;
145  // return 0;
146 */
147 }
148 
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155