StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofINLSCorr.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 storetofINLSCorr()
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-11-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 *f = new TFile("INL_test.root");
63 
64  for(int iboard=0;iboard<NMAX;iboard++) {
65  if(iboard%100==0) cout << " Processing board Id = " << iboard << endl;
66 
67  for(int itdc=0;itdc<NTDC;itdc++){
68  for(int ichan=0;ichan<NCHAN;ichan++) {
69 
70  char hisname[512];
71  sprintf(hisname,"b_%d_tdc_%d_chan_%d",iboard,itdc,ichan);
72 
73  hINLSCorr[iboard][itdc][ichan] = (TH1S *)f->Get(hisname);
74 
75  if(!hINLSCorr[iboard][itdc][ichan]) {
76 // cout << " Histogram board " << iboard << " itdc " << itdc << " ichan " << ichan << " doesn't exist!" << endl;
77  continue;
78  }
79 
80  inlcorr[NFILL].tdigId = (Short_t)iboard;
81  inlcorr[NFILL].tdcChanId = (Short_t)(itdc*NCHAN+ichan);
82 
83  for(int j=0;j<1024;j++) {
84  inlcorr[NFILL].INLCorr[j]=(Short_t)(hINLSCorr[iboard][itdc][ichan]->GetBinContent(j+1));
85  }
86 
87 
88  NFILL++;
89  } // end of loop channel
90  } // end of loop TDC
91 
92  NBOARD++;
93  hFlag[iboard] = true;
94 
95  } // end of loop board
96  cout<<" prepare to upload data to DB NFILL="<<NFILL<<" NBOARD="<<NBOARD<<endl;
97 
98 /*
99  char rootname[100];
100  sprintf(rootname,"INL_test.root");
101  TFile *fout = new TFile(rootname,"recreate");
102  int index = 0;
103  for(int iboard=0;iboard<NMAX;iboard++) {
104  if(!hFlag[iboard]) continue;
105 
106  for(int itdc=0;itdc<NTDC;itdc++){
107  for(int ichan=0;ichan<NCHAN;ichan++) {
108  if(!hINLSCorr[iboard][itdc][ichan]) continue;
109  hINLSCorr[iboard][itdc][ichan]->Write();
110 
111  cout << " Ids = " << iboard << " " << itdc << " " << ichan << endl;
112  cout << " IN Ids = " << inlcorr[index].tdigId << " " << inlcorr[index].tdcChanId << endl;
113  for(int j=0;j<1024;j++) {
114  if(j%100==0)
115  cout << " INL j = " << j << " " << inlcorr[index].INLCorr[j] << endl;
116  }
117  index++;
118  }
119  }
120  }
121  fout->Close();
122 */
123 
124  //- store data in table
125  tofINLSCorr->SetTable((char*)inlcorr, NFILL);
126  //- set store time
127  dbManager->setStoreTime(ZStoreTime.Data());
128  //- store table in dBase
129  cout<<" here "<<endl;
130  dbManager->storeDbTable(tofINLSCorr);
131  cout<<"uploaded"<<endl;
132  // return 0;
133 }
134 
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