// // File : EyeEventFile.hh // // Purpose: Header file for TEyeEventFile.cc, // containing TEyeEventFile class declaration // // $Id: EyeEventFile.hh 11637 2010-10-29 10:07:29Z mathes $ // /* Generated by Together */ /** @file EyeEventFile.hh * Declaration for the class TEyeEventFile. * @author H.-J. Mathes, FzK */ #ifndef EYEEVENTFILE_HH #define EYEEVENTFILE_HH #include #include #include #include // ----- forward declaration(s) class TBranch; class TTree; class TEyeEvent; class TEyeEventHeader; class TEyeRunHeader; class TEyeRunTrailer; class TEyeEventFileSignalHandler; /** Class to handle saving/loading of the Eyes event data. * * This class inherits from ROOTs TFile class, thus all operations defined * for a TFile object are also valid here. * * This class is able to create/read from a ROOT file containing TEyeEvent * related objects. These objects are: * @li a TEyeRunheader named "RunHeader" * @li a TEyeRunTrailer named "RunTrailer" * @li a TTree named "EventTree", containing TEyeEvent objects */ class TEyeEventFile : public TFile { friend class TEyeEventFileSignalHandler; public: /** Create a new TEyeEventFile object using the defaults * given by the TFile default constructor. */ TEyeEventFile(); /** Create a new TEyeEventFile object with given name 'fname'. */ TEyeEventFile(const char *fname, Option_t *option="", const char *ftitle="", Int_t compress=1); /** Destructor for a TEyeEventFile object. * * Close an eventually open TEyeEventFile object, release all * resources occupied by it and delete it. */ virtual ~TEyeEventFile(); /** Close input/output file. See documentation of ROOT class TFile. */ void Close(Option_t *option=""); /** Get the current Id of the entry just read to access it later again. * * Note: Method might fail when writing to the file... */ unsigned int GetCurrentEntryId() const; /** 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. */ unsigned int GetNEvents(); /** Read a TEyeEvent object into an already allocated event buffer */ Bool_t ReadEvent(TEyeEvent**); /** Read a TEyeEvent object at the specified position into an already * allocated event buffer. */ Bool_t ReadEvent(TEyeEvent** event,unsigned int pos) { TEyeEventFile::Seek( pos ); return ReadEvent( event ); } /** Read a TEyeEventHeader object into an already allocated buffer */ Bool_t ReadEventHeader(TEyeEventHeader**); /** Read the run header (TEyeRunHeader) of the current file. * * Either a pointer to an allocated TEyeRunHeader or to a NULL-object * must be passed. * @return kTRUE, if the read was successful. */ Bool_t ReadRunHeader(TEyeRunHeader**); /** Read the run trailer (TEyeRunTrailer) of the current file. * * Either a pointer to an allocated TEyeRunTrailer or to a NULL-object * must be passed. * @return kTRUE, if the read was successful. */ Bool_t ReadRunTrailer(TEyeRunTrailer**); /** Rewind the internal pointer to the first entry of the TTree. */ void Rewind() { TEyeEventFile::Seek( (unsigned int)0 ); } #if (defined __GNUC__) && !(__GNUC__ < 3) // don't override method of base class, avoid warning -Woverloaded-virtual using TFile::Seek; #endif // __GNUC__ /** 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. * * Note: Second argument is currently ignored! */ //void TFile::Seek(Seek_t pos,TFile::ERelativeTo rel = TFile::kBeg) void Seek(unsigned int pos) { fCurrentEntry = pos; } /** Set the print (verbosity) level for this class. */ static void SetPrintLevel(int level=1) { fgPrintLevel = level; } /** Show some information about the TEyeEventFile verbosely to the * specified ostream, with default cout. */ void Show(std::ostream& str=std::cout); /** Write TEyeEvent to file, assume that address of TEyeEvent * is never changed (for TBranch reasons) */ Bool_t WriteEvent(TEyeEvent**); /** Write the TEyeRunHeader object to the file. * Return kTRUE, if the write was successful. */ Bool_t WriteRunHeader(TEyeRunHeader*); /** Write TEyeRunTrailer object to the file. * * Return kTRUE, if the write was successful. */ Bool_t WriteRunTrailer(TEyeRunTrailer*); protected: /** Exit handler (atexit()) for the class TEyeEventFile. * * Needed to close open files properly. */ static void ExitHandler(); /** Internal method: Get access handles to all branches of the tree. * * @return kFALSE if any expected branch could not be resolved. */ Bool_t GetBranches(TEyeEvent**); /** Internal method: Get access to the TTree object in the files and * determine the number of events in file. * * @return kFALSE if the expected TTree could not be found. */ Bool_t GetTree(); /** Setup a few internal things: * * @li install program exit handler */ void Setup(); /** A list of all files opened for writing. * * These files will be closed when the program is terminated abnormally. * The following signals when caught, are considered as 'abnormal': * @li SIGABRT * @li SIGINT * @li SIGTERM * @li SIGSEGV (via SIGABRT) */ static std::list fgFileList; /** */ static int fgPrintLevel; private: TBranch *fBranch; // event branch in split level=1 Int_t fCurrentEntry; // current entry id on file (read mode) TEyeEvent *fPartialEvent; // buffer for partial readout TEyeEvent *fEventBuffer; // backup pointer for branch Int_t fNEntries; // number of entries/events in tree TTree *fTree; // event data tree TBranch *fEventHeaderBranch; //TBranch *fFADCDataBranch; //TBranch *fPixelDataBranch; //TBranch *fPixelListBranch; static std::list fgSignalHandlerList; #ifndef DPA static void SigSegvHandler(int); #ifndef __DARWIN__ static struct sigaction fgOldSigSegvAction; #endif // __DARWIN__ #endif // DPA ClassDef(TEyeEventFile,0) }; #endif //EYEEVENTFILE_HH