File indexing completed on 2025-08-06 08:17:10
0001 #include "PdbParameterMapContainer.h"
0002 #include "PdbBankID.h"
0003 #include "PdbParameterMap.h"
0004
0005 #include <phool/PHTimeStamp.h>
0006 #include <phool/phool.h>
0007
0008 #include <TBufferXML.h>
0009 #include <TFile.h>
0010 #include <TSystem.h>
0011
0012 #include <boost/stacktrace.hpp>
0013
0014 #include <unistd.h>
0015 #include <algorithm>
0016 #include <cctype>
0017 #include <ctime>
0018 #include <iostream>
0019 #include <sstream>
0020
0021 PdbParameterMapContainer::~PdbParameterMapContainer()
0022 {
0023 while (parametermap.begin() != parametermap.end())
0024 {
0025 delete parametermap.begin()->second;
0026 parametermap.erase(parametermap.begin());
0027 }
0028 return;
0029 }
0030
0031 void PdbParameterMapContainer::print() const
0032 {
0033 for (auto iter : parametermap)
0034 {
0035 std::cout << "layer " << iter.first << std::endl;
0036 iter.second->print();
0037 }
0038 return;
0039 }
0040 void PdbParameterMapContainer::Reset()
0041 {
0042 while (parametermap.begin() != parametermap.end())
0043 {
0044 delete parametermap.begin()->second;
0045 parametermap.erase(parametermap.begin());
0046 }
0047 return;
0048 }
0049
0050 void PdbParameterMapContainer::AddPdbParameterMap(const int layer, PdbParameterMap *params)
0051 {
0052 if (parametermap.find(layer) != parametermap.end())
0053 {
0054 std::cout << PHWHERE << " layer " << layer << " already exists" << std::endl;
0055 std::cout << "Here is the stacktrace: " << std::endl;
0056 std::cout << boost::stacktrace::stacktrace();
0057 std::cout << std::endl
0058 << "DO NOT PANIC - this is not a segfault" << std::endl;
0059 std::cout << "Check the stacktrace for the guilty party (typically #2)" << std::endl;
0060 gSystem->Exit(1);
0061 }
0062 parametermap[layer] = params;
0063 }
0064
0065 const PdbParameterMap *
0066 PdbParameterMapContainer::GetParameters(const int layer) const
0067 {
0068 std::map<int, PdbParameterMap *>::const_iterator iter = parametermap.find(layer);
0069 if (iter == parametermap.end())
0070 {
0071 return nullptr;
0072 }
0073 return iter->second;
0074 }
0075
0076 PdbParameterMap *
0077 PdbParameterMapContainer::GetParametersToModify(const int layer)
0078 {
0079 std::map<int, PdbParameterMap *>::iterator iter = parametermap.find(layer);
0080 if (iter == parametermap.end())
0081 {
0082 return nullptr;
0083 }
0084 return iter->second;
0085 }
0086
0087 int PdbParameterMapContainer::WriteToFile(const std::string &detector_name,
0088 const std::string &extension, const std::string &dir)
0089 {
0090
0091
0092 std::ostringstream fullpath;
0093 std::ostringstream fnamestream;
0094 PdbBankID bankID(0);
0095 PHTimeStamp TStart(0);
0096 PHTimeStamp TStop(0xffffffff);
0097 fullpath << dir;
0098
0099 if (*(dir.rbegin()) != '/')
0100 {
0101 fullpath << "/";
0102 }
0103 fnamestream << detector_name << "_geoparams"
0104 << "-"
0105 << bankID.getInternalValue() << "-" << TStart.getTics() << "-"
0106 << TStop.getTics() << "-" << time(nullptr) << "." << extension;
0107 std::string fname = fnamestream.str();
0108 std::transform(fname.begin(), fname.end(), fname.begin(), ::tolower);
0109 fullpath << fname;
0110
0111 std::cout << "PdbParameterMapContainer::WriteToFile - save to " << fullpath.str()
0112 << std::endl;
0113
0114 TFile *f = TFile::Open(fullpath.str().c_str(), "recreate");
0115
0116 PdbParameterMapContainer *container = new PdbParameterMapContainer();
0117 for (std::map<int, PdbParameterMap *>::const_iterator it =
0118 parametermap.begin();
0119 it != parametermap.end(); ++it)
0120 {
0121 PdbParameterMap *myparm = dynamic_cast<PdbParameterMap *>(it->second->CloneMe());
0122 container->AddPdbParameterMap(it->first, myparm);
0123 }
0124
0125
0126
0127 std::string floatformat = TBufferXML::GetFloatFormat();
0128 TBufferXML::SetFloatFormat("%.17g");
0129 container->Write("PdbParameterMapContainer");
0130 delete f;
0131
0132 TBufferXML::SetFloatFormat(floatformat.c_str());
0133 std::cout << "sleeping 1 second to prevent duplicate inserttimes" << std::endl;
0134 sleep(1);
0135 return 0;
0136 }