Belle II Software  release-05-01-25
MilleData.cc
1 
2 #include <alignment/dataobjects/MilleData.h>
3 
4 #include <framework/utilities/FileSystem.h>
5 
6 #include <cstdlib>
7 
8 char* full_path = realpath("foo.dat", NULL);
9 using namespace std;
10 using namespace Belle2;
11 
12 void MilleData::merge(const MergeableNamed* other)
13 {
14  auto* data = dynamic_cast<const MilleData*>(other);
15  const vector<string>& files = data->getFiles();
16  m_numRecords += data->m_numRecords;
17  for (auto& file : files) {
18  bool exists = false;
19  for (auto& myfile : m_files) {
20  if (myfile == file) {
21  exists = true;
22  break;
23  }
24  }
25  if (!exists)
26  m_files.push_back(file);
27  }
28 }
29 
30 MilleData* MilleData::Clone(const char* newname) const
31 {
32  MilleData* obj = new MilleData(*this);
33  if (newname && strlen(newname)) {
34  obj->SetName(newname);
35  }
36  return obj;
37 }
38 
39 MilleData& MilleData::operator=(const MilleData& other)
40 {
41  close();
42  m_files = other.m_files;
43  m_doublePrecision = other.m_doublePrecision;
44  m_absFilePaths = other.m_absFilePaths;
45  m_numRecords = other.m_numRecords;
46  return *this;
47 }
48 
49 void MilleData::close()
50 {
51  if (m_binary) {
52  delete m_binary;
53  m_binary = nullptr;
54  }
55 }
56 
57 void MilleData::fill(gbl::GblTrajectory& trajectory)
58 {
59  if (m_binary) {
60  trajectory.milleOut(*m_binary);
61  ++m_numRecords;
62  }
63 }
64 
65 void MilleData::open(string filename)
66 {
67  if (m_binary) {
68  close();
69  }
70  m_binary = new gbl::MilleBinary(filename, m_doublePrecision);
71  if (m_absFilePaths)
72  m_files.push_back(FileSystem::findFile(string(realpath(filename.c_str(), NULL))));
73  else
74  m_files.push_back(filename);
75 
76 }
gbl::GblTrajectory::milleOut
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
Definition: GblTrajectory.cc:1091
Belle2::MilleData::m_absFilePaths
bool m_absFilePaths
Use absolute file paths to binary files Default is False - so you have to move the binaries to workin...
Definition: MilleData.h:68
Belle2::MergeableNamed
Abstract base class for objects that can be merged but also named.
Definition: MergeableNamed.h:32
Belle2::MilleData::m_numRecords
int m_numRecords
Pointer to opened binary file (not streamed)
Definition: MilleData.h:73
Belle2::MilleData::m_doublePrecision
bool m_doublePrecision
Use double-precision for binary files.
Definition: MilleData.h:63
gbl::GblTrajectory
GBL trajectory.
Definition: GblTrajectory.h:48
Belle2::MilleData
Mergeable class holding list of so far opened mille binaries and providing the binaries.
Definition: MilleData.h:17
Belle2::merge
std::vector< std::vector< double > > merge(std::vector< std::vector< std::vector< double >>> toMerge)
merge { vector<double> a, vector<double> b} into {a, b}
Definition: tools.h:44
Belle2::MilleData::m_files
std::vector< std::string > m_files
List of already created file names.
Definition: MilleData.h:69
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
gbl::MilleBinary
Millepede-II (binary) record.
Definition: MilleBinary.h:68