GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TMidasFile Class Reference

Detailed Description

Reader for MIDAS .mid files.

This Class is used to read and write MIDAS files in the root framework. It reads and writes TMidasEvents.

Definition at line 32 of file TMidasFile.h.

Public Types

enum class  EOpenType { kRead , kWrite }
 

Public Member Functions

 TMidasFile ()
 
 TMidasFile (const char *filename, TRawFile::EOpenType open_type=TRawFile::EOpenType::kRead)
 
 TMidasFile (const TMidasFile &)=default
 
 TMidasFile (TMidasFile &&) noexcept=default
 
 ~TMidasFile () override
 
char * BufferData ()
 
size_t BufferSize () const
 
virtual size_t BytesRead ()
 
void ClearBuffer ()
 
void Close () override
 
virtual std::string Filename () const
 
virtual void Filename (const char *val)
 
virtual size_t FileSize ()
 
void FileSize (size_t fileSize)
 
void FillBuffer (const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
 
virtual const char * GetFilename () const
 
int GetLastErrno () const
 
const char * GetLastError () const
 
std::shared_ptr< TRawEventGetOdbEvent () override
 
int GetRunNumber () override
 
int GetSubRunNumber () override
 
void IncrementBytesRead (size_t val=1)
 
std::shared_ptr< TRawEventNewEvent () override
 
bool Open (const char *filename) override
 
TMidasFileoperator= (const TMidasFile &)=default
 
TMidasFileoperator= (TMidasFile &&) noexcept=default
 
void OutClose ()
 
bool OutOpen (const char *filename)
 
int Read (std::shared_ptr< TRawEvent > event) override
 
void ResizeBuffer (size_t newSize)
 
void SetMaxBufferSize (int maxsize)
 
void Skip (size_t nofEvents) override
 
std::string Status (bool long_file_description=true) override
 
bool Write (const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
 
bool WriteBuffer ()
 

Private Member Functions

void ReadMoreBytes (size_t bytes)
 
void SetEPICSOdb ()
 
void SetFileOdb ()
 
void SetGRIFFOdb ()
 
void SetRunInfo (uint32_t time)
 
void SetTIGDAQOdb ()
 
void SetTIGOdb ()
 

Private Attributes

size_t fBytesRead {0}
 
uint32_t fCurrentBufferSize {0}
 
int fCurrentEventNumber {0}
 
bool fDoByteSwap {false}
 
int fFile {-1}
 
std::string fFilename
 
size_t fFileSize {0}
 
void * fGzFile {nullptr}
 
int fLastErrno {0}
 
std::string fLastError
 
uint32_t fMaxBufferSize {1000000}
 
TXMLOdbfOdb
 
std::shared_ptr< TMidasEventfOdbEvent
 
int fOutFile {-1}
 
std::string fOutFilename
 
void * fOutGzFile {nullptr}
 
void * fPoFile {nullptr}
 
std::vector< char > fReadBuffer
 
std::vector< char > fWriteBuffer
 
+ Inheritance diagram for TMidasFile:
+ Collaboration diagram for TMidasFile:

Member Enumeration Documentation

◆ EOpenType

enum class TRawFile::EOpenType
stronginherited
Enumerator
kRead 
kWrite 

Definition at line 33 of file TRawFile.h.

Constructor & Destructor Documentation

◆ TMidasFile() [1/4]

TMidasFile::TMidasFile ( )

default constructor

Definition at line 25 of file TMidasFile.cxx.

◆ TMidasFile() [2/4]

TMidasFile::TMidasFile ( const char * filename,
TRawFile::EOpenType open_type = TRawFile::EOpenType::kRead )
explicit

Definition at line 35 of file TMidasFile.cxx.

References fLastError, TRawFile::kRead, TRawFile::kWrite, Open(), OutOpen(), RED, and RESET_COLOR.

◆ TMidasFile() [3/4]

TMidasFile::TMidasFile ( const TMidasFile & )
default

◆ TMidasFile() [4/4]

TMidasFile::TMidasFile ( TMidasFile && )
defaultnoexcept

◆ ~TMidasFile()

TMidasFile::~TMidasFile ( )
override

destructor

Definition at line 49 of file TMidasFile.cxx.

References Close(), and OutClose().

Member Function Documentation

◆ BufferData()

char * TRawFile::BufferData ( )
inlineinherited

Definition at line 70 of file TRawFile.h.

References TRawFile::fReadBuffer.

Referenced by Read(), ReadMoreBytes(), and Skip().

◆ BufferSize()

size_t TRawFile::BufferSize ( ) const
inlineinherited

Definition at line 69 of file TRawFile.h.

References TRawFile::fReadBuffer.

Referenced by Read(), ReadMoreBytes(), and Skip().

◆ BytesRead()

virtual size_t TRawFile::BytesRead ( )
inlinevirtualinherited

Definition at line 61 of file TRawFile.h.

References TRawFile::fBytesRead.

Referenced by TDataLoop::Iteration(), and Status().

◆ ClearBuffer()

void TRawFile::ClearBuffer ( )
inlineinherited

Definition at line 71 of file TRawFile.h.

References TRawFile::fReadBuffer.

Referenced by Read(), and Skip().

◆ Close()

void TMidasFile::Close ( )
overridevirtual

Close input file.

Implements TRawFile.

Definition at line 546 of file TMidasFile.cxx.

References fFile, fGzFile, TRawFile::Filename(), and fPoFile.

Referenced by ~TMidasFile(), and Open().

◆ Filename() [1/2]

virtual std::string TRawFile::Filename ( ) const
inlinevirtualinherited

Get the name of this file.

Definition at line 66 of file TRawFile.h.

References TRawFile::fFilename.

Referenced by Close(), GetRunNumber(), GetSubRunNumber(), and Open().

◆ Filename() [2/2]

virtual void TRawFile::Filename ( const char * val)
inlinevirtualinherited

Definition at line 67 of file TRawFile.h.

References TRawFile::fFilename.

◆ FileSize() [1/2]

virtual size_t TRawFile::FileSize ( )
inlinevirtualinherited

Definition at line 63 of file TRawFile.h.

References TRawFile::fFileSize.

Referenced by TDataLoop::Iteration(), Open(), and Status().

◆ FileSize() [2/2]

void TRawFile::FileSize ( size_t fileSize)
inlineinherited

Definition at line 64 of file TRawFile.h.

References TRawFile::fFileSize.

◆ FillBuffer()

void TMidasFile::FillBuffer ( const std::shared_ptr< TMidasEvent > & midasEvent,
Option_t * opt = "" )

Definition at line 437 of file TMidasFile.cxx.

References fCurrentBufferSize, fMaxBufferSize, fWriteBuffer, and WriteBuffer().

Referenced by ProcessEvent(), Write(), and WriteEvents().

◆ GetFilename()

virtual const char * TRawFile::GetFilename ( ) const
inlinevirtualinherited

Get the name of this file.

Definition at line 56 of file TRawFile.h.

References TRawFile::fFilename.

Referenced by TLstFile::Open(), Open(), TRlmdFile::Open(), TTdrFile::Open(), and WriteEvents().

◆ GetLastErrno()

int TMidasFile::GetLastErrno ( ) const
inline

Get error value for the last file error.

Definition at line 65 of file TMidasFile.h.

References fLastErrno.

Referenced by WriteEvents().

◆ GetLastError()

const char * TMidasFile::GetLastError ( ) const
inline

Get error text for the last file error.

Definition at line 66 of file TMidasFile.h.

References fLastError.

Referenced by WriteEvents().

◆ GetOdbEvent()

std::shared_ptr< TRawEvent > TMidasFile::GetOdbEvent ( )
inlineoverridevirtual

Reimplemented from TRawFile.

Definition at line 69 of file TMidasFile.h.

References fOdbEvent.

Referenced by ExamineMidasFile().

◆ GetRunNumber()

int TMidasFile::GetRunNumber ( )
overridevirtual

Implements TRawFile.

Definition at line 587 of file TMidasFile.cxx.

References TRawFile::Filename().

Referenced by Open().

◆ GetSubRunNumber()

int TMidasFile::GetSubRunNumber ( )
overridevirtual

Implements TRawFile.

Definition at line 615 of file TMidasFile.cxx.

References TRawFile::Filename().

Referenced by Open(), and QueueEvents().

◆ IncrementBytesRead()

void TRawFile::IncrementBytesRead ( size_t val = 1)
inlineinherited

Definition at line 62 of file TRawFile.h.

References TRawFile::fBytesRead.

Referenced by Read(), and Skip().

◆ NewEvent()

std::shared_ptr< TRawEvent > TMidasFile::NewEvent ( )
inlineoverridevirtual

Implements TRawFile.

Definition at line 81 of file TMidasFile.h.

◆ Open()

bool TMidasFile::Open ( const char * filename)
overridevirtual

Open input file.

Open a midas .mid file with given file name.

Remote files can be accessed using these special file names:

  • pipein://command - read data produced by given command, see examples below
  • ssh://username@hostname/path/file.mid - read remote file through an ssh pipe
  • ssh://username@hostname/path/file.mid.gz and file.mid.bz2 - same for compressed files
  • dccp://path/file.mid (also file.mid.gz and file.mid.bz2) - read data from dcache, requires dccp in the PATH

Examples:

  • ./event_dump.exe /ladd/data9/t2km11/data/run02696.mid.gz - read normal compressed file
  • ./event_dump.exe ssh://ladd09//ladd/data9/t2km11/data/run02696.mid.gz - read compressed file through ssh to ladd09 (note double "/")
  • ./event_dump.exe pipein://"cat /ladd/data9/t2km11/data/run02696.mid.gz | gzip -dc" - read data piped from a command or script (note quotes)
  • ./event_dump.exe pipein://"gzip -dc /ladd/data9/t2km11/data/run02696.mid.gz" - another way to read compressed files
  • ./event_dump.exe dccp:///pnfs/triumf.ca/data/t2km11/aug2008/run02837.mid.gz - read file directly from a dcache pool (note triple "/")
Parameters
[in]filenameThe file to open.
Returns
"true" for succes, "false" for error, use GetLastError() to see why

Implements TRawFile.

Definition at line 95 of file TMidasFile.cxx.

References TRunInfo::ClearLibraryVersion(), Close(), fFile, fGzFile, TRawFile::Filename(), TRawFile::FileSize(), fLastErrno, fLastError, fOdbEvent, fPoFile, TRawFile::GetFilename(), GetRunNumber(), GetSubRunNumber(), hasSuffix(), O_LARGEFILE, Read(), s, TRunInfo::SetDetectorInformation(), SetFileOdb(), TRunInfo::SetLibraryVersion(), TChannel::SetMnemonicClass(), and TRunInfo::SetRunInfo().

Referenced by TMidasFile(), ExamineMidasFile(), and main().

◆ operator=() [1/2]

TMidasFile & TMidasFile::operator= ( const TMidasFile & )
default

◆ operator=() [2/2]

TMidasFile & TMidasFile::operator= ( TMidasFile && )
defaultnoexcept

◆ OutClose()

void TMidasFile::OutClose ( )

Close output file.

Definition at line 566 of file TMidasFile.cxx.

References fOutFile, fOutFilename, fOutGzFile, fWriteBuffer, and WriteBuffer().

Referenced by ~TMidasFile(), and OutOpen().

◆ OutOpen()

bool TMidasFile::OutOpen ( const char * filename)

Open output file.

Open a midas .mid file for OUTPUT with given file name.

Remote files not yet implemented

Parameters
[in]filenameThe file to open.
Returns
"true" for succes, "false" for error, use GetLastError() to see why

Definition at line 229 of file TMidasFile.cxx.

References fLastErrno, fLastError, fOutFile, fOutFilename, fOutGzFile, hasSuffix(), O_LARGEFILE, and OutClose().

Referenced by TMidasFile().

◆ Read()

int TMidasFile::Read ( std::shared_ptr< TRawEvent > event)
overridevirtual

Read one event from the file.

Parameters
[in]eventshared Pointer to an empty TMidasEvent
Returns
"true" for success, "false" for failure, see GetLastError() to see why

EDITED FROM THE ORIGINAL TO RETURN TOTAL SUCESSFULLY BYTES READ INSTEAD OF TRUE/FALSE, PCB

Implements TRawFile.

Definition at line 309 of file TMidasFile.cxx.

References TRawFile::BufferData(), TRawFile::BufferSize(), TRawFile::ClearBuffer(), fCurrentEventNumber, fDoByteSwap, fLastErrno, fLastError, TRawFile::IncrementBytesRead(), and ReadMoreBytes().

Referenced by ExamineMidasFile(), Open(), QueueEvents(), and WriteEvents().

◆ ReadMoreBytes()

void TMidasFile::ReadMoreBytes ( size_t bytes)
private

◆ ResizeBuffer()

void TRawFile::ResizeBuffer ( size_t newSize)
inlineinherited

Definition at line 72 of file TRawFile.h.

References TRawFile::fReadBuffer.

Referenced by ReadMoreBytes().

◆ SetEPICSOdb()

void TMidasFile::SetEPICSOdb ( )
private

◆ SetFileOdb()

◆ SetGRIFFOdb()

◆ SetMaxBufferSize()

void TMidasFile::SetMaxBufferSize ( int maxsize)

Definition at line 539 of file TMidasFile.cxx.

References fMaxBufferSize.

◆ SetRunInfo()

void TMidasFile::SetRunInfo ( uint32_t time)
private

◆ SetTIGDAQOdb()

◆ SetTIGOdb()

◆ Skip()

◆ Status()

std::string TMidasFile::Status ( bool long_file_description = true)
overridevirtual

◆ Write()

bool TMidasFile::Write ( const std::shared_ptr< TMidasEvent > & midasEvent,
Option_t * opt = "" )

Write one event to the output file.

Definition at line 497 of file TMidasFile.cxx.

References fOutFile, and fOutGzFile.

Referenced by ProcessEvent().

◆ WriteBuffer()

bool TMidasFile::WriteBuffer ( )

Definition at line 477 of file TMidasFile.cxx.

References fCurrentBufferSize, fOutFile, fOutGzFile, and fWriteBuffer.

Referenced by FillBuffer(), OutClose(), and WriteEvents().

Member Data Documentation

◆ fBytesRead

◆ fCurrentBufferSize

uint32_t TMidasFile::fCurrentBufferSize {0}
private

Definition at line 108 of file TMidasFile.h.

Referenced by FillBuffer(), and WriteBuffer().

◆ fCurrentEventNumber

int TMidasFile::fCurrentEventNumber {0}
private

Definition at line 113 of file TMidasFile.h.

Referenced by Read(), Skip(), and Status().

◆ fDoByteSwap

bool TMidasFile::fDoByteSwap {false}
private

"true" if file has to be byteswapped

Definition at line 115 of file TMidasFile.h.

Referenced by Read(), and Skip().

◆ fFile

int TMidasFile::fFile {-1}
private

open input file descriptor

Definition at line 117 of file TMidasFile.h.

Referenced by Close(), Open(), and ReadMoreBytes().

◆ fFilename

std::string TRawFile::fFilename
privateinherited

◆ fFileSize

◆ fGzFile

void* TMidasFile::fGzFile {nullptr}
private

zlib compressed input file reader

Definition at line 118 of file TMidasFile.h.

Referenced by Close(), Open(), and ReadMoreBytes().

◆ fLastErrno

int TMidasFile::fLastErrno {0}
private

errno from the last operation

Definition at line 111 of file TMidasFile.h.

Referenced by GetLastErrno(), Open(), OutOpen(), Read(), ReadMoreBytes(), and Skip().

◆ fLastError

std::string TMidasFile::fLastError
private

error string from last errno

Definition at line 112 of file TMidasFile.h.

Referenced by TMidasFile(), GetLastError(), Open(), OutOpen(), Read(), ReadMoreBytes(), and Skip().

◆ fMaxBufferSize

uint32_t TMidasFile::fMaxBufferSize {1000000}
private

Definition at line 109 of file TMidasFile.h.

Referenced by FillBuffer(), and SetMaxBufferSize().

◆ fOdb

TXMLOdb* TMidasFile::fOdb
private

Definition at line 102 of file TMidasFile.h.

Referenced by SetEPICSOdb(), SetFileOdb(), SetGRIFFOdb(), SetRunInfo(), SetTIGDAQOdb(), and SetTIGOdb().

◆ fOdbEvent

std::shared_ptr<TMidasEvent> TMidasFile::fOdbEvent
private

Definition at line 98 of file TMidasFile.h.

Referenced by GetOdbEvent(), Open(), and SetFileOdb().

◆ fOutFile

int TMidasFile::fOutFile {-1}
private

open output file descriptor

Definition at line 120 of file TMidasFile.h.

Referenced by OutClose(), OutOpen(), Write(), and WriteBuffer().

◆ fOutFilename

std::string TMidasFile::fOutFilename
private

name of the currently open file

Definition at line 105 of file TMidasFile.h.

Referenced by OutClose(), and OutOpen().

◆ fOutGzFile

void* TMidasFile::fOutGzFile {nullptr}
private

zlib compressed output file reader

Definition at line 121 of file TMidasFile.h.

Referenced by OutClose(), OutOpen(), Write(), and WriteBuffer().

◆ fPoFile

void* TMidasFile::fPoFile {nullptr}
private

popen() input file reader

Definition at line 119 of file TMidasFile.h.

Referenced by Close(), and Open().

◆ fReadBuffer

std::vector<char> TRawFile::fReadBuffer
privateinherited

◆ fWriteBuffer

std::vector<char> TMidasFile::fWriteBuffer
private

Definition at line 107 of file TMidasFile.h.

Referenced by FillBuffer(), OutClose(), and WriteBuffer().