46 std::ostringstream
cmd;
51 transform(lowname.begin(), lowname.end(), lowname.begin(), (int (*)(int)) tolower);
52 cmd <<
"select * from pg_tables where tablename = '" << lowname <<
"'";
56 std::cout <<
"cmd: " << cmd.str() << std::endl;
66 std::cout << name <<
" does not exist, creating it" << std::endl;
75 cmd <<
"CREATE TABLE " << name <<
"(runnumber int NOT NULL, events int NOT NULL";
76 std::map<unsigned int, unsigned int>::const_iterator iter;
77 for (iter = packetsize.begin(); iter != packetsize.end(); ++iter)
79 cmd <<
", p_" << iter->first <<
" float DEFAULT 0";
81 cmd <<
", primary key(runnumber))";
84 std::cout <<
"Executing " << cmd.str() << std::endl;
92 std::cout <<
"Exception caught, Message: " << e.
getMessage() << std::endl;
106 std::ostringstream
cmd;
116 cmd <<
"SELECT events FROM " << table <<
" where runnumber = "
125 std::cout <<
"Exception caught, Message: " << e.
getMessage() << std::endl;
131 if (nevnts <= events)
133 std::cout <<
"Run " << runnumber <<
" already in table "
134 << table <<
" extracted from " << events <<
" Events"
136 std::cout <<
"Run more events than " << events
137 <<
" if you want to overwrite this entry" << std::endl;
144 cmd <<
"DELETE FROM " << table <<
" WHERE runnumber = " <<
runnumber;
154 std::map<unsigned int, unsigned int>::const_iterator iter;
156 std::ostringstream cmd1, cmd2;
157 cmd1 <<
"INSERT INTO " << table
158 <<
" (runnumber, events";
159 cmd2 <<
" VALUES(" << runnumber <<
", " << nevnts;
161 for (iter = packetsize.begin(); iter != packetsize.end(); ++iter)
163 cmd1 <<
", p_" << iter->first;
164 size_in_bytes = (float) (iter->second) / (float) (nevnts);
166 cmd2 <<
", " << size_in_bytes;
170 cmd << cmd1.str() << cmd2.str();
177 std::cout <<
"Exception caught, Message: " << e.
getMessage() << std::endl;
193 std::ostringstream
cmd;
194 cmd <<
"SELECT * FROM " << table <<
" WHERE runnumber = " <<
runnumber;
198 std::cout <<
"command: " << cmd.str() << std::endl;
209 if (errmsg.find(
"does not exist") == std::string::npos)
211 std::cout <<
"Exception caught, when accessing table "
212 << table << std::endl;
213 std::cout <<
"Message: " << e.
getMessage() << std::endl;
222 if (colname ==
"runnumber" || colname ==
"events")
226 std::string packet = colname.substr(colname.find_last_of(
'_') + 1);
227 std::istringstream istr(packet);
231 if (rs->
wasNull() || size <= 1.)
235 packetsize[ipkt] = size / 4.;
255 <<
" Exception caught during DriverManager::getConnection" << std::endl;
256 std::cout <<
"Message: " << e.
getMessage() << std::endl;
264 printf(
"opened DB connection\n");
275 std::ostringstream
cmd;
276 cmd <<
"SELECT * FROM " << table <<
" limit 1 ";
284 std::cout <<
"Exception caught, Message: " << e.
getMessage() << std::endl;
287 std::map<unsigned int, unsigned int>::const_iterator iter;
288 std::set<unsigned int> packetids;
289 for (iter = packetsize.begin(); iter != packetsize.end(); ++iter)
291 packetids.insert(iter->first);
296 if (colname ==
"runnumber" || colname ==
"events")
300 std::string packet = colname.substr(colname.find_last_of(
'_') + 1);
301 std::istringstream istr(packet);
304 packetids.erase(ipkt);
307 std::set<unsigned int>::const_iterator siter;
308 for (siter = packetids.begin(); siter != packetids.end(); ++siter)
310 std::ostringstream newcol;
312 newcol <<
"p_" << *siter;
314 cmd <<
"ALTER TABLE " << table <<
" ADD COLUMN " << newcol.str()
315 <<
" float DEFAULT 0";
322 std::cout <<
"Exception caught, Message: " << e.
getMessage() << std::endl;