ATLAS Offline Software
Loading...
Searching...
No Matches
ByteStreamDataWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <stdexcept>
8
9#include "EventStorage/DataWriter.h"
10
11namespace {
12
13void versionException(int version) {
14 std::string msg = "Unexpected version number in ByteStreamDataWriter::makeWriter: " +
15 std::to_string(version);
16 throw std::invalid_argument(msg);
17}
18
19/*
20 * Implementation of ByteStreamDataWriter for current version of EventStorage.
21 */
22class ByteStreamDataWriterCurrent: public ByteStreamDataWriter {
23public:
24
25 ByteStreamDataWriterCurrent(const std::string& writingPath,
26 const std::string& fileNameCore,
27 const EventStorage::run_parameters_record& rPar,
28 const std::vector<std::string>& fmdStrings,
29 unsigned int maxFileNE,
30 unsigned int maxFileMB,
31 unsigned int startIndex,
32 EventStorage::CompressionType compression,
33 unsigned int compLevel);
34
35 ByteStreamDataWriterCurrent(const std::string& writingPath,
36 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
37 const EventStorage::run_parameters_record& rPar,
38 const std::string& project,
39 const std::string& streamType,
40 const std::string& streamName,
41 const std::string& stream,
42 unsigned int lumiBlockNumber,
43 const std::string& applicationName,
44 const std::vector<std::string>& fmdStrings,
45 unsigned int maxFileNE,
46 unsigned int maxFileMB,
47 EventStorage::CompressionType compression,
48 unsigned int compLevel);
49
50 virtual ~ByteStreamDataWriterCurrent() = default;
51
52 // abstract class cannot be copied
53 ByteStreamDataWriterCurrent(const ByteStreamDataWriterCurrent&) = delete;
54 ByteStreamDataWriterCurrent& operator=(const ByteStreamDataWriterCurrent&) = delete;
55
56 virtual EventStorage::DWError putData(unsigned int dataSize, const void *data) override;
57
58 virtual bool good() const override;
59
60private:
61
62 std::unique_ptr<EventStorage::DataWriter> m_writer;
63};
64
65} // namespace
66
67std::unique_ptr<ByteStreamDataWriter>
69 const std::string& writingPath,
70 const std::string& fileNameCore,
71 const EventStorage::run_parameters_record& rPar,
72 const std::vector<std::string>& fmdStrings,
73 unsigned int maxFileNE,
74 unsigned int maxFileMB,
75 unsigned int startIndex,
76 EventStorage::CompressionType compression,
77 unsigned int compLevel)
78{
79 ByteStreamDataWriter* res = nullptr;
80 if (version == 0 or version == FILE_FORMAT_VERSION) {
81 // Use current version
82 res = new ByteStreamDataWriterCurrent(writingPath,
83 fileNameCore,
84 rPar,
85 fmdStrings,
86 maxFileNE,
87 maxFileMB,
88 startIndex,
89 compression,
90 compLevel);
91 } else {
92 // Unexpected something
93 versionException(version);
94 }
95
96 return std::unique_ptr<ByteStreamDataWriter>(res);
97}
98
99std::unique_ptr<ByteStreamDataWriter>
101 const std::string& writingPath,
102 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
103 const EventStorage::run_parameters_record& rPar,
104 const std::string& project,
105 const std::string& streamType,
106 const std::string& streamName,
107 const std::string& stream,
108 unsigned int lumiBlockNumber,
109 const std::string& applicationName,
110 const std::vector<std::string>& fmdStrings,
111 unsigned int maxFileNE,
112 unsigned int maxFileMB,
113 EventStorage::CompressionType compression,
114 unsigned int compLevel)
115{
116 ByteStreamDataWriter* res = nullptr;
117 if (version == 0 or version == FILE_FORMAT_VERSION) {
118 // Use current version
119 res = new ByteStreamDataWriterCurrent(writingPath,
120 theFNCB,
121 rPar,
122 project,
123 streamType,
124 streamName,
125 stream,
126 lumiBlockNumber,
127 applicationName,
128 fmdStrings,
129 maxFileNE,
130 maxFileMB,
131 compression,
132 compLevel);
133 } else {
134 // Unexpected something
135 versionException(version);
136 }
137
138 return std::unique_ptr<ByteStreamDataWriter>(res);
139}
140
141std::unique_ptr<ByteStreamDataWriter>
143 // initiate with production file name
144 if (parameters.theFNCB == nullptr)
145 return makeWriter(
146 parameters.version,
147 parameters.writingPath,
148 parameters.fileNameCore,
149 parameters.rPar,
150 parameters.fmdStrings,
151 parameters.maxFileNE,
152 parameters.maxFileMB,
153 parameters.startIndex,
154 parameters.compression,
155 parameters.compLevel);
156
157 // initiate for user-defined file name
158 return makeWriter(
159 parameters.version,
160 parameters.writingPath,
161 parameters.theFNCB,
162 parameters.rPar,
163 parameters.project,
164 parameters.streamType,
165 parameters.streamName,
166 parameters.stream,
167 parameters.lumiBlockNumber,
168 parameters.applicationName,
169 parameters.fmdStrings,
170 parameters.maxFileNE,
171 parameters.maxFileMB,
172 parameters.compression,
173 parameters.compLevel);
174}
175
176namespace {
177
178ByteStreamDataWriterCurrent::ByteStreamDataWriterCurrent(const std::string& writingPath,
179 const std::string& fileNameCore,
180 const EventStorage::run_parameters_record& rPar,
181 const std::vector<std::string>& fmdStrings,
182 unsigned int maxFileNE,
183 unsigned int maxFileMB,
184 unsigned int startIndex,
185 EventStorage::CompressionType compression,
186 unsigned int compLevel)
187{
188 m_writer.reset(new EventStorage::DataWriter(writingPath,
189 fileNameCore,
190 rPar,
191 fmdStrings,
192 startIndex,
193 compression,
194 compLevel));
195 m_writer->setMaxFileNE(maxFileNE);
196 m_writer->setMaxFileMB(maxFileMB);
197}
198
199ByteStreamDataWriterCurrent::ByteStreamDataWriterCurrent(const std::string& writingPath,
200 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
201 const EventStorage::run_parameters_record& rPar,
202 const std::string& project,
203 const std::string& streamType,
204 const std::string& streamName,
205 const std::string& stream,
206 unsigned int lumiBlockNumber,
207 const std::string& applicationName,
208 const std::vector<std::string>& fmdStrings,
209 unsigned int maxFileNE,
210 unsigned int maxFileMB,
211 EventStorage::CompressionType compression,
212 unsigned int compLevel)
213{
214 m_writer.reset(new EventStorage::DataWriter(writingPath,
215 theFNCB,
216 rPar,
217 project,
218 streamType,
219 streamName,
220 stream,
221 lumiBlockNumber,
222 applicationName,
223 fmdStrings,
224 compression,
225 compLevel));
226 m_writer->setMaxFileNE(maxFileNE);
227 m_writer->setMaxFileMB(maxFileMB);
228}
229
230EventStorage::DWError
231ByteStreamDataWriterCurrent::putData(unsigned int dataSize, const void *data)
232{
233 return m_writer->putData(dataSize, data);
234}
235
236bool
237ByteStreamDataWriterCurrent::good() const
238{
239 return m_writer->good();
240}
241
242} // namespace
This file contains the class definition for the ByteStreamDataWriter class.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::pair< std::vector< unsigned int >, bool > res
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
This class defines abstract interface for data writing.
static std::unique_ptr< ByteStreamDataWriter > makeWriter(int version, const std::string &writingPath, const std::string &fileNameCore, const EventStorage::run_parameters_record &rPar, const std::vector< std::string > &fmdStrings, unsigned int maxFileNE=0, unsigned int maxFileMB=0, unsigned int startIndex=1, EventStorage::CompressionType compression=EventStorage::NONE, unsigned int compLevel=1)
Factory method returning data writer instance for specified version.
Class containing parameters needed to initiate DataWriter.
MsgStream & msg
Definition testRead.cxx:32