Belle II Software development
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 <filesystem>
12
13using namespace std;
14using namespace Belle2;
15
16void MilleData::merge(const MergeableNamed* other)
17{
18 auto* data = dynamic_cast<const MilleData*>(other);
19 const vector<string>& files = data->getFiles();
20 m_numRecords += data->m_numRecords;
21 for (auto& file : files) {
22 bool exists = false;
23 for (auto& myfile : m_files) {
24 if (myfile == file) {
25 exists = true;
26 break;
27 }
28 }
29 if (!exists)
30 m_files.push_back(file);
31 }
32}
33
34MilleData* MilleData::Clone(const char* newname) const
35{
36 MilleData* obj = new MilleData(*this);
37 if (newname && strlen(newname)) {
38 obj->SetName(newname);
39 }
40 return obj;
41}
42
44{
45 close();
46 m_files = other.m_files;
50 return *this;
51}
52
54{
55 if (m_binary) {
56 delete m_binary;
57 m_binary = nullptr;
58 }
59}
60
61void MilleData::fill(gbl::GblTrajectory& trajectory)
62{
63 if (m_binary) {
64 trajectory.milleOut(*m_binary);
66 }
67}
68
69void MilleData::open(string filename)
70{
71 if (m_binary) {
72 close();
73 }
74 m_binary = new gbl::MilleBinary(filename, m_doublePrecision);
76 m_files.push_back(string(std::filesystem::canonical(filename)));
77 else
78 m_files.push_back(filename);
79
80}
int m_numRecords
Pointer to opened binary file (not streamed)
Definition MilleData.h:80
virtual MilleData * Clone(const char *newname="") const override
Clone object (with optionally a new name)
Definition MilleData.cc:34
std::vector< std::string > m_files
List of already created file names.
Definition MilleData.h:76
MilleData & operator=(const MilleData &other)
Copy by assignment (if some file on LHS is opened, it is closed during this operation; file pointers ...
Definition MilleData.cc:43
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
void close()
Close current mille binary if opened.
Definition MilleData.cc:53
bool m_doublePrecision
Use double-precision for binary files.
Definition MilleData.h:70
virtual void merge(const MergeableNamed *other) override
Implementation of merging.
Definition MilleData.cc:16
gbl::MilleBinary * m_binary
Pointer to current binary file.
Definition MilleData.h:78
void open(std::string filename)
Open a new file and remember it. Filename should encode also process id!
Definition MilleData.cc:69
void fill(gbl::GblTrajectory &trajectory)
Write a GBL trajectory to the binary file.
Definition MilleData.cc:61
MilleData(bool doublePrecision=false, bool absFilePaths=false)
Constructor. Set doublePrecision to true to write binary files with doubles instead of floats.
Definition MilleData.h:27
Abstract base class for different kinds of events.
STL namespace.