StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tofStatus.C
1 //This generates a projected channel map of TOF.
2 
3 #include <iostream>
4 #include <fstream>
5 #include <string>
6 #include <iomanip>
7 using namespace std;
8 
9 
10 //update headers
11 
12 
13 void tofStatus(){
14  const Int_t NTRAY = 120;
15  const Int_t NCHANNELTRAY = 192;
16  const Int_t NCHANNELTOTAL = 23040;
17  const Int_t NCHANNELMODULE = 6;
18  Short_t tofmap[NCHANNELTOTAL]; //Make 120 trays of 192 channels. They can either be usable(1) or not(0).
19 
20 
21 //-- load dBase and Table definition libraries
22  gSystem->Load("St_base");
23  gSystem->Load("StChain");
24  gSystem->Load("StUtilities");
25  gSystem->Load("St_Tables.so");
26  gSystem->Load("StDbLib.so");
27  gSystem->Load("libStDb_Tables.so");
28 
29 //-- get the singleton manager
30  StDbManager* dbManager = StDbManager::Instance();
31 
32 //-- connect to the db & get an empty container
33  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");//Not really a calibration.
34 
35 //-- add table to the container with descriptor given by Database
36  StDbTable* tofStatus = configNode->addDbTable("tofStatus");//
37 
38 //--fill structures and store times
39  tofStatus_st *Status = new tofStatus_st[1];
40 
41 
42 //----------------------------------------
43 // Commit log:
44  // Note: start time is part of the configuration file (the following line is only to set a default)
45  TString ZStoreTime = "2011-12-20 00:00:02"; //Default start time, user can enter more.
46 
47 
48  //Initialize all the channels
49  for(int channel = 0; channel<NCHANNELTOTAL; channel++){
50  tofmap[channel]=1; //set all channels as good
51  }//end of nchannels loop
52 
53  TString Date,Time;
54  Int_t nEntries=0;
55  Int_t inputTray[100]={0},inputModule[100]={0},inputChannel[100]={0};
56 /*
57  Now for user input
58  Expect the format" Date, Time, number of entries, tray, module, channel, tray, module, channel...
59  Tray 1-120, Module 1-32, Channel 1-6. Set tray,module or channel to 0 for a whole range to be cleared.
60  channel=0, sets that module bad, module=0 sets that tray bad, and tray=0 sets all of tof bad.
61  Entries=0, enables all trays.
62  Eg: tray=1,module=2,channel=0 all of module 2 set bad.
63  Sample format for the input file:
64 
65 2012-01-01 00:00:01 8
66 95 0 0
67 102 0 0
68 33 23 6
69 76 28 1
70 77 1 6
71 39 13 0
72 39 14 1
73 39 14 2
74 */
75 
76 
77  //May want to add multiple date entries to make this easier.
78 
79  ifstream inData;
80  inData.open("data/run13/tofStatus/badtofentry.txt");
81  inData >> Date >> Time >> nEntries;
82 
83  cout<<"Date: "<<Date<<", Entries: "<<nEntries<<endl;
84 // Int_t inputTray[nEntries],inputModule[nEntries],inputChannel[nEntries];
85 
86 
87  for(int entry=0;entry<nEntries;entry++){
88  inData >> inputTray[entry] >> inputModule[entry] >> inputChannel[entry];
89  cout<<"tray,module,channel: "<<inputTray[entry]<<", "<<inputModule[entry]<<", "<<inputChannel[entry]<<endl;
90  }//entries
91  inData.close();
92 
93 
94  Date.Append(" ");
95  ZStoreTime = Date.Append(Time);
96  cout <<"Date+time and ZStoreTime : "<<Date<<", "<<ZStoreTime<<endl;
97 
98 
99  if(nEntries==0) cout<< "Enabling All Trays--Entries=0" <<endl;
100 
101 
102  for(int entry=0;entry<nEntries;entry++){
103 
104  //Mapping whole trays, modules, or channels.
105  if(nEntries==0) continue; //Set only default values.
106 
107  if(inputTray[entry]==0){//tray==0 Set all of tof disabled.
108  cout <<"Caution: Disabling all trays"<<endl;
109  for(int channel=0;channel<NCHANNELTOTAL;channel++) tofmap[channel]=0;
110  }
111 
112  if(inputTray[entry]!=0&&inputModule[entry]==0){//module==0 Set the whole tray disabled.
113  //Tray
114  for(int channel =0;channel<NCHANNELTRAY;channel++){
115  tofmap[(inputTray[entry]-1)*NCHANNELTRAY+channel]=0;
116  }//
117  }
118 
119  if(inputTray[entry]!=0&&inputModule[entry]!=0&&inputChannel[entry]==0){//channel==0 Set that module disabled
120 
121  //
122  for(int channel =0;channel<NCHANNELMODULE;channel++){
123  tofmap[(inputTray[entry]-1)*NCHANNELTRAY+channel+(inputModule[entry]-1)*NCHANNELMODULE]=0;
124  }//module
125  }
126 
127  //Channel
128  if((inputTray[entry]!=0)&&(inputModule[entry]!=0)&&(inputChannel[entry]!=0)){
129  tofmap[(inputTray[entry]-1)*NCHANNELTRAY+(inputModule[entry]-1)*NCHANNELMODULE+inputChannel[entry]-1]=0;
130  }
131  }//entries
132 
133 
134 
135  // Move values to Status table.
136  for(int tray=0;tray<NTRAY;tray++){
137  for(int channel=0;channel<NCHANNELTRAY;channel++){
138  if (0) cout <<"Tray, channel, map: "<<tray<<", "<<channel<<", "<< tofmap[tray*NCHANNELTRAY+channel]<<endl;
139  Status[0].status[channel+tray*NCHANNELTRAY]=tofmap[tray*NCHANNELTRAY+channel];
140  }//channel
141  }
142 
143 
144  //Upload to Database.
145  tofStatus->SetTable((char*)Status,1);
146  //time
147  dbManager->setStoreTime(ZStoreTime.Data());
148  dbManager->storeDbTable(tofStatus);
149  cout<<"Done."<<endl;
150 
151 }//end of tofStatus
152 
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