// // File : MiEventFile.hh // // Purpose: Declaration of class TMirrorEventFile // // $Id: MiEventFile.hh 8759 2010-09-27 12:16:36Z mathes $ // #ifndef _MiEventFile_hh_ #define _MiEventFile_hh_ /** @file MiEventFile.hh * Declaration of class TMirrorEventFile. * @author H.-J. Mathes, FzK */ #include #include #include #include #include #include #include /** TFile based class to load/save TMirrorEvents. * * This class provides an interface to data files written by the single * mirror DAQ system using the ROOT * I/O system. It inherits ROOTs * TFile class * thus allowing the user to use all methods provided there. * * This implementation is extended by special access methods to read/write * the specific data structures present in the mirror DAQ. * * A file written with the class TMirrorEventFile might consist of: * @li an object (named RunHeader) of type TMirrorRunHeader * @li an object (named RunTrailer) of type TMirrorRunTrailer * @li a single branched tree (named EventBranch and EventTree respectively) * of TMirrorEvent objects. */ class TMirrorEventFile : public TFile { public: /** Create a new TMirrorEventFile object using the defaults * given by the TFile default constructor. */ TMirrorEventFile(); /** Create a new TMirrorEventFile object with given name 'fname'. */ TMirrorEventFile(const char *fname, Option_t *option="", const char *ftitle="", Int_t compress=1); /** Close an eventually open TMirrorEventFile object, release all * resources occupied by it and delete it finally. */ virtual ~TMirrorEventFile(); /** Close input/output file. See documentation of the ROOT class * TFile. */ void Close(Option_t *option=""); /** Get the number of events present in the current file. * * If no file is open, 0 is be returned. In case of a file opened for * writing, the number of events written to the file/tree so far is * returned. */ UInt_t GetNEvents(); /** Read TMirrorEvent into already allocated event buffer. Return * kTRUE if read was successful, kFALSE otherwise. */ Bool_t ReadMirrorEvent(TMirrorEvent**); /** Read the run header (TMirrorRunHeader) of the current file. Return * kTRUE if read was successful, kFALSE otherwise. * * 'header' must be either NULL or point to an already allocated * TMirrorRunHeader object. */ Bool_t ReadRunHeader(TMirrorRunHeader**); /** Read the run trailer (TMirrorRunTrailer) of the current file. Return * kTRUE if read was successful, kFALSE otherwise. * * 'trailer' must be either NULL or point to an already allocated * TMirrorRunTrailer object. */ Bool_t ReadRunTrailer(TMirrorRunTrailer**); /** Rewind the internal pointer to the first entry of the TTree. */ void Rewind() { Seek( 0 ); } /** Seek (position) the read 'pointer' before the specified event (tree * entry in the file. * * The next read will then return the specified event or no event * (and kFALSE) if the number of tree entries is less than the specified * number. * * Notes: * @li Seek_t is specified in $ROOTSYS/Rtypes.h with * typedef int Seek_t; * @li Only rel=TFile::kBeg is specified, i.e. this parameter is simply * ignored. * @li the streamer changes somehow if we use the proper interface */ #if 0 # if (ROOT_VERSION_CODE >= ROOT_VERSION(4,0,0)) void Seek(Long64_t pos,TFile::ERelativeTo /* rel */ = TFile::kBeg) # else void Seek(Seek_t pos,TFile::ERelativeTo /* rel */ = TFile::kBeg) # endif // ROOT_VERSION_CODE #else void Seek(Seek_t pos) #endif { fCurrentEvent = pos; } /** Write TMirrorEvent to file, assume that address of TMirrorEvent * is never changed (for TBranch reasons). * * Return kTRUE if write was successfull, kFALSE otherwise. */ Bool_t WriteMirrorEvent(TMirrorEvent**); /** Write the TMirrorRunHeader object to the file. * * Return kTRUE if write was successfull, kFALSE otherwise. */ Bool_t WriteRunHeader(TMirrorRunHeader*); /** Write the TMirrorRunHeader object to the file (obsolete). */ Bool_t WriteRunHeader(TMirrorRunHeader **header) { return WriteRunHeader( *header ); } /** Write the TMirrorRunTrailer object to the file. * Return kTRUE if write was successfull, kFALSE otherwise. */ Bool_t WriteRunTrailer(TMirrorRunTrailer*); /** Write the TMirrorRunTrailer object to the file (obsolete). */ Bool_t WriteRunTrailer(TMirrorRunTrailer **trailer) { return WriteRunTrailer( *trailer ); } private: // don't use these ones ... TMirrorEventFile(const TMirrorEventFile&); TMirrorEventFile& operator=(const TMirrorEventFile&); TBranch *fBranch; //! single branch in TTree Seek_t fCurrentEvent; //! current event id on file (rd) TMirrorEvent *fEvent; //! backup pointer for branch const char *fFileName; //! input data file name Int_t fNEntries; //! number of events in tree TTree *fTree; //! event data tree bool fIsReading; //! indicates that we read from file ClassDef(TMirrorEventFile,0) }; #endif // _MiEventFile_hh_