3 #include <pdbcalbase/PdbApplication.h>
4 #include <pdbcalbase/PdbBankID.h>
5 #include <pdbcalbase/PdbBankManager.h>
6 #include <pdbcalbase/PdbCalBank.h>
7 #include <pdbcalbase/PdbParameterMap.h>
8 #include <pdbcalbase/PdbParameterMapContainer.h>
16 #include <TBufferXML.h>
20 #include <boost/foreach.hpp>
21 #include <boost/functional/hash.hpp>
22 #include <boost/lexical_cast.hpp>
23 #include <boost/stacktrace.hpp>
24 #include <boost/tokenizer.hpp>
61 std::cout <<
PHWHERE <<
" integer parameter " << name
62 <<
" does not exist (forgot to set?)" << std::endl;
63 std::cout <<
"Here is the stacktrace: " << std::endl;
64 std::cout << boost::stacktrace::stacktrace();
65 std::cout << std::endl
66 <<
"DO NOT PANIC - this is not a segfault" << std::endl;
67 std::cout <<
"Check the stacktrace for the guilty party (typically #2)" << std::endl;
83 std::cout <<
"int parameters: " << std::endl;
84 for (std::map<const std::string, int>::const_iterator iter =
m_IntParMap.begin();
87 std::cout << iter->first <<
": " << iter->second << std::endl;
104 std::cout <<
PHWHERE <<
" double parameter " << name
105 <<
" does not exist (forgot to set?)" << std::endl;
106 std::cout <<
"Here is the stacktrace: " << std::endl;
107 std::cout << boost::stacktrace::stacktrace();
108 std::cout << std::endl
109 <<
"DO NOT PANIC - this is not a segfault" << std::endl;
110 std::cout <<
"Check the stacktrace for the guilty party (typically #2)" << std::endl;
127 std::cout <<
"Parameters for " <<
m_Detector << std::endl;
148 for (iMap::const_iterator iter =
m_IntParMap.begin();
171 std::cout <<
"double parameters: " << std::endl;
172 for (std::map<const std::string, double>::const_iterator iter =
m_DoubleParMap.begin();
175 std::cout << iter->first <<
": " << iter->second << std::endl;
192 std::cout <<
PHWHERE <<
" string parameter " << name
193 <<
" does not exist (forgot to set?)" << std::endl;
194 std::cout <<
"Here is the stacktrace: " << std::endl;
195 std::cout << boost::stacktrace::stacktrace();
196 std::cout << std::endl
197 <<
"DO NOT PANIC - this is not a segfault" << std::endl;
198 std::cout <<
"Check the stacktrace for the guilty party (typically #2)" << std::endl;
214 std::cout <<
"string parameters: " << std::endl;
215 for (std::map<const std::string, std::string>::const_iterator iter =
m_StringParMap.begin();
218 std::cout << iter->first <<
": " << iter->second << std::endl;
227 std::pair<std::map<const std::string, double>::const_iterator,
228 std::map<const std::string, double>::const_iterator>
230 for (std::map<const std::string, double>::const_iterator iter = begin_end_d.first;
231 iter != begin_end_d.second; ++iter)
235 std::pair<std::map<const std::string, int>::const_iterator,
236 std::map<const std::string, int>::const_iterator>
238 for (std::map<const std::string, int>::const_iterator iter = begin_end_i.first;
239 iter != begin_end_i.second; ++iter)
243 std::pair<std::map<const std::string, std::string>::const_iterator,
244 std::map<const std::string, std::string>::const_iterator>
246 for (std::map<const std::string, std::string>::const_iterator iter = begin_end_s.first;
247 iter != begin_end_s.second; ++iter)
264 std::pair<std::map<const std::string, double>::const_iterator,
265 std::map<const std::string, double>::const_iterator>
267 for (std::map<const std::string, double>::const_iterator iter = begin_end_d.first;
268 iter != begin_end_d.second; ++iter)
272 std::pair<std::map<const std::string, int>::const_iterator,
273 std::map<const std::string, int>::const_iterator>
275 for (std::map<const std::string, int>::const_iterator iter = begin_end_i.first;
276 iter != begin_end_i.second; ++iter)
280 std::pair<std::map<const std::string, std::string>::const_iterator,
281 std::map<const std::string, std::string>::const_iterator>
283 for (std::map<const std::string, std::string>::const_iterator iter = begin_end_s.first;
284 iter != begin_end_s.second; ++iter)
296 for (dMap::const_iterator iter = saveparams->
m_DoubleParMap.begin();
302 for (iMap::const_iterator iter = saveparams->
m_IntParMap.begin();
308 for (strMap::const_iterator iter = saveparams->
m_StringParMap.begin();
319 PdbParameterMap *nodeparams = findNode::getClass<PdbParameterMap>(topNode, nodename);
324 topNode->addNode(newnode);
336 PdbParameterMap *nodeparams = findNode::getClass<PdbParameterMap>(topNode, nodename);
339 std::cout <<
PHWHERE <<
" could not find PdbParameterMap " << nodename
340 <<
" which must exist" << std::endl;
351 if (!nodeparamcontainer)
356 topNode->addNode(newnode);
375 if (!nodeparamcontainer)
377 std::cout <<
PHWHERE <<
" could not find PdbParameterMapContainer " << nodename
378 <<
" which must exist" << std::endl;
384 std::cout <<
PHWHERE <<
" could not find PdbParameterMap for detector " << detid
385 <<
" which must exist" << std::endl;
398 std::cout <<
PHWHERE <<
" Aborting, Database not writable" << std::endl;
399 application->
abort();
409 std::string tablename =
m_Detector +
"_geoparams";
410 std::transform(tablename.begin(), tablename.end(), tablename.begin(), ::tolower);
412 "Geometry Parameters", TStart, TStop, tablename);
418 application->
commit(NewBank);
423 std::cout <<
PHWHERE " Committing to DB failed" << std::endl;
435 std::cout <<
PHWHERE <<
" Aborting, Database not readable" << std::endl;
436 application->
abort();
445 std::string tablename = name +
"_geoparams";
446 std::transform(tablename.begin(), tablename.end(), tablename.begin(), ::tolower);
447 PdbCalBank *NewBank = bankManager->
fetchBank(
"PdbParameterMapContainerBank", bankID, tablename, TSearch);
456 std::cout <<
PHWHERE " Reading from DB failed" << std::endl;
468 std::cout <<
PHWHERE <<
" Aborting, Database not readable" << std::endl;
469 application->
abort();
478 std::string tablename =
m_Detector +
"_geoparams";
479 std::transform(tablename.begin(), tablename.end(), tablename.begin(),
491 std::cout <<
PHWHERE " Reading from DB failed" << std::endl;
499 std::ostringstream fullpath;
500 std::ostringstream fnamestream;
506 if (*(dir.rbegin()) !=
'/')
514 std::string
fname = fnamestream.str();
515 std::transform(fname.begin(), fname.end(), fname.begin(), ::tolower);
518 std::cout <<
"PHParameters::WriteToFile - save to " << fullpath.str() << std::endl;
522 TFile *
f = TFile::Open(fullpath.str().c_str(),
"recreate");
525 std::string floatformat = TBufferXML::GetFloatFormat();
526 TBufferXML::SetFloatFormat(
"%.17g");
530 TBufferXML::SetFloatFormat(floatformat.c_str());
531 std::cout <<
"sleeping 1 second to prevent duplicate inserttimes" << std::endl;
540 std::ostringstream fnamestream;
541 fnamestream << name <<
"_geoparams"
543 std::string fileprefix = fnamestream.str();
544 std::transform(fileprefix.begin(), fileprefix.end(), fileprefix.begin(),
546 std::filesystem::path targetDir(dir);
548 std::filesystem::recursive_directory_iterator diriter(targetDir), eod;
549 boost::char_separator<char> sep(
"-.");
550 std::map<unsigned int, std::string> calibfiles;
551 BOOST_FOREACH (std::filesystem::path
const &i, std::make_pair(diriter, eod))
553 if (is_regular_file(i))
558 std::string basename = i.filename().string();
559 if (basename.compare(0, fileprefix.size(), fileprefix) != 0)
566 if (i.extension().string().find(extension) == std::string::npos || i.extension().string().size() != extension.size() + 1)
570 boost::tokenizer<boost::char_separator<char> > tok(basename, sep);
571 boost::tokenizer<boost::char_separator<char> >::iterator iter =
576 if (TSearch < TStart)
582 if (TSearch >= TStop)
590 if (calibfiles.empty())
592 std::cout <<
"No calibration file like " << dir <<
"/" << fileprefix <<
" found" << std::endl;
595 std::cout <<
"PHParameters::ReadFromFile - Reading from File: " << (calibfiles.rbegin())->
second <<
" ... ";
597 TFile *
f = TFile::Open(fname.c_str());
604 std::cout <<
"Missing PdbParameterMapContainer Detector Id " << detid << std::endl;
607 std::cout <<
"Received PdbParameterMapContainer Detector Id " << detid <<
" with (Hash = 0x" << std::hex << myparm->
GetParameters(detid)->
get_hash() << std::dec <<
")" << std::endl;
616 std::cout <<
"Received PdbParameterMap with (Hash = 0x" << std::hex << myparm->
get_hash() << std::dec <<
")" << std::endl;
628 for (std::map<const std::string, double>::const_iterator iter =
m_DoubleParMap.begin();
633 for (std::map<const std::string, int>::const_iterator iter =
m_IntParMap.begin();
638 for (std::map<const std::string, std::string>::const_iterator iter =
m_StringParMap.begin();
651 tics = boost::lexical_cast<
unsigned int>(str);
653 catch (boost::bad_lexical_cast
const &)
655 std::cout <<
"Cannot extract timestamp from " << str << std::endl;