ATLAS Offline Software
ByteStreamDataWriter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ByteStreamDataWriter.h"
6 
7 #include <stdexcept>
8 
10 #include "EventStorage/DataWriter.h"
11 
12 namespace {
13 
14 void versionException(int version) {
15  std::string msg = "Unexpected version number in ByteStreamDataWriter::makeWriter: " +
17  throw std::invalid_argument(msg);
18 }
19 
20 /*
21  * Implementation of ByteStreamDataWriter for current version of EventStorage.
22  */
23 class ByteStreamDataWriterCurrent: public ByteStreamDataWriter {
24 public:
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,
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,
49  unsigned int compLevel);
50 
51  virtual ~ByteStreamDataWriterCurrent() {}
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 
61 private:
62 
63  std::unique_ptr<EventStorage::DataWriter> m_writer;
64 };
65 
66 } // namespace
67 
68 std::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,
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,
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 
111 std::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,
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 
169 std::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 
204 namespace {
205 
206 ByteStreamDataWriterCurrent::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,
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 
227 ByteStreamDataWriterCurrent::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,
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 
258 EventStorage::DWError
259 ByteStreamDataWriterCurrent::putData(unsigned int dataSize, const void *data)
260 {
261  return m_writer->putData(dataSize, data);
262 }
263 
264 bool
266 {
267  return m_writer->good();
268 }
269 
270 } // namespace
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
ByteStreamDataWriter::good
virtual bool good() const =0
Feedback to user, check if open and last write went OK.
ByteStreamDataWriter.h
This file contains the class definition for the ByteStreamDataWriter class.
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
ByteStreamDataWriter::putData
virtual EventStorage::DWError putData(unsigned int dataSize, const void *data)=0
Write a single block of data.
DataWriterParameters
Class containing parameters needed to initiate DataWriter.
Definition: ByteStreamDataWriter.h:153
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
PayloadHelpers::dataSize
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.
Definition: TriggerEDMDeserialiserAlg.cxx:188
ByteStreamDataWriter::makeWriter
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.
Definition: ByteStreamDataWriter.cxx:69
ByteStreamDataWriterV5
Implementation of ByteStreamDataWriter for version 5 (run1) of EventStorage.
Definition: ByteStreamDataWriterV5.h:24
project
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
Definition: MeasurementSelector.h:142
get_generator_info.version
version
Definition: get_generator_info.py:33
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
RunTileMonitoring.streamType
streamType
Definition: RunTileMonitoring.py:158
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
offline_EventStorage_v5::CompressionType
CompressionType
Definition: v5_EventStorageRecords.h:41
ByteStreamDataWriter::operator=
ByteStreamDataWriter & operator=(const ByteStreamDataWriter &)=delete
ByteStreamDataWriterV5.h
This file contains the class definition for the ByteStreamDataWriterV5 class.
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
python.BeamSpotUpdate.compression
compression
Definition: BeamSpotUpdate.py:188
ByteStreamDataWriter
This class defines abstract interface for data writing.
Definition: ByteStreamDataWriter.h:41