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
10#include "EventStorage/DataWriter.h"
11
12namespace {
13
14void versionException(int version) {
15 std::string msg = "Unexpected version number in ByteStreamDataWriter::makeWriter: " +
16 std::to_string(version);
17 throw std::invalid_argument(msg);
18}
19
20/*
21 * Implementation of ByteStreamDataWriter for current version of EventStorage.
22 */
23class ByteStreamDataWriterCurrent: public ByteStreamDataWriter {
24public:
25
26 ByteStreamDataWriterCurrent(const std::string& writingPath,
27 const std::string& fileNameCore,
28 const EventStorage::run_parameters_record& rPar,
29 const std::vector<std::string>& fmdStrings,
30 unsigned int maxFileNE,
31 unsigned int maxFileMB,
32 unsigned int startIndex,
33 EventStorage::CompressionType compression,
34 unsigned int compLevel);
35
36 ByteStreamDataWriterCurrent(const std::string& writingPath,
37 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
38 const EventStorage::run_parameters_record& rPar,
39 const std::string& project,
40 const std::string& streamType,
41 const std::string& streamName,
42 const std::string& stream,
43 unsigned int lumiBlockNumber,
44 const std::string& applicationName,
45 const std::vector<std::string>& fmdStrings,
46 unsigned int maxFileNE,
47 unsigned int maxFileMB,
48 EventStorage::CompressionType compression,
49 unsigned int compLevel);
50
51 virtual ~ByteStreamDataWriterCurrent() = default;
52
53 // abstract class cannot be copied
54 ByteStreamDataWriterCurrent(const ByteStreamDataWriterCurrent&) = delete;
55 ByteStreamDataWriterCurrent& operator=(const ByteStreamDataWriterCurrent&) = delete;
56
57 virtual EventStorage::DWError putData(unsigned int dataSize, const void *data) override;
58
59 virtual bool good() const override;
60
61private:
62
63 std::unique_ptr<EventStorage::DataWriter> m_writer;
64};
65
66} // namespace
67
68std::unique_ptr<ByteStreamDataWriter>
70 const std::string& writingPath,
71 const std::string& fileNameCore,
72 const EventStorage::run_parameters_record& rPar,
73 const std::vector<std::string>& fmdStrings,
74 unsigned int maxFileNE,
75 unsigned int maxFileMB,
76 unsigned int startIndex,
77 EventStorage::CompressionType compression,
78 unsigned int compLevel)
79{
80 ByteStreamDataWriter* res = nullptr;
81 if (version == 0 or version == FILE_FORMAT_VERSION) {
82 // Use current version
83 res = new ByteStreamDataWriterCurrent(writingPath,
84 fileNameCore,
85 rPar,
86 fmdStrings,
87 maxFileNE,
88 maxFileMB,
89 startIndex,
90 compression,
91 compLevel);
92 } else if (version == 5) {
93 // Run1 version
94 res = new ByteStreamDataWriterV5(writingPath,
95 fileNameCore,
96 rPar,
97 fmdStrings,
98 maxFileNE,
99 maxFileMB,
100 startIndex,
101 compression,
102 compLevel);
103 } else {
104 // Unexpected something
105 versionException(version);
106 }
107
108 return std::unique_ptr<ByteStreamDataWriter>(res);
109}
110
111std::unique_ptr<ByteStreamDataWriter>
113 const std::string& writingPath,
114 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
115 const EventStorage::run_parameters_record& rPar,
116 const std::string& project,
117 const std::string& streamType,
118 const std::string& streamName,
119 const std::string& stream,
120 unsigned int lumiBlockNumber,
121 const std::string& applicationName,
122 const std::vector<std::string>& fmdStrings,
123 unsigned int maxFileNE,
124 unsigned int maxFileMB,
125 EventStorage::CompressionType compression,
126 unsigned int compLevel)
127{
128 ByteStreamDataWriter* res = nullptr;
129 if (version == 0 or version == FILE_FORMAT_VERSION) {
130 // Use current version
131 res = new ByteStreamDataWriterCurrent(writingPath,
132 theFNCB,
133 rPar,
134 project,
135 streamType,
136 streamName,
137 stream,
138 lumiBlockNumber,
139 applicationName,
140 fmdStrings,
141 maxFileNE,
142 maxFileMB,
143 compression,
144 compLevel);
145 } else if (version == 5) {
146 // Run1 version
147 res = new ByteStreamDataWriterV5(writingPath,
148 theFNCB,
149 rPar,
150 project,
151 streamType,
152 streamName,
153 stream,
154 lumiBlockNumber,
155 applicationName,
156 fmdStrings,
157 maxFileNE,
158 maxFileMB,
159 compression,
160 compLevel);
161 } else {
162 // Unexpected something
163 versionException(version);
164 }
165
166 return std::unique_ptr<ByteStreamDataWriter>(res);
167}
168
169std::unique_ptr<ByteStreamDataWriter>
171 // initiate with production file name
172 if (parameters.theFNCB == nullptr)
173 return makeWriter(
174 parameters.version,
175 parameters.writingPath,
176 parameters.fileNameCore,
177 parameters.rPar,
178 parameters.fmdStrings,
179 parameters.maxFileNE,
180 parameters.maxFileMB,
181 parameters.startIndex,
182 parameters.compression,
183 parameters.compLevel);
184
185 // initiate for user-defined file name
186 return makeWriter(
187 parameters.version,
188 parameters.writingPath,
189 parameters.theFNCB,
190 parameters.rPar,
191 parameters.project,
192 parameters.streamType,
193 parameters.streamName,
194 parameters.stream,
195 parameters.lumiBlockNumber,
196 parameters.applicationName,
197 parameters.fmdStrings,
198 parameters.maxFileNE,
199 parameters.maxFileMB,
200 parameters.compression,
201 parameters.compLevel);
202}
203
204namespace {
205
206ByteStreamDataWriterCurrent::ByteStreamDataWriterCurrent(const std::string& writingPath,
207 const std::string& fileNameCore,
208 const EventStorage::run_parameters_record& rPar,
209 const std::vector<std::string>& fmdStrings,
210 unsigned int maxFileNE,
211 unsigned int maxFileMB,
212 unsigned int startIndex,
213 EventStorage::CompressionType compression,
214 unsigned int compLevel)
215{
216 m_writer.reset(new EventStorage::DataWriter(writingPath,
217 fileNameCore,
218 rPar,
219 fmdStrings,
220 startIndex,
221 compression,
222 compLevel));
223 m_writer->setMaxFileNE(maxFileNE);
224 m_writer->setMaxFileMB(maxFileMB);
225}
226
227ByteStreamDataWriterCurrent::ByteStreamDataWriterCurrent(const std::string& writingPath,
228 boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
229 const EventStorage::run_parameters_record& rPar,
230 const std::string& project,
231 const std::string& streamType,
232 const std::string& streamName,
233 const std::string& stream,
234 unsigned int lumiBlockNumber,
235 const std::string& applicationName,
236 const std::vector<std::string>& fmdStrings,
237 unsigned int maxFileNE,
238 unsigned int maxFileMB,
239 EventStorage::CompressionType compression,
240 unsigned int compLevel)
241{
242 m_writer.reset(new EventStorage::DataWriter(writingPath,
243 theFNCB,
244 rPar,
245 project,
246 streamType,
247 streamName,
248 stream,
249 lumiBlockNumber,
250 applicationName,
251 fmdStrings,
252 compression,
253 compLevel));
254 m_writer->setMaxFileNE(maxFileNE);
255 m_writer->setMaxFileMB(maxFileMB);
256}
257
258EventStorage::DWError
259ByteStreamDataWriterCurrent::putData(unsigned int dataSize, const void *data)
260{
261 return m_writer->putData(dataSize, data);
262}
263
264bool
265ByteStreamDataWriterCurrent::good() const
266{
267 return m_writer->good();
268}
269
270} // namespace
This file contains the class definition for the ByteStreamDataWriterV5 class.
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)
Implementation of ByteStreamDataWriter for version 5 (run1) of EventStorage.
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