19 #ifndef DABC_BinaryFile
23 #ifndef MBS_LmdTypeDefs
52 if (fname==0 || *fname==0) {
53 fprintf(stderr,
"file name not specified\n");
61 fprintf(stderr,
"File open failed %s for reading\n", fname);
66 fprintf(stderr,
"Failure reading file %s header\n", fname);
72 fprintf(stderr,
"Wrong endian %u in file %s, expected 1\n", (
unsigned)
fFileHdr.
iEndian, fname);
84 fprintf(stderr,
"%s is original LMD file, which is not supported by DABC\n", fname);
109 if (fname==0 || *fname==0) {
110 fprintf(stderr,
"file name not specified\n");
118 fprintf(stderr,
"File open failed %s for writing\n", fname);
136 fprintf(stderr,
"Failure writing file %s header\n", fname);
157 if (!
isWriting() || (ptr==0) || (sz==0))
return false;
160 fprintf(stderr,
"fail to write buffer of size %u to lmd file\n", (
unsigned) sz);
170 bool ReadBuffer(
void* ptr, uint64_t* sz,
bool onlyevent =
false)
176 uint64_t maxsz = *sz; *sz = 0;
181 size_t readsz =
io->
fread(ptr, 1, maxsz,
fd);
185 if (readsz==0)
return false;
187 size_t checkedsz = 0;
191 while (checkedsz < readsz) {
194 if ((checkedsz +
hdr->
FullSize() > readsz) || (onlyevent && (checkedsz>0))) {
196 io->
fseek(
fd, -(readsz - checkedsz),
true);
Base class for file writing/reading in DABC.
FileInterface::Handle fd
if true, io object owned by file
bool CloseBasicFile()
reading/writing mode
bool fReadingMode
file descriptor
virtual bool fseek(Handle f, long int offset, bool relative=true)
virtual size_t fwrite(const void *ptr, size_t sz, size_t nmemb, Handle f)
virtual size_t fread(void *ptr, size_t sz, size_t nmemb, Handle f)
virtual Handle fopen(const char *fname, const char *mode, const char *=0)
Reading/writing LMD files (new API)
const FileHeader & hdr() const
bool OpenReading(const char *fname, const char *opt=0)
bool WriteBuffer(const void *ptr, uint64_t sz)
Write buffer or part of buffer User must ensure that content of buffer is corresponds to the lmd head...
bool OpenWriting(const char *fname, const char *opt=nullptr)
bool ReadBuffer(void *ptr, uint64_t *sz, bool onlyevent=false)
Reads buffer with several MBS events.
Support for MBS - standard GSI DAQ.