StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
insertDriftVelocity.C
1 //
2 // macro to transfer data from a ASCII file to data base
3 //
4 
5 #define NUMBER_OF_HYBRIDS 432
6 #define MEAN_VELOC 695934
7 #include <fstream.h>
8 #include "/afs/rhic/star/packages/DEV/StRoot/StDbLib/StDbDefs.hh"
9 
10 void insertDriftVelocity(char* unixTime = 0, Bool_t write = kFALSE)
11 {
12  // DB-specific libs
13  gSystem->Load("libStDb_Tables.so");
14  gSystem->Load("StDbLib");
15  gSystem->Load("StDbBroker");
16 
17  ifstream file("driftVeloc_01_23_04.txt");
18  ofstream fileout("outTest.txt");
19 
20  float veloc, time, sum;
21  int index, i=0;
22  // define IDs
23  int* rowIDs=new int[NUMBER_OF_HYBRIDS];
24  // define new table to be stored
25  svtDriftVelAvg_st *driftVelocity = new svtDriftVelAvg_st[NUMBER_OF_HYBRIDS];
26 
27  while (kTRUE) {
28 
29  // read drift velocity file
30  file >> index >> veloc >> time;
31 
32  if (file.eof()) break;
33 
34  fileout << index << " " << veloc << " " << time << endl;
35 
36  if ((veloc > MEAN_VELOC*1.50) || (veloc < MEAN_VELOC*0.50)) {
37  cout << "Bad drift velocity : " << veloc << endl;
38  veloc = MEAN_VELOC;
39  }
40  else {
41  sum += veloc;
42  i++;
43  }
44  rowIDs[index]=index;
45  driftVelocity[index].averageDriftVelocity = veloc;
46 
47  }
48 
49  /*
50  for (int i=0;i<432;i++) {
51  rowIDs[i]=i;
52  driftVelocity[i].averageDriftVelocity = 675000;
53  }
54  */
55 
56  cout << "Mean drift velocity : " << sum/i << endl;
57 
58  if (write) {
60  StDbConfigNode* svtCalibNode = mgr->initConfig(dbCalibrations,dbSvt); StDbTable* svtCalibTable = svtCalibNode->addDbTable("svtDriftVelAvg");
61  svtCalibTable->SetTable((char*)driftVelocity,NUMBER_OF_HYBRIDS,rowIDs);
62  mgr->setStoreTime(unixTime);
63  cout<<" Will attempt store with timestamp="<<mgr->getDateStoreTime()<<endl; mgr->storeDbTable(svtCalibTable);
64  delete [] driftVelocity;
65  }
66 
67 }
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