ATLAS Offline Software
Loading...
Searching...
No Matches
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
15
16
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
34namespace EventStorage {
35 class DataWriterCallBack;
36}
37
39
40 class DataBuffer;
41
43
44class DataWriter : boost::noncopyable
45{
46public:
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,
64 const CompressionType compression = NONE,
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,
79 const CompressionType compression = NONE,
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,
92 const CompressionType compression = NONE,
93 const unsigned int compLevel = 1);
94
95
96private:
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,
110 const CompressionType compression,
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
119public:
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;
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
static Double_t fs
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
#define pi
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition Guid.h:25
DataWriter(const std::string &writingPath, const std::string &fileNameCore, const run_parameters_record &rPar, const std::vector< std::string > &fmdStrings, const unsigned int startIndex=1, const CompressionType compression=NONE, const unsigned int compLevel=1)
constructor with metadata strings
void date_timeAsInt(uint32_t &getDate, uint32_t &getTime) const
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)
EventStorage::DWError putPrecompressedData(const unsigned int &dataSize, const void *event)
Write a single block of data already compressed.
EventStorage::DWError setMaxFileMB(const unsigned int &maxFileMB)
max size of 1 file in MB.
EventStorage::DWError putData_implementation(const unsigned int &entries, const iovec_const *my_iovec, uint32_t &sizeToDisk, bool precompressed=false)
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...
internal_run_parameters_record m_internal_run_parameters_record
void file_record(void *ri, const void *pi)
std::string nameFile(const FileStatus &fs) const
get the name of the current file
std::string getElement(const std::string &fileNameCore, const std::string &element) const
EventStorage::DataWriterCallBack * m_callBack
EventStorage::DWError closeFile()
Close the currently open file.
offline_EventStorage_v5::iovec_const iovec_const
~DataWriter()
destructor, the way to close the sequence of files
unsigned int dataMB_InFileSequence() const
number of mega bytes written to the file sequence
void setGUID(const std::string &GUID)
Set the GUID for the next file in this sequence.
bool fileExists(const std::string &name) const
void cd(const std::string &writingPath)
set another writing path
std::string getAppName(const std::string &fileNameCore) const
bool good() const
feedback to user
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
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)
uint64_t getFileSize(const std::string &fileNameCore) const
unsigned int dataMB_InFile() const
number of mega bytes written to the current file
unsigned int eventsInFileSequence() const
number of events written to the file sequence
int64_t getPosition() const
get the offset of the latest written event; one should call it AFTER putData(...)
void setGuid(const std::string &Guid)
Externally set the GUID for the next file in this sequence.
boost::shared_ptr< EventStorage::FileNameCallback > m_filenamecallback
void setRunParamsRecord(const run_parameters_record &rPar)
CompressionType getCompression() const
Returns the compression type for this file.
bool inTransition() const
The file currently open is not closed immediately after cd() this method will return true if we are i...
EventStorage::DWError putData(const unsigned int &dataSize, const void *event)
Write a single block of data.
EventStorage::DWError nextFile()
close the file and open next one immediately
unsigned int eventsInFile() const
number of events written to the currently open file
double entries
Definition listroot.cxx:49
std::vector< std::string > freeMetaDataStrings