Belle II Software development
MilleData Class Reference

Mergeable class holding list of so far opened mille binaries and providing the binaries. More...

#include <MilleData.h>

Inheritance diagram for MilleData:
MergeableNamed

Public Member Functions

 MilleData (bool doublePrecision=false, bool absFilePaths=false)
 Constructor. Set doublePrecision to true to write binary files with doubles instead of floats.
 
virtual ~MilleData ()
 Destructor.
 
virtual void merge (const MergeableNamed *other) override
 Implementation of merging.
 
virtual void clear () override
 Implementation of clearing.
 
void open (std::string filename)
 Open a new file and remember it. Filename should encode also process id!
 
bool isOpen ()
 Is some file already open?
 
void fill (gbl::GblTrajectory &trajectory)
 Write a GBL trajectory to the binary file.
 
void close ()
 Close current mille binary if opened.
 
const std::vector< std::string > & getFiles () const
 Get the list of all created files.
 
MilleDataoperator= (const MilleData &other)
 Copy by assignment (if some file on LHS is opened, it is closed during this operation; file pointers not transferred - new file to be opened)
 
 MilleData (const MilleData &other)
 Construct from other object (pointer to binary file is not transferred - new file has to be opened by new object)
 
virtual MilleDataClone (const char *newname="") const override
 Clone object (with optionally a new name)
 
int getNumRecords ()
 Get number of records (trajectories) written to binary files.
 
bool hasDoublePrecision ()
 Are files written with double precision?
 
void addFile (const std::string &path)
 Add a filename (path) to the file list manually.
 
virtual Long64_t Merge (TCollection *hlist)
 Allow merging using TFileMerger if saved directly to a file.
 
virtual void Reset ()
 Root-like Reset function for "template compatibility" with ROOT objects.
 
virtual void SetDirectory (TDirectory *)
 Root-like Clone function for "template compatibility" with ROOT objects.
 

Private Member Functions

 ClassDef (MergeableNamed, 0)
 Abstract base class for objects that can be merged and named.
 

Private Attributes

bool m_doublePrecision {false}
 Use double-precision for binary files.
 
bool m_absFilePaths {false}
 Use absolute file paths to binary files Default is False - so you have to move the binaries to working dir of the algorithm If True, the original location of binaries is remembered in datastore and Millepede will take them from there.
 
std::vector< std::string > m_files {}
 List of already created file names.
 
gbl::MilleBinary * m_binary {nullptr}
 Pointer to current binary file.
 
int m_numRecords {0}
 Pointer to opened binary file (not streamed)
 

Detailed Description

Mergeable class holding list of so far opened mille binaries and providing the binaries.

Definition at line 24 of file MilleData.h.

Constructor & Destructor Documentation

◆ MilleData() [1/2]

MilleData ( bool doublePrecision = false,
bool absFilePaths = false )
inline

Constructor. Set doublePrecision to true to write binary files with doubles instead of floats.

Definition at line 27 of file MilleData.h.

27 : MergeableNamed(), m_doublePrecision(doublePrecision),
28 m_absFilePaths(absFilePaths) {};

◆ ~MilleData()

virtual ~MilleData ( )
inlinevirtual

Destructor.

Definition at line 30 of file MilleData.h.

30{ close(); }

◆ MilleData() [2/2]

MilleData ( const MilleData & other)
inline

Construct from other object (pointer to binary file is not transferred - new file has to be opened by new object)

Definition at line 49 of file MilleData.h.

49 : MergeableNamed(other), m_doublePrecision(other.m_doublePrecision),
50 m_absFilePaths(other.m_absFilePaths), m_files(other.m_files),
51 m_binary(nullptr),
52 m_numRecords(other.m_numRecords) {}

Member Function Documentation

◆ addFile()

void addFile ( const std::string & path)
inline

Add a filename (path) to the file list manually.

Definition at line 63 of file MilleData.h.

64 {
65 m_files.push_back(path);
66 }

◆ clear()

virtual void clear ( )
inlineoverridevirtual

Implementation of clearing.

Implements MergeableNamed.

Definition at line 35 of file MilleData.h.

35{ m_files.clear(); m_numRecords = 0; }

◆ Clone()

MilleData * Clone ( const char * newname = "") const
overridevirtual

Clone object (with optionally a new name)

Definition at line 34 of file MilleData.cc.

