ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PdbParameterMapContainer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PdbParameterMapContainer.cc
2 #include "PdbBankID.h"
3 #include "PdbParameterMap.h"
4 
5 #include <phool/PHTimeStamp.h>
6 #include <phool/phool.h>
7 
8 #include <TBufferXML.h>
9 #include <TFile.h>
10 #include <TSystem.h>
11 
12 #include <boost/stacktrace.hpp>
13 
14 #include <unistd.h>
15 #include <algorithm>
16 #include <cctype>
17 #include <ctime>
18 #include <iostream>
19 #include <sstream>
20 
21 using namespace std;
22 
24 {
25  while (parametermap.begin() != parametermap.end())
26  {
27  delete parametermap.begin()->second;
28  parametermap.erase(parametermap.begin());
29  }
30  return;
31 }
32 
34 {
35  for (map<int, PdbParameterMap *>::const_iterator iter = parametermap.begin();
36  iter != parametermap.end(); ++iter)
37  {
38  cout << "layer " << iter->first << endl;
39  iter->second->print();
40  }
41  return;
42 }
44 {
45  while (parametermap.begin() != parametermap.end())
46  {
47  delete parametermap.begin()->second;
48  parametermap.erase(parametermap.begin());
49  }
50  return;
51 }
52 
54 {
55  if (parametermap.find(layer) != parametermap.end())
56  {
57  cout << PHWHERE << " layer " << layer << " already exists" << endl;
58  cout << "Here is the stacktrace: " << endl;
59  cout << boost::stacktrace::stacktrace();
60  cout << endl
61  << "DO NOT PANIC - this is not a segfault" << endl;
62  cout << "Check the stacktrace for the guilty party (typically #2)" << endl;
63  gSystem->Exit(1);
64  }
65  parametermap[layer] = params;
66 }
67 
68 const PdbParameterMap *
70 {
71  map<int, PdbParameterMap *>::const_iterator iter = parametermap.find(layer);
72  if (iter == parametermap.end())
73  {
74  return nullptr;
75  }
76  return iter->second;
77 }
78 
81 {
82  map<int, PdbParameterMap *>::iterator iter = parametermap.find(layer);
83  if (iter == parametermap.end())
84  {
85  return nullptr;
86  }
87  return iter->second;
88 }
89 
90 int PdbParameterMapContainer::WriteToFile(const std::string &detector_name,
91  const string &extension, const string &dir)
92 {
93  //Note the naming convention should be consistent with PHParameters::WriteToFile
94 
95  ostringstream fullpath;
96  ostringstream fnamestream;
97  PdbBankID bankID(0); // lets start at zero
98  PHTimeStamp TStart(0);
99  PHTimeStamp TStop(0xffffffff);
100  fullpath << dir;
101  // add / if directory lacks ending /
102  if (*(dir.rbegin()) != '/')
103  {
104  fullpath << "/";
105  }
106  fnamestream << detector_name << "_geoparams"
107  << "-"
108  << bankID.getInternalValue() << "-" << TStart.getTics() << "-"
109  << TStop.getTics() << "-" << time(0) << "." << extension;
110  string fname = fnamestream.str();
111  std::transform(fname.begin(), fname.end(), fname.begin(), ::tolower);
112  fullpath << fname;
113 
114  cout << "PdbParameterMapContainer::WriteToFile - save to " << fullpath.str()
115  << endl;
116 
117  TFile *f = TFile::Open(fullpath.str().c_str(), "recreate");
118 
120  for (std::map<int, PdbParameterMap *>::const_iterator it =
121  parametermap.begin();
122  it != parametermap.end(); ++it)
123  {
124  PdbParameterMap *myparm = static_cast<PdbParameterMap *>(it->second->CloneMe());
125  container->AddPdbParameterMap(it->first, myparm);
126  }
127 
128  // force xml file writing to use extended precision shown experimentally
129  // to not modify input parameters (.15e)
130  string floatformat = TBufferXML::GetFloatFormat();
131  TBufferXML::SetFloatFormat("%.17g"); // for IEEE 754 double
132  container->Write("PdbParameterMapContainer");
133  delete f;
134  // restore previous xml float format
135  TBufferXML::SetFloatFormat(floatformat.c_str());
136  cout << "sleeping 1 second to prevent duplicate inserttimes" << endl;
137  sleep(1);
138  return 0;
139 }