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