35{
36 MilleData* obj = new MilleData(*this);
37 if (newname && strlen(newname)) {
38 obj->SetName(newname);
39 }
40 return obj;
41}
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

◆ close()

void close ( )

Close current mille binary if opened.

Definition at line 53 of file MilleData.cc.

54{
55 if (m_binary) {
56 delete m_binary;
57 m_binary = nullptr;
58 }
59}
gbl::MilleBinary * m_binary
Pointer to current binary file.
Definition MilleData.h:78

◆ fill()

void fill ( gbl::GblTrajectory & trajectory)

Write a GBL trajectory to the binary file.

Definition at line 61 of file MilleData.cc.

62{
63 if (m_binary) {
64 trajectory.milleOut(*m_binary);
66 }
67}
int m_numRecords
Pointer to opened binary file (not streamed)
Definition MilleData.h:80

◆ getFiles()

const std::vector< std::string > & getFiles ( ) const
inline

Get the list of all created files.

Definition at line 45 of file MilleData.h.

45{ return m_files; }

◆ getNumRecords()

int getNumRecords ( )
inline

Get number of records (trajectories) written to binary files.

Definition at line 58 of file MilleData.h.

58{return m_numRecords;}

◆ hasDoublePrecision()

bool hasDoublePrecision ( )
inline

Are files written with double precision?

Definition at line 60 of file MilleData.h.

60{return m_doublePrecision;}

◆ isOpen()

bool isOpen ( )
inline

Is some file already open?

Definition at line 39 of file MilleData.h.

39{ return !!m_binary; }

◆ Merge()

Long64_t Merge ( TCollection * hlist)
virtualinherited

Allow merging using TFileMerger if saved directly to a file.

Definition at line 14 of file MergeableNamed.cc.

15{
16 Long64_t nMerged = 0;
17 if (hlist) {
18 const MergeableNamed* xh = 0;
19 TIter nxh(hlist);
20 while ((xh = dynamic_cast<MergeableNamed*>(nxh()))) {
21 // Add xh to me
22 merge(xh);
23 ++nMerged;
24 }
25 }
26 return nMerged;
27}
virtual void merge(const MergeableNamed *other)=0
Merge object 'other' into this one.

◆ merge()

void merge ( const MergeableNamed * other)
overridevirtual

Implementation of merging.

Implements MergeableNamed.

Definition at line 16 of file MilleData.cc.

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}
std::vector< std::string > m_files
List of already created file names.
Definition MilleData.h:76

◆ open()

void open ( std::string filename)

Open a new file and remember it. Filename should encode also process id!

Definition at line 69 of file MilleData.cc.

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}
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

◆ operator=()

MilleData & operator= ( const MilleData & other)

Copy by assignment (if some file on LHS is opened, it is closed during this operation; file pointers not transferred - new file to be opened)

Definition at line 43 of file MilleData.cc.

44{
45 close();
46 m_files = other.m_files;
50 return *this;
51}

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

Root-like Reset function for "template compatibility" with ROOT objects.

Alias for clear().

Definition at line 52 of file MergeableNamed.h.

52{clear();}

◆ SetDirectory()

virtual void SetDirectory ( TDirectory * )
inlinevirtualinherited

Root-like Clone function for "template compatibility" with ROOT objects.

Calls clone() Root-like SetDirectory function for "template compatibility" with ROOT objects. Does nothing.

Definition at line 56 of file MergeableNamed.h.

56{}

Member Data Documentation

◆ m_absFilePaths

bool m_absFilePaths {false}
private

Use absolute file paths to binary files Default is False - so you have to move the binaries to working dir of the algorithm If True, the original location of binaries is remembered in datastore and Millepede will take them from there.

Definition at line 75 of file MilleData.h.

75{false};

◆ m_binary

gbl::MilleBinary* m_binary {nullptr}
private

Pointer to current binary file.

Definition at line 78 of file MilleData.h.

78{nullptr};

◆ m_doublePrecision

bool m_doublePrecision {false}
private

Use double-precision for binary files.

Definition at line 70 of file MilleData.h.

70{false};

◆ m_files

std::vector<std::string> m_files {}
private

List of already created file names.

Definition at line 76 of file MilleData.h.

76{};

◆ m_numRecords

int m_numRecords {0}
private

Pointer to opened binary file (not streamed)

Number of written trajectories

Definition at line 80 of file MilleData.h.

80{0};

The documentation for this class was generated from the following files: