16 #include <TSQLServer.h>
34 SQRun* run_header = findNode::getClass<SQRun>(topNode,
"SQRun");
37 ClearTable(
"spill" , run_id);
38 ClearTable(
"scaler_bos" , run_id);
39 ClearTable(
"scaler_eos" , run_id);
40 ClearTable(
"slow_cont_DAQ" , run_id);
41 ClearTable(
"slow_cont_beam" , run_id);
42 ClearTable(
"slow_cont_environment", run_id);
43 ClearTable(
"slow_cont_target ", run_id);
49 SQSpillMap* spill_map = findNode::getClass<SQSpillMap >(topNode,
"SQSpillMap");
50 SQEvent* event_header = findNode::getClass<SQEvent >(topNode,
"SQEvent");
53 static int spill_id_pre = -1;
54 if (event_header->get_spill_id() != spill_id_pre) {
55 spill_id_pre = event_header->get_spill_id();
58 UploadToSpillTable(spi);
59 UploadToScalerTable(spi,
"bos");
60 UploadToScalerTable(spi,
"eos");
61 UploadToSlowContTable(spi);
72 void DbUpSpill::ClearTable(
const char* table_name,
const int run_id)
76 if (! db.HasTable(table_name))
return;
78 oss <<
"delete from " << table_name <<
" where run_id = " << run_id;
79 if (! db.Con()->Exec(oss.str().c_str())) {
80 cerr <<
"!!ERROR!! DbUpSpill::ClearTables(): table = " << table_name <<
", run_id = " << run_id <<
"." << endl;
85 void DbUpSpill::UploadToSpillTable(
SQSpill* spi)
87 const char* table_name =
"spill";
91 if (! db.HasTable(table_name)) {
93 list.
Add(
"run_id" ,
"INT",
true);
94 list.
Add(
"spill_id" ,
"INT",
true);
95 list.
Add(
"target_pos" ,
"INT");
96 list.
Add(
"bos_coda_id" ,
"INT");
97 list.
Add(
"bos_vme_time",
"INT");
98 list.
Add(
"eos_coda_id" ,
"INT");
99 list.
Add(
"eos_vme_time",
"INT");
100 db.CreateTable(table_name, list);
104 oss <<
"delete from " << table_name <<
" where run_id = " << spi->
get_run_id() <<
" and spill_id = " << spi->
get_spill_id();
105 if (! db.Con()->Exec(oss.str().c_str())) {
106 cerr <<
"!!ERROR!! DbUpSpill::UploadToSpillTable()." << endl;
110 oss <<
"insert into " << table_name <<
" values"
119 if (! db.Con()->Exec(oss.str().c_str())) {
120 cerr <<
"!!ERROR!! DbUpSpill::UploadToSpillTable()." << endl;
125 void DbUpSpill::UploadToScalerTable(
SQSpill* spi,
const std::string boseos)
133 cerr <<
"!!ERROR!! DbUpSpill::UploadToScalerTable(): " << boseos <<
"?" << endl;
138 oss <<
"scaler_" << boseos;
139 string table_name = oss.str();
144 if (! db.HasTable(table_name)) {
146 list.
Add(
"run_id" ,
"INT",
true);
147 list.
Add(
"spill_id",
"INT",
true);
148 list.
Add(
"name" ,
"VARCHAR(32)",
true);
149 list.
Add(
"count" ,
"INT");
150 db.CreateTable(table_name, list);
154 oss <<
"delete from " << table_name <<
" where run_id = " << run_id <<
" and spill_id = " << spill_id;
155 if (! db.Con()->Exec(oss.str().c_str())) {
156 cerr <<
"!!ERROR!! DbUpSpill::UploadToScalerTable()." << endl;
160 oss <<
"insert into " << table_name <<
" values";
162 string name = it->first;
164 oss <<
" (" << run_id <<
", " << spill_id <<
", '" << name <<
"', " << sca->
get_count() <<
"),";
166 oss.seekp(-1, oss.cur);
168 if (! db.Con()->Exec(oss.str().c_str())) {
169 cerr <<
"!!ERROR!! DbUpSpill::UploadToScalerTable()." << endl;
174 void DbUpSpill::UploadToSlowContTable(
SQSpill* spi)
180 typedef map<string, ostringstream> OssMap_t;
183 string name = it->first;
184 if (name ==
"U:TODB25")
continue;
187 if (name ==
"SLOWCONTROL_IS_GOOD") type =
"DAQ";
188 map_oss[type] <<
" (" << run_id <<
", " << spill_id <<
", '" << name <<
"', '" << slo->
get_time_stamp() <<
"', '" << slo->
get_value() <<
"'),";
195 for (OssMap_t::iterator it = map_oss.begin(); it != map_oss.end(); it++) {
196 string type = it->first;
197 string values = it->second.str();
198 if (values.size() == 0)
continue;
200 string table_name =
"slow_cont_";
203 if (! db.HasTable(table_name)) {
205 list.
Add(
"run_id" ,
"INT",
true);
206 list.
Add(
"spill_id" ,
"INT",
true);
207 list.
Add(
"name" ,
"VARCHAR(64)",
true);
208 list.
Add(
"time_stamp",
"CHAR(14)");
209 list.
Add(
"value" ,
"TEXT");
210 db.CreateTable(table_name, list);
213 oss <<
"delete from " << table_name <<
" where run_id = " << run_id <<
" and spill_id = " << spill_id;
214 if (! db.Con()->Exec(oss.str().c_str())) {
215 cerr <<
"!!ERROR!! DbUpSpill::UploadToSlowContTable()." << endl;
219 oss <<
"insert into " << table_name <<
" values" << values;
220 oss.seekp(-1, oss.cur);
222 if (! db.Con()->Exec(oss.str().c_str())) {
223 cerr <<
"!!ERROR!! DbUpSpill::UploadToSlowContTable()." << endl;
229 void DbUpSpill::PrintSpill(
SQSpill* spi)
241 string name = it->first;
243 cout <<
" " << setw(20) << name <<
" " << setw(10) << sca->
get_count() <<
"\n";
247 string name = it->first;
249 cout <<
" " << setw(20) << name <<
" " << setw(10) << sca->
get_count() <<
"\n";
253 string name = it->first;
int process_event(PHCompositeNode *topNode)
An SQ interface class to hold the data of one scaler channel.
virtual std::string get_type() const
Return the type (i.e. caterogy name) of this channel.
virtual int get_run_id() const
Return the run ID when this spill was taken.
virtual ConstIter begin() const
virtual int get_count() const
Return the count of this scaler channel.
virtual std::string get_value() const
Return the value of this channel.
virtual size_t size() const
virtual int get_bos_vme_time() const
Return the VME time at BOS of this spill.
An SQ interface class to hold the data of one slow-control channel.
int Init(PHCompositeNode *topNode)
virtual short get_target_pos() const
Return the target position in this spill.
virtual SQStringMap * get_bos_scaler_list()
Return the list of scaler variables read out at BOS.
virtual int get_spill_id() const
Return the spill ID.
void Add(const std::string name, const std::string type, const bool is_key=false)
virtual SQStringMap * get_eos_scaler_list()
Return the list of scaler variables read out at EOS.
static std::string GetSchemaMainDaq()
virtual int get_bos_coda_id() const
Return the Coda ID at BOS of this spill.
An SQ interface class to hold the data of one spill.
virtual ConstIter end() const
A general-purpose SQ interface class that holds a list of PHObjects with key = string.
int End(PHCompositeNode *topNode)
Called at the end of all processing.
virtual int get_eos_vme_time() const
Return the VME time at EOS of this spill.
int InitRun(PHCompositeNode *topNode)
An SQ interface class to hold one event header.
virtual int get_run_id() const
Return the run ID.
virtual std::string get_time_stamp() const
Return the time when this channel was read out.
An SQ interface class to hold the run-level info.
virtual SQStringMap * get_slow_cont_list()
Return the list of slow control variables.
DbUpSpill(const std::string &name="DbUpSpill")
An SQ interface class to hold a list of SQSpill objects.
virtual int get_eos_coda_id() const
Return the Coda ID at EOS of this spill.
ObjectMap::const_iterator ConstIter
virtual const SQSpill * get(unsigned int idkey) const
Return the SQSpill entry having spill ID = 'idkey'. Return '0' if no entry exists.