20 #include "CoolKernel/DatabaseId.h"
21 #include "CoolKernel/Exception.h"
22 #include "CoolKernel/IDatabaseSvc.h"
23 #include "CoolKernel/IDatabase.h"
24 #include "CoolKernel/IFolder.h"
25 #include "CoolKernel/FolderSpecification.h"
26 #include "CoolKernel/IObject.h"
27 #include "CoolKernel/Record.h"
28 #include "CoolApplication/DatabaseSvcFactory.h"
31 #include "SealBase/Time.h"
35 DCSTxtToCool(
const std::string& cooldb,
const std::string& configfile,
36 const std::string& datafile,
const int offset);
40 static bool getCoolDB(
const std::string& coolst, cool::IDatabasePtr& dbPtr);
41 static void readMap(
const std::string& configfile);
46 const cool::IRecordSpecification& atrspec);
60 typedef std::map<std::string, DataPointInfo*>
DPMap;
67 const std::string& configfile,
const std::string& datafile,
const int offset) :
68 m_coolstr(cooldb), m_configfile(configfile), m_datafile(datafile),
70 m_ndata(0), m_datap(
""), m_vkmin(
cool::ValidityKeyMax), m_vkmax(0) {
71 std::cout <<
"Read data into COOL db: " <<
m_coolstr << std::endl;
72 std::cout <<
"Datapoint configuration file: " <<
m_configfile << std::endl;
73 std::cout <<
"Data file: " <<
m_datafile << std::endl;
74 std::cout <<
"Time offset " <<
m_timeoffset <<
" hours" << std::endl;
80 std::cout <<
"COOL database opened" << std::endl;
82 std::cout <<
"Database open fails" << std::endl;
90 std::vector<char>
buffer(999);
96 if (sline.substr(0,3)==
"200") {
98 std::string sdate,
stime;
100 std::istringstream sbuf(&
buffer[0]);
104 year=
atoi(sdate.substr(0,4).c_str());
106 month=
atoi(sdate.substr(5,2).c_str())-1;
107 day=
atoi(sdate.substr(8,2).c_str());
114 seal::TimeSpan tofs=seal::TimeSpan(3600*
m_timeoffset,0);
117 }
else if (sline.size()>2) {
125 std::cout <<
"Read total of " << nobj <<
" lines from data file" << std::endl;
132 while (datap.substr(datap.size()-1,1)==
"\r")
135 std::cout <<
"Begin processing datapoint " << datap << std::endl;
136 std::string key0=
m_dpmap.begin()->first;
137 DPMap::const_iterator fitr=
m_dpmap.find(datap);
141 std::cout <<
"Associated datapoint to folder " <<
m_dpinfo->
folder() <<
149 std::cout <<
"No valid folder to store data: " <<
e.what()
154 std::cout <<
"ERROR: No mapping defined for datapoint " << datap <<
178 std::cout <<
"Attempt to write " <<
m_ndata <<
" data points but no folder"
182 std::cout <<
"Write " <<
m_ndata <<
" values [" <<
191 std::cout <<
"Bulk insertion failed for folder " <<
193 ", reason: " <<
e.what() << std::endl;
202 cool::IDatabasePtr& dbPtr) {
203 std::cout <<
"Attempt to open COOL database with connection string: "
204 << coolstr << std::endl;
205 cool::IDatabaseSvc&
dbSvc=cool::DatabaseSvcFactory::databaseService();
207 dbPtr=
dbSvc.openDatabase(coolstr,
false);
211 std::cout <<
"COOL exception caught: " <<
e.what() << std::endl;
212 std::cout <<
"Try to create new conditions DB" << std::endl;
214 dbPtr=
dbSvc.createDatabase(coolstr);
215 std::cout <<
"Creation succeeded" << std::endl;
219 std::cout <<
"Creation failed" << std::endl;
227 std::cout <<
"Read configuration from file: " << configfile << std::endl;
232 infile.open(configfile.c_str());
238 cool::RecordSpecification atrspec;
239 atrspec.extend(
column,cool::StorageType::Float);
241 m_dpmap.insert(std::pair<std::string,DataPointInfo*>(dpname,dptr));
256 std::cout <<
"Read " << nobj <<
" lines from file, giving " <<
257 m_dpmap.size() <<
" datapoint mappings " << std::endl;
258 std::cout <<
"Total of " <<
m_folderlist.size() <<
" COOL folders used" <<
261 std::cout <<
"Folder " <<
m_folderlist[
i] <<
" channel count " <<
266 const cool::IRecordSpecification& atrspec) {
268 std::cout <<
"Folder " <<
folder <<
" already exists in database"
272 std::cout <<
"Folder " <<
folder <<
" not found - try to create it" <<
280 std::string
desc=
"dummy";
281 if (
nchan==1)
desc=
"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"40774348\" /></addrHeader><typeName>AthenaAttributeList</typeName>";
282 if (
nchan>1)
desc=
"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>";
283 std::cout <<
"Folder description string set to: " <<
desc << std::endl;
284 cool::IFolderPtr folderptr=
m_coolDb->createFolder(
folder,cool::FolderSpecification(cool::FolderVersioning::SINGLE_VERSION,atrspec),
desc,
true);
291 std::cout <<
"Syntax: DCSTxtToCool,exe <coolDBconnection> <configfile> <datafile> {<offset>}" << std::endl;
294 std::string coolstr=
argv[1];
295 std::string configfile=
argv[2];
296 std::string datafile=
argv[3];