StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
write_fgt_status.C
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <iomanip>
4 #include "fgtPedestal.h"
5 
6 void write_fgt_status(int runnumber, char* date, char* time, int opt=0){
7  char storeTime[200];
8  sprintf(storeTime,"%s %s",date,time);
9  cout <<"Run"<<runnumber<<" the RTS Start date and time is " << storeTime<<endl;
10 
11  gSystem->Setenv("DB_ACCESS_MODE", "write");
12  gROOT->Macro("LoadLogger.C");
13  gSystem->Load("St_base.so");
14  gSystem->Load("libStDb_Tables.so");
15  gSystem->Load("StDbLib.so");
16 
17  // Initialize db manager
19  StDbConfigNode* node = mgr->initConfig("Calibrations_fgt");
20  StDbTable* dbtable = node->addDbTable("fgtStatus");
21 
22  cout <<"The RTS Start date and time is " << storeTime<<endl;
23  mgr->setStoreTime(storeTime);
24 
25  // Create your c-struct
26  fgtStatus_st table;
27 
28  int yearday=runnumber/1000;
29  TString infile = "";
30  infile +=yearday;
31  infile +="/status/status.";
32  infile +=runnumber;
33  infile +=".txt";
34  cout<<" Opening File "<<infile<<endl;
35 
36  std::ifstream in(infile);
37  if (!in.is_open()) {
38  cout << "Can't find file!\n";
39  exit(0);
40  }
41 
42 
43  Int_t electId,stat;//electronic Id
44  Int_t zero = 128;//if this channel does not have a determined pedestal set it to bad
45  Int_t counter=0;
46  Char_t status;//status
47  TString statread;
48 
49  //initialize all entries to 0 ie good
50  for (int i = 0; i < 51200; i++) {
51  table.Status[i] = (Char_t)zero;
52  }
53 
54  //read in file of electId and status
55  while(in >> electId >>statread){
56 
57  statread.Remove(0,2);
58  stat = statread.Atoi();
59  status = (Char_t)stat;
60  cout<<counter++<<" electId="<<electId<<" stat ="<<statread<<" status="<<(Short_t)status<<endl;
61  table.Status[electId] = status;
62  }
63 
64  // Store data to the StDbTable
65  dbtable->SetTable((char*)&table, 1);
66 
67  // Store table to database
68  if(opt){
69  mgr->storeDbTable(dbtable);
70  }else{
71  printf("Not interting... specify opt=1 to actually insert into DB\n");
72  }
73 }
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