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 transfered - new file to be opened)
 
 MilleData (const MilleData &other)
 Construct from other object (pointer to binary file is not transfered - 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 remebered 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) {};
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

◆ ~MilleData()

virtual ~MilleData ( )
inlinevirtual

Destructor.

Definition at line 30 of file MilleData.h.

30{ close(); }
void close()
Close current mille binary if opened.
Definition: MilleData.cc:56

◆ MilleData() [2/2]

MilleData ( const MilleData other)
inline

Construct from other object (pointer to binary file is not transfered - 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) {}
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
gbl::MilleBinary * m_binary
Pointer to current binary file.
Definition: MilleData.h:78

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 37 of file MilleData.cc.

38{
39 MilleData* obj = new MilleData(*this);
40 if (newname && strlen(newname)) {
41 obj->SetName(newname);
42 }
43 return obj;
44}
Mergeable class holding list of so far opened mille binaries and providing the binaries.
Definition: MilleData.h:24

◆ close()

void close ( )

Close current mille binary if opened.

Definition at line 56 of file MilleData.cc.

57{
58 if (m_binary) {
59 delete m_binary;
60 m_binary = nullptr;
61 }
62}

◆ fill()

void fill ( gbl::GblTrajectory &  trajectory)

Write a GBL trajectory to the binary file.

Definition at line 64 of file MilleData.cc.

65{
66 if (m_binary) {
67 trajectory.milleOut(*m_binary);
69 }
70}

◆ 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()

void merge ( const MergeableNamed other)
overridevirtual

Implementation of merging.

Implements MergeableNamed.

Definition at line 19 of file MilleData.cc.

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}

◆ 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}
Abstract base class for objects that can be merged but also named.
virtual void merge(const MergeableNamed *other)=0
Merge object 'other' into this one.

◆ open()

void open ( std::string  filename)

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

Definition at line 72 of file MilleData.cc.

73{
74 if (m_binary) {
75 close();
76 }
77 m_binary = new gbl::MilleBinary(filename, m_doublePrecision);
79 m_files.push_back(FileSystem::findFile(string(realpath(filename.c_str(), NULL))));
80 else
81 m_files.push_back(filename);
82
83}
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151

◆ 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 transfered - new file to be opened)

Definition at line 46 of file MilleData.cc.

47{
48 close();
49 m_files = other.m_files;
53 return *this;
54}

◆ 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();}
virtual void clear()=0
Clear content of this object (e.g. set to zeroes). Called by the Reset() function.

◆ 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 remebered in datastore and Millepede will take them from there.

Definition at line 75 of file MilleData.h.

◆ m_binary

gbl::MilleBinary* m_binary {nullptr}
private

Pointer to current binary file.

Definition at line 78 of file MilleData.h.

◆ m_doublePrecision

bool m_doublePrecision {false}
private

Use double-precision for binary files.

Definition at line 70 of file MilleData.h.

◆ m_files

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

List of already created file names.

Definition at line 76 of file MilleData.h.

◆ 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.


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