Belle II Software development
MilleData.h
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#pragma once
9
10#include <calibration/core/MergeableNamed.h>
11
12#include <genfit/MilleBinary.h>
13#include <genfit/GblTrajectory.h>
14
15#include <string>
16#include <vector>
17
18namespace Belle2 {
24 class MilleData : public MergeableNamed {
25 public:
27 MilleData(bool doublePrecision = false, bool absFilePaths = false) : MergeableNamed(), m_doublePrecision(doublePrecision),
28 m_absFilePaths(absFilePaths) {};
30 virtual ~MilleData() { close(); }
31
33 virtual void merge(const MergeableNamed* other) override;
35 virtual void clear() override { m_files.clear(); m_numRecords = 0; }
37 void open(std::string filename);
39 bool isOpen() { return !!m_binary; }
41 void fill(gbl::GblTrajectory& trajectory);
43 void close();
45 const std::vector<std::string>& getFiles() const { return m_files; }
47 MilleData& operator=(const MilleData& other);
51 m_binary(nullptr),
53
55 virtual MilleData* Clone(const char* newname = "") const override;
56
61
63 void addFile(const std::string& path)
64 {
65 m_files.push_back(path);
66 }
67
68 private:
70 bool m_doublePrecision{false};
75 bool m_absFilePaths{false};
76 std::vector<std::string> m_files{};
78 gbl::MilleBinary* m_binary{nullptr};
81
82 ClassDefOverride(MilleData, 2)
83 };
85}
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
bool hasDoublePrecision()
Are files written with double precision?
Definition: MilleData.h:60
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:37
bool isOpen()
Is some file already open?
Definition: MilleData.h:39
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:46
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:56
int getNumRecords()
Get number of records (trajectories) written to binary files.
Definition: MilleData.h:58
bool m_doublePrecision
Use double-precision for binary files.
Definition: MilleData.h:70
virtual void clear() override
Implementation of clearing.
Definition: MilleData.h:35
virtual ~MilleData()
Destructor.
Definition: MilleData.h:30
virtual void merge(const MergeableNamed *other) override
Implementation of merging.
Definition: MilleData.cc:19
MilleData(const MilleData &other)
Construct from other object (pointer to binary file is not transfered - new file has to be opened by ...
Definition: MilleData.h:49
const std::vector< std::string > & getFiles() const
Get the list of all created files.
Definition: MilleData.h:45
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:72
void addFile(const std::string &path)
Add a filename (path) to the file list manually.
Definition: MilleData.h:63
void fill(gbl::GblTrajectory &trajectory)
Write a GBL trajectory to the binary file.
Definition: MilleData.cc:64
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.