ATLAS Offline Software
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 
12 namespace 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
TrigAccel::DataExportBuffer
Definition: DataExportBuffer.h:14
TrigAccel::DataExportBuffer::fit
bool fit(size_t s)
Definition: DataExportBuffer.h:26
TrigAccel::DATA_EXPORT_BUFFER
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigAccel::DataExportBuffer::operator=
DataExportBuffer & operator=(const DataExportBuffer &)=delete
TrigAccel::DataExportBuffer::reallocate
void reallocate(size_t s)
Definition: DataExportBuffer.h:30
TrigAccel::DataExportBuffer::m_size
size_t m_size
Definition: DataExportBuffer.h:56
TrigAccel::DataExportBuffer::DataExportBuffer
DataExportBuffer(const DataExportBuffer &)=delete
TrigAccel::DataExportBuffer::DataExportBuffer
DataExportBuffer(size_t s)
Definition: DataExportBuffer.h:17
TrigAccel::DataExportBuffer::load
size_t load(const std::string &name)
Definition: DataExportBuffer.h:42
TrigAccel::DataExportBuffer::~DataExportBuffer
~DataExportBuffer()
Definition: DataExportBuffer.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigAccel::DataExportBuffer::m_buffer
char * m_buffer
Definition: DataExportBuffer.h:57
TrigAccel::DataExportBuffer::DataExportBuffer
DataExportBuffer()
Definition: DataExportBuffer.h:16
TrigAccel
Definition: DataExportBuffer.h:12
TrigAccel::DataExportBuffer::save
void save(const std::string &name) const
Definition: DataExportBuffer.h:36