GRSISort
Created by P.C. Bender
Developement Team: P.C. Bender, R. Dunlop, V. Bildstein
An extension of the ROOT analysis Framework
TMidasFile Class Reference

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  EOpenType { EOpenType::kRead, EOpenType::kWrite }
 

Public Member Functions

 TMidasFile ()
 
 TMidasFile (const char *filename, TRawFile::EOpenType open_type=TRawFile::EOpenType::kRead)
 
 ~TMidasFile () override
 
void Close () override
 
void FillBuffer (const std::shared_ptr< TMidasEvent > &midasEvent, Option_t *opt="")
 
virtual size_t GetBytesRead ()
 
const char * GetFilename () const override
 
virtual size_t GetFileSize ()
 
int GetLastErrno () const
 
const char * GetLastError () const
 
std::shared_ptr< TRawEventGetOdbEvent () override
 
int GetRunNumber () override
 
int GetSubRunNumber () override
 
std::shared_ptr< TRawEventNewEvent () override
 
bool Open (const char *filename) override
 
void OutClose ()
 
bool OutOpen (const char *filename)
 
int Read (std::shared_ptr< TRawEvent > event) override
 
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 ()
 

Protected Attributes

size_t fBytesRead {0}
 
std::string fFilename
 
size_t fFileSize {0}
 
std::vector< char > fReadBuffer
 

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

uint32_t fCurrentBufferSize
 
int fCurrentEventNumber
 
bool fDoByteSwap
 
int fFile
 
void * fGzFile
 
int fLastErrno
 
std::string fLastError
 
uint32_t fMaxBufferSize
 
TXMLOdbfOdb
 
std::shared_ptr< TMidasEventfOdbEvent
 
int fOutFile
 
std::string fOutFilename
 
void * fOutGzFile
 
void * fPoFile
 
std::vector< char > fWriteBuffer
 

#include <TMidasFile.h>

+ Inheritance diagram for TMidasFile:
+ Collaboration diagram for TMidasFile:

Member Enumeration Documentation

◆ EOpenType

enum TRawFile::EOpenType
stronginherited
Enumerator
kRead 
kWrite 

Definition at line 33 of file TRawFile.h.

Constructor & Destructor Documentation

◆ TMidasFile() [1/2]

TMidasFile::TMidasFile ( )

default constructor

Definition at line 29 of file TMidasFile.cxx.

◆ TMidasFile() [2/2]

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

Definition at line 63 of file TMidasFile.cxx.

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

◆ ~TMidasFile()

TMidasFile::~TMidasFile ( )
override

destructor

Definition at line 71 of file TMidasFile.cxx.

References Close(), and OutClose().

Member Function Documentation

◆ Close()

void TMidasFile::Close ( )
overridevirtual

Close input file.

Implements TRawFile.

Definition at line 567 of file TMidasFile.cxx.

References fFile, TRawFile::fFilename, fGzFile, and fPoFile.

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

◆ FillBuffer()

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

Definition at line 458 of file TMidasFile.cxx.

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

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

◆ GetBytesRead()

virtual size_t TRawFile::GetBytesRead ( )
inlinevirtualinherited

Definition at line 56 of file TRawFile.h.

References TRawFile::fBytesRead.

Referenced by TDataLoop::Iteration().

◆ GetFilename()

const char* TMidasFile::GetFilename ( ) const
inlineoverridevirtual

Get the name of this file.

Reimplemented from TRawFile.

Definition at line 61 of file TMidasFile.h.

References TRawFile::fFilename.

Referenced by Open(), and WriteEvents().

◆ GetFileSize()

virtual size_t TRawFile::GetFileSize ( )
inlinevirtualinherited

Definition at line 57 of file TRawFile.h.

References TRawFile::fFileSize.

Referenced by TDataLoop::Iteration().

◆ GetLastErrno()

int TMidasFile::GetLastErrno ( ) const
inline

Get error value for the last file error.

Definition at line 62 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 63 of file TMidasFile.h.

References fLastError.

Referenced by WriteEvents().

