ATLAS Offline Software
v5_DataWriter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
17 #ifndef OFFLINE_EVENTSTORAGE_V5_DATAWRITER_H
18 #define OFFLINE_EVENTSTORAGE_V5_DATAWRITER_H
19 
20 #include <string>
21 #include <fstream>
22 #include <sys/uio.h>
23 #include <stdint.h>
24 #include <zlib.h>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/utility.hpp>
27 
28 #include "EventStorage/DWError.h"
30 #include "EventStorage/FileNameCallback.h"
31 #include "EventStorage/RawFileName.h"
32 
33 
34 namespace EventStorage {
35  class DataWriterCallBack;
36 }
37 
38 namespace offline_EventStorage_v5 {
39 
40  class DataBuffer;
41 
43 
44 class DataWriter : boost::noncopyable
45 {
46 public:
48 
59  DataWriter(const std::string& writingPath,
60  const std::string& fileNameCore,
61  const run_parameters_record& rPar,
62  const std::vector<std::string>& fmdStrings,
63  const unsigned int startIndex = 1,
65  const unsigned int compLevel = 1);
66 
67 
68 
69  DataWriter(const std::string& writingPath,
70  boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
71  const run_parameters_record& rPar,
72  const std::string& project,
73  const std::string& streamType,
74  const std::string& streamName,
75  const std::string& stream,
76  const unsigned int lumiBlockNumber,
77  const std::string& applicationName,
78  const std::vector<std::string>& fmdStrings,
80  const unsigned int compLevel = 1);
81 
82  DataWriter(const std::string& writingPath,
83  const std::string& fileNameCore,
84  const run_parameters_record& rPar,
85  const std::string& project,
86  const std::string& streamType,
87  const std::string& streamName,
88  const std::string& stream,
89  const unsigned int lumiBlockNumber,
90  const std::string& applicationName,
91  const std::vector<std::string>& fmdStrings,
93  const unsigned int compLevel = 1);
94 
95 
96 private:
98 
99 
100  void initDW(const std::string& writingPath,
101  boost::shared_ptr<EventStorage::FileNameCallback> theFNCB,
102  const run_parameters_record& rPar,
103  const std::string& project,
104  const std::string& streamType,
105  const std::string& streamName,
106  const std::string& stream,
107  const unsigned int lumiBlockNumber,
108  const std::string& applicationName,
109  const std::vector<std::string>& fmdStrings,
111  const unsigned int compLevel);
112 
113 
114  EventStorage::DWError putData_implementation(const unsigned int& entries,
115  const iovec_const * my_iovec,
116  uint32_t& sizeToDisk,
117  bool precompressed = false);
118 
119 public:
123  ~DataWriter();
124 
129  EventStorage::DWError setMaxFileNE(const unsigned int& maxFileNE);
130 
134  EventStorage::DWError setMaxFileMB(const unsigned int& maxFileMB);
135 
139  void setGUID(const std::string& GUID);
140 
141 
145  bool good() const; // check if open and last write went OK
146 
150  void cd(const std::string& writingPath);
151 
157  bool inTransition() const;
158 
166  EventStorage::DWError putData(const unsigned int& dataSize, const void *event);
167 
168 
180  EventStorage::DWError putPrecompressedData(const unsigned int& dataSize,
181  const void *event);
182 
194  EventStorage::DWError putPrecompressedData(const unsigned int& entries,
195  const iovec_const* my_iovec);
196 
197 
206  EventStorage::DWError putData(const unsigned int& entries, const struct iovec* my_iovec);
207 
208 
217  EventStorage::DWError putData(const unsigned int& dataSize, const void *event, uint32_t& sizeToDisk);
218 
228  EventStorage::DWError putData(const unsigned int& entries, const iovec_const* my_iovec,
229  uint32_t& sizeToDisk);
230 
231 
236  EventStorage::DWError closeFile();
237 
241  EventStorage::DWError nextFile();
242 
246  std::string nameFile(const FileStatus& fs) const;
247 
252  int64_t getPosition() const;
253 
255  unsigned int eventsInFile() const;
256 
258  unsigned int eventsInFileSequence() const;
259 
261  unsigned int dataMB_InFile() const;
262 
264  unsigned int dataMB_InFileSequence() const;
265 
269  void registerCallBack(EventStorage::DataWriterCallBack *pUserCBclass);
270 
274 
277  void setGuid(const std::string& Guid);
278 
279  private:
280  // date and time utility, other private methods
281  void date_timeAsInt(uint32_t &getDate, uint32_t &getTime) const;
282  void openNextFile();
283  bool fileExists(const std::string& name) const;
284  void setRunParamsRecord(const run_parameters_record& rPar);
285 
286  //methods to write records to files
287  void file_record(void *ri, const void *pi);
288  void file_record(const file_name_strings& nst);
289  void file_record(const freeMetaDataStrings& fmdStrings);
290 
291  // some parsing is needed to fill metadata
292  std::string getAppName(const std::string& fileNameCore) const;
293  std::string getElement(const std::string& fileNameCore,
294  const std::string& element) const;
295  uint64_t getFileSize(const std::string& fileNameCore) const;
296 
297  //methods to add the Global Unique ID to the files
298  void spaceForGuid();
299  void replaceGuid();
300 
301  private: //data members
302 
303 
304  std::fstream m_cFile; // current file
305 
306  bool m_cFileOpen; // Is a file open at the moment?
307  bool m_openFailed; // Has the lest open operation failed?
308 
309  file_start_record m_file_start_record; // parameters of the current file
310  file_name_strings m_file_name_strings; // two significant strings in file name
312  file_end_record m_file_end_record; // more parameters of the file
313 
314  std::string m_guid; //the GUID
315  std::string m_next_guid;
316 
317  std::string m_writePath; // path to write
318  std::string m_nextWritePath; // next path to write
319  std::string m_fileNameCore; // most of the file name
320 
321  std::string m_project; // fields needed at some point
322  std::string m_streamType; //
323  std::string m_streamName; //
324  std::string m_stream;
325  unsigned int m_lumiBlockNumber;
326  std::string m_applicationName;
327 
329  unsigned int m_complevel;
331 
332  double m_cFileMB; // megabytes so far in the file, for adding up
333  long double m_runMB; // megabytes so far in the run
334  uLong m_check; //running checksum
335 
336  int64_t m_latestPosition; // offset of the latest written event
337 
338  EventStorage::DataWriterCallBack *m_callBack; // pointer to call-back, for reporting file names
339 
340  freeMetaDataStrings m_fmdStrings; // optional vector of strings, not written out if empty
341 
342  boost::shared_ptr<EventStorage::FileNameCallback> m_filenamecallback;
343 };
344 
345 }
346 #endif // OFFLINE_EVENTSTORAGE_V5_DATAWRITER_H
347 
348 
349 
350 
offline_EventStorage_v5::DataWriter::m_latestPosition
int64_t m_latestPosition
Definition: v5_DataWriter.h:336
offline_EventStorage_v5::DataWriter::nameFile
std::string nameFile(const FileStatus &fs) const
get the name of the current file
Definition: v5_DataWriter.cxx:621
offline_EventStorage_v5::DataWriter::m_check
uLong m_check
Definition: v5_DataWriter.h:334
offline_EventStorage_v5::DataWriter::getPosition
int64_t getPosition() const
get the offset of the latest written event; one should call it AFTER putData(...)
Definition: v5_DataWriter.cxx:417
offline_EventStorage_v5::DataWriter::m_applicationName
std::string m_applicationName
Definition: v5_DataWriter.h:326
offline_EventStorage_v5::FINISHED
@ FINISHED
Definition: v5_DataWriter.h:42
offline_EventStorage_v5::freeMetaDataStrings
std::vector< std::string > freeMetaDataStrings
Definition: v5_EventStorageRecords.h:60
offline_EventStorage_v5::DataWriter::~DataWriter
~DataWriter()
destructor, the way to close the sequence of files
Definition: v5_DataWriter.cxx:117
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
offline_EventStorage_v5::DataWriter::m_cFileMB
double m_cFileMB
Definition: v5_DataWriter.h:332
offline_EventStorage_v5::FileStatus
FileStatus
Definition: v5_DataWriter.h:42
offline_EventStorage_v5::DataWriter::m_stream
std::string m_stream
Definition: v5_DataWriter.h:324
v5_EventStorageRecords.h
offline_EventStorage_v5::DataWriter::m_file_start_record
file_start_record m_file_start_record
Definition: v5_DataWriter.h:309
offline_EventStorage_v5::DataWriter
Definition: v5_DataWriter.h:45
offline_EventStorage_v5::DataWriter::m_cFile
std::fstream m_cFile
Definition: v5_DataWriter.h:304
offline_EventStorage_v5::iovec_const
Definition: v5_EventStorageRecords.h:36
offline_EventStorage_v5::DataWriter::m_nextWritePath
std::string m_nextWritePath
Definition: v5_DataWriter.h:318
offline_EventStorage_v5::DataWriter::getFileSize
uint64_t getFileSize(const std::string &fileNameCore) const
Definition: v5_DataWriter.cxx:779
IDTPM::getTime
float getTime(const xAOD::TrackParticle &p)
Accessor utility function for getting the track time.
Definition: TrackParametersHelper.h:156
offline_EventStorage_v5::DataWriter::openNextFile
void openNextFile()
Definition: v5_DataWriter.cxx:544
offline_EventStorage_v5::file_end_record
Definition: v5_EventStorageRecords.h:81
offline_EventStorage_v5::DataWriter::good
bool good() const
feedback to user
Definition: v5_DataWriter.cxx:230
offline_EventStorage_v5::DataWriter::m_compression
CompressionType m_compression
Definition: v5_DataWriter.h:328
offline_EventStorage_v5::DataWriter::spaceForGuid
void spaceForGuid()
Definition: v5_DataWriter.cxx:754
offline_EventStorage_v5::DataWriter::inTransition
bool inTransition() const
The file currently open is not closed immediately after cd() this method will return true if we are i...
Definition: v5_DataWriter.cxx:636
offline_EventStorage_v5::DataWriter::m_file_end_record
file_end_record m_file_end_record
Definition: v5_DataWriter.h:312
offline_EventStorage_v5::DataWriter::dataMB_InFileSequence
unsigned int dataMB_InFileSequence() const
number of mega bytes written to the file sequence
Definition: v5_DataWriter.cxx:438
offline_EventStorage_v5::DataWriter::m_fileNameCore
std::string m_fileNameCore
Definition: v5_DataWriter.h:319
offline_EventStorage_v5::DataWriter::m_file_name_strings
file_name_strings m_file_name_strings
Definition: v5_DataWriter.h:310
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
offline_EventStorage_v5::DataWriter::setMaxFileNE
EventStorage::DWError setMaxFileNE(const unsigned int &maxFileNE)
max size of 1 file in number of data blocks (or events) 1 putData call is one block
Definition: v5_DataWriter.cxx:254
offline_EventStorage_v5::DataWriter::m_next_guid
std::string m_next_guid
Definition: v5_DataWriter.h:315
pi
#define pi
Definition: TileMuonFitter.cxx:65
offline_EventStorage_v5::DataWriter::fileExists
bool fileExists(const std::string &name) const
Definition: v5_DataWriter.cxx:535
offline_EventStorage_v5::DataWriter::DataWriter
DataWriter()
offline_EventStorage_v5::DataWriter::file_record
void file_record(void *ri, const void *pi)
Definition: v5_DataWriter.cxx:645
offline_EventStorage_v5::DataWriter::dataMB_InFile
unsigned int dataMB_InFile() const
number of mega bytes written to the current file
Definition: v5_DataWriter.cxx:433
offline_EventStorage_v5::DataWriter::getElement
std::string getElement(const std::string &fileNameCore, const std::string &element) const
offline_EventStorage_v5::DataWriter::closeFile
EventStorage::DWError closeFile()
Close the currently open file.
Definition: v5_DataWriter.cxx:444
offline_EventStorage_v5::DataWriter::m_runMB
long double m_runMB
Definition: v5_DataWriter.h:333
offline_EventStorage_v5::DataWriter::m_writePath
std::string m_writePath
Definition: v5_DataWriter.h:317
offline_EventStorage_v5::DataWriter::nextFile
EventStorage::DWError nextFile()
close the file and open next one immediately
Definition: v5_DataWriter.cxx:518
offline_EventStorage_v5::file_name_strings
Definition: v5_EventStorageRecords.h:55
offline_EventStorage_v5::DataWriter::m_project
std::string m_project
Definition: v5_DataWriter.h:321
offline_EventStorage_v5::DataWriter::getCompression
CompressionType getCompression() const
Returns the compression type for this file.
Definition: v5_DataWriter.cxx:792
offline_EventStorage_v5::DataWriter::initDW
void initDW(const std::string &writingPath, boost::shared_ptr< EventStorage::FileNameCallback > theFNCB, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression, const unsigned int compLevel)
Definition: v5_DataWriter.cxx:131
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
offline_EventStorage_v5::DataWriter::m_openFailed
bool m_openFailed
Definition: v5_DataWriter.h:307
offline_EventStorage_v5::DataWriter::date_timeAsInt
void date_timeAsInt(uint32_t &getDate, uint32_t &getTime) const
Definition: v5_DataWriter.cxx:212
offline_EventStorage_v5::DataWriter::eventsInFileSequence
unsigned int eventsInFileSequence() const
number of events written to the file sequence
Definition: v5_DataWriter.cxx:428
offline_EventStorage_v5::DataBuffer
Definition: v5_DataBuffer.h:16
offline_EventStorage_v5::DataWriter::setRunParamsRecord
void setRunParamsRecord(const run_parameters_record &rPar)
Definition: v5_DataWriter.cxx:260
offline_EventStorage_v5::DataWriter::m_cFileOpen
bool m_cFileOpen
Definition: v5_DataWriter.h:306
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
offline_EventStorage_v5::DataWriter::m_guid
std::string m_guid
Definition: v5_DataWriter.h:314
offline_EventStorage_v5::DataWriter::setGuid
void setGuid(const std::string &Guid)
Externally set the GUID for the next file in this sequence.
Definition: v5_DataWriter.cxx:774
offline_EventStorage_v5::DataWriter::putData
EventStorage::DWError putData(const unsigned int &dataSize, const void *event)
Write a single block of data.
Definition: v5_DataWriter.cxx:277
offline_EventStorage_v5::UNFINISHED
@ UNFINISHED
Definition: v5_DataWriter.h:42
offline_EventStorage_v5
Definition: ByteStreamDataWriterV5.h:15
offline_EventStorage_v5::DataWriter::m_fmdStrings
freeMetaDataStrings m_fmdStrings
Definition: v5_DataWriter.h:340
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
offline_EventStorage_v5::DataWriter::getAppName
std::string getAppName(const std::string &fileNameCore) const
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
offline_EventStorage_v5::DataWriter::m_lumiBlockNumber
unsigned int m_lumiBlockNumber
Definition: v5_DataWriter.h:325
offline_EventStorage_v5::DataWriter::DataWriter
DataWriter(const std::string &writingPath, boost::shared_ptr< EventStorage::FileNameCallback > theFNCB, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression=NONE, const unsigned int compLevel=1)
offline_EventStorage_v5::DataWriter::cd
void cd(const std::string &writingPath)
set another writing path
Definition: v5_DataWriter.cxx:630
offline_EventStorage_v5::DataWriter::m_internal_run_parameters_record
internal_run_parameters_record m_internal_run_parameters_record
Definition: v5_DataWriter.h:311
project
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
Definition: MeasurementSelector.h:142
offline_EventStorage_v5::DataWriter::m_compressed
DataBuffer * m_compressed
Definition: v5_DataWriter.h:330
offline_EventStorage_v5::DataWriter::setMaxFileMB
EventStorage::DWError setMaxFileMB(const unsigned int &maxFileMB)
max size of 1 file in MB.
Definition: v5_DataWriter.cxx:248
offline_EventStorage_v5::DataWriter::m_callBack
EventStorage::DataWriterCallBack * m_callBack
Definition: v5_DataWriter.h:338
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
offline_EventStorage_v5::DataWriter::m_streamType
std::string m_streamType
Definition: v5_DataWriter.h:322
RunTileMonitoring.streamType
streamType
Definition: RunTileMonitoring.py:158
offline_EventStorage_v5::CompressionType
CompressionType
Definition: v5_EventStorageRecords.h:41
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
offline_EventStorage_v5::file_start_record
Definition: v5_EventStorageRecords.h:44
offline_EventStorage_v5::DataWriter::m_complevel
unsigned int m_complevel
Definition: v5_DataWriter.h:329
offline_EventStorage_v5::DataWriter::m_streamName
std::string m_streamName
Definition: v5_DataWriter.h:323
offline_EventStorage_v5::DataWriter::putPrecompressedData
EventStorage::DWError putPrecompressedData(const unsigned int &dataSize, const void *event)
Write a single block of data already compressed.
Definition: v5_DataWriter.cxx:307
Herwig7_QED_EvtGen_ll.fs
dictionary fs
Definition: Herwig7_QED_EvtGen_ll.py:17
entries
double entries
Definition: listroot.cxx:49
offline_EventStorage_v5::run_parameters_record
Definition: v5_EventStorageRecords.h:62
offline_EventStorage_v5::DataWriter::m_filenamecallback
boost::shared_ptr< EventStorage::FileNameCallback > m_filenamecallback
Definition: v5_DataWriter.h:342
offline_EventStorage_v5::DataWriter::setGUID
void setGUID(const std::string &GUID)
Set the GUID for the next file in this sequence.
EventStorage
Definition: ByteStreamEventStorageInputSvc.h:25
offline_EventStorage_v5::DataWriter::registerCallBack
void registerCallBack(EventStorage::DataWriterCallBack *pUserCBclass)
If you want to define actions to be taken when a file is open or closed register your call-back class...
Definition: v5_DataWriter.cxx:737
offline_EventStorage_v5::NONE
@ NONE
Definition: v5_EventStorageRecords.h:41
offline_EventStorage_v5::internal_run_parameters_record
Definition: v5_EventStorageRecords.h:109
offline_EventStorage_v5::DataWriter::eventsInFile
unsigned int eventsInFile() const
number of events written to the currently open file
Definition: v5_DataWriter.cxx:423
offline_EventStorage_v5::DataWriter::replaceGuid
void replaceGuid()
Definition: v5_DataWriter.cxx:759
offline_EventStorage_v5::DataWriter::putData_implementation
EventStorage::DWError putData_implementation(const unsigned int &entries, const iovec_const *my_iovec, uint32_t &sizeToDisk, bool precompressed=false)
Definition: v5_DataWriter.cxx:325
python.BeamSpotUpdate.compression
compression
Definition: BeamSpotUpdate.py:188