LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
LCSplitWriter.h
1 #ifndef UTIL_LCSplitWriter_H
2 #define UTIL_LCSplitWriter_H 1
3 
4 #include "IO/LCWriter.h"
5 #include "LCIOTypes.h"
6 #include <string>
7 
8 namespace UTIL{
9 
16  class LCSplitWriter : public IO::LCWriter {
17 
18  public:
19 
29  _wrt( wrt ),
30  _maxBytes(maxBytes),
31  _baseFilename(""),
32  _filename(""),
33  _extension(""),
34  _count(0) ,
35  _lastCount(4294967295UL) {
36  }
37 
40  virtual ~LCSplitWriter() {;}
41 
42 
43  //-------------------- the LCWriter interface: -------------------------------------
44 
45 
51  virtual void open(const std::string & filename) throw (IO::IOException, std::exception ) ;
52 
59  virtual void open(const std::string & filename, int writeMode) throw (IO::IOException, std::exception ) ;
60 
66  virtual void writeRunHeader(const EVENT::LCRunHeader * hdr) throw (IO::IOException, std::exception ) ;
67 
71  virtual void setCompressionLevel(int level) {
72  _wrt->setCompressionLevel(level) ;
73  }
74 
75 
81  virtual void writeEvent(const EVENT::LCEvent * evt) throw (IO::IOException, std::exception ) ;
82 
87  virtual void close() throw (IO::IOException, std::exception ) ;
88 
89 
94  virtual void flush() throw (IO::IOException, std::exception ) ;
95 
96 
97  //---------------------------------------------------------------------------------------------
98 
101  EVENT::long64 fileSize() ;
102 
103 
104 
105  protected:
106  LCSplitWriter( );
107 
110  EVENT::long64 file_size( const char *fname) ;
111 
114  const std::string& getFilename() ;
115 
118  void setBaseFilename( const std::string& filename ) ;
119 
122  std::string getCountingString(unsigned count) ;
123 
124  IO::LCWriter* _wrt ;
125  EVENT::long64 _maxBytes ;
126  std::string _baseFilename ;
127  std::string _filename ;
128  std::string _extension ;
129  unsigned _count ;
130  unsigned _lastCount ;
131 
132  }; // class
133 
134 } // namespace UTIL
135 
136 #endif /* ifndef UTIL_LCSplitWriter_H */
virtual void setCompressionLevel(int level)=0
Set the compression level - needs to be called before open() otherwise call will have no effect...
Interface for the run header.
Definition: LCRunHeader.h:23
EVENT::long64 fileSize()
Return the current file size in bytes.
Definition: LCSplitWriter.cc:112
virtual void writeEvent(const EVENT::LCEvent *evt)
Writes the given file to file.
Definition: LCSplitWriter.cc:58
virtual void flush()
Flushes the output file/stream.
Definition: LCSplitWriter.cc:81
const std::string & getFilename()
Get the complete filename w/o extensiomn,e.g.
Definition: LCSplitWriter.cc:88
virtual void setCompressionLevel(int level)
Set CompressionLevel.
Definition: LCSplitWriter.h:71
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
LCWriter wrapper that automatically splits files if a given number of bytes is exceeded.
Definition: LCSplitWriter.h:16
LCSplitWriter(IO::LCWriter *wrt, EVENT::long64 maxBytes)
The constructor.
Definition: LCSplitWriter.h:28
virtual ~LCSplitWriter()
Destructor.
Definition: LCSplitWriter.h:40
std::string getCountingString(unsigned count)
Returns the string representation of the file number, e.g.
Definition: LCSplitWriter.cc:146
EVENT::long64 file_size(const char *fname)
Helper function that returns the file size in bytes - o if the file does not exist.
Definition: LCSplitWriter.cc:100
IOException used for reading/writing errors.
Definition: Exceptions.h:92
virtual void writeRunHeader(const EVENT::LCRunHeader *hdr)
Writes the given run header to file.
Definition: LCSplitWriter.cc:46
void setBaseFilename(const std::string &filename)
Helper function to determine base file name, i.e.
Definition: LCSplitWriter.cc:127
The main event interface.
Definition: LCEvent.h:30
Interface for writing data with LCIO.
Definition: LCWriter.h:27
virtual void close()
Closes the output file/stream.
Definition: LCSplitWriter.cc:77
virtual void open(const std::string &filename)
Opens a file for writing where the filename has to include the extension but not the number...
Definition: LCSplitWriter.cc:31