◆ GetOdbEvent()

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

Reimplemented from TRawFile.

Definition at line 66 of file TMidasFile.h.

References fOdbEvent.

Referenced by ExamineMidasFile().

◆ GetRunNumber()

int TMidasFile::GetRunNumber ( )
overridevirtual

Implements TRawFile.

Definition at line 608 of file TMidasFile.cxx.

References TRawFile::fFilename.

Referenced by Open().

◆ GetSubRunNumber()

int TMidasFile::GetSubRunNumber ( )
overridevirtual

Implements TRawFile.

Definition at line 636 of file TMidasFile.cxx.

References TRawFile::fFilename.

Referenced by Open(), and QueueEvents().

◆ NewEvent()

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

Implements TRawFile.

Definition at line 75 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 116 of file TMidasFile.cxx.

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

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

◆ OutClose()

void TMidasFile::OutClose ( )

Close output file.

Definition at line 587 of file TMidasFile.cxx.

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

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

◆ 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 250 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 330 of file TMidasFile.cxx.

References TRawFile::fBytesRead, fCurrentEventNumber, fDoByteSwap, fLastErrno, fLastError, TRawFile::fReadBuffer, and ReadMoreBytes().

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

◆ ReadMoreBytes()

void TMidasFile::ReadMoreBytes ( size_t  bytes)
private

Definition at line 432 of file TMidasFile.cxx.

References fFile, fGzFile, fLastErrno, fLastError, TRawFile::fReadBuffer, and readpipe().

Referenced by Read(), and Skip().

◆ SetEPICSOdb()

void TMidasFile::SetEPICSOdb ( )
private

◆ SetFileOdb()

◆ SetGRIFFOdb()

◆ SetMaxBufferSize()

void TMidasFile::SetMaxBufferSize ( int  maxsize)

Definition at line 560 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 518 of file TMidasFile.cxx.

References fOutFile, and fOutGzFile.

Referenced by ProcessEvent().

◆ WriteBuffer()

bool TMidasFile::WriteBuffer ( )

Definition at line 498 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
private

Definition at line 99 of file TMidasFile.h.

Referenced by FillBuffer(), and WriteBuffer().

◆ fCurrentEventNumber

int TMidasFile::fCurrentEventNumber
private

Definition at line 104 of file TMidasFile.h.

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

◆ fDoByteSwap

bool TMidasFile::fDoByteSwap
private

"true" if file has to be byteswapped

Definition at line 106 of file TMidasFile.h.

Referenced by Read(), and Skip().

◆ fFile

int TMidasFile::fFile
private

open input file descriptor

Definition at line 108 of file TMidasFile.h.

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

◆ fFilename

◆ fFileSize

◆ fGzFile

void* TMidasFile::fGzFile
private

zlib compressed input file reader

Definition at line 109 of file TMidasFile.h.

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

◆ fLastErrno

int TMidasFile::fLastErrno
private

errno from the last operation

Definition at line 102 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 103 of file TMidasFile.h.

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

◆ fMaxBufferSize

uint32_t TMidasFile::fMaxBufferSize
private

Definition at line 100 of file TMidasFile.h.

Referenced by FillBuffer(), and SetMaxBufferSize().

◆ fOdb

TXMLOdb* TMidasFile::fOdb
private

Definition at line 89 of file TMidasFile.h.

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

◆ fOdbEvent

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

Definition at line 93 of file TMidasFile.h.

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

◆ fOutFile

int TMidasFile::fOutFile
private

open output file descriptor

Definition at line 111 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 96 of file TMidasFile.h.

Referenced by OutClose(), and OutOpen().

◆ fOutGzFile

void* TMidasFile::fOutGzFile
private

zlib compressed output file reader

Definition at line 112 of file TMidasFile.h.

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

◆ fPoFile

void* TMidasFile::fPoFile
private

popen() input file reader

Definition at line 110 of file TMidasFile.h.

Referenced by Close(), and Open().

◆ fReadBuffer

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

◆ fWriteBuffer

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

Definition at line 98 of file TMidasFile.h.

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