ATLAS Offline Software
Loading...
Searching...
No Matches
DataExportBuffer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGACCELEVENT_DATAEXPORTBUFFER_H
6#define TRIGACCELEVENT_DATAEXPORTBUFFER_H
7
8
9#include <string>
10#include <fstream>
11
12namespace TrigAccel {
13
14 typedef struct DataExportBuffer {
15 public:
17 DataExportBuffer(size_t s) : m_size(s) {
18 m_buffer = new char[s];
19 }
21
22 // no copy/assign
25
26 inline bool fit(size_t s) {
27 return s<=m_size;
28 }
29
30 void reallocate(size_t s) {
31 delete[] m_buffer;
32 m_buffer = new char[s];
33 m_size = s;
34 }
35
36 void save(const std::string& name) const {
37 std::ofstream binFile(name, std::ios::binary);
38 binFile.write(m_buffer, m_size);
39 binFile.close();
40 }
41
42 size_t load(const std::string& name) {
43 std::ifstream binFile(name, std::ios::binary);
44 if (!binFile) {
45 return 0;
46 }
47 binFile.seekg(0, binFile.end);
48 size_t fileSize = binFile.tellg();
49 binFile.seekg (0, binFile.beg);
50 reallocate(fileSize);
51 binFile.read(m_buffer, m_size);
52 binFile.close();
53 return fileSize;
54 }
55
56 size_t m_size;
57 char* m_buffer;
59}
60
61#endif
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
size_t load(const std::string &name)
DataExportBuffer & operator=(const DataExportBuffer &)=delete
DataExportBuffer(const DataExportBuffer &)=delete
void save(const std::string &name) const