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 <framework/utilities/FileSystem.h>
12
13#include <cstdlib>
14
15char* full_path = realpath("foo.dat", NULL);
16using namespace std;
17using namespace Belle2;
18
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
37MilleData* 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
47{
48 close();
49 m_files = other.m_files;
53 return *this;
54}
55
57{
58 if (m_binary) {
59 delete m_binary;
60 m_binary = nullptr;
61 }
62}
63
64void MilleData::fill(gbl::GblTrajectory& trajectory)
65{
66 if (m_binary) {
67 trajectory.milleOut(*m_binary);
69 }
70}
71
72void MilleData::open(string filename)
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
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
virtual MilleData * Clone(const char *newname="") const override
Clone object (with optionally a new name)
Definition: MilleData.cc:37
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
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:19
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 fill(gbl::GblTrajectory &trajectory)
Write a GBL trajectory to the binary file.
Definition: MilleData.cc:64
Abstract base class for different kinds of events.
STL namespace.