CtSaving_Edf.h 3.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
seb's avatar
seb committed
22
23
24
#ifndef CTSAVING_EDF_H
#define CTSAVING_EDF_H

25
#include "lima/CtSaving.h"
seb's avatar
seb committed
26
27
28
29
30
31

namespace lima {

  class SaveContainerEdf : public CtSaving::SaveContainer
  {
    DEB_CLASS_NAMESPC(DebModControl,"Saving EDF Container","Control");
32
33
    class Compression;
    friend class Compression;
34
35
    class Lz4Compression;
    friend class Lz4Compression;
seb's avatar
seb committed
36
  public:
37
38
    struct _BufferHelper
    {
39
40
41
42
43
44
45
46
      DEB_CLASS_NAMESPC(DebModControl,"_BufferHelper","Control");

      void _init(int buffer_size);
    public:
      static const int BUFFER_HELPER_SIZE;
      _BufferHelper();
      _BufferHelper(int buffer_size);
      ~_BufferHelper();
47
      int used_size;
48
      void *buffer;
49
50
51
52
    };

    SaveContainerEdf(CtSaving::Stream& stream,
		     CtSaving::FileFormat format);
seb's avatar
seb committed
53
    virtual ~SaveContainerEdf();
54
55
    
    virtual bool needParallelCompression() const 
56
    {return m_format == CtSaving::EDFGZ || m_format == CtSaving::EDFLZ4;}
57
58
    virtual SinkTaskBase* getCompressionTask(const CtSaving::HeaderMap&);

seb's avatar
seb committed
59
  protected:
60
61
62
    virtual void* _open(const std::string &filename,
			std::ios_base::openmode flags);
    virtual void _close(void*);
63
    virtual long _writeFile(void*,Data &data,
seb's avatar
seb committed
64
65
			    CtSaving::HeaderMap &aHeader,
			    CtSaving::FileFormat);
66
    virtual void _clear();
seb's avatar
seb committed
67
  private:
68
69
    typedef std::vector<_BufferHelper*> ZBufferType;
    typedef std::map<int,ZBufferType*> dataId2ZBufferType;
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    struct MmapInfo
    {
      MmapInfo() :
	header_size(0),
	height_offset(0),
	size_offset(0),
	height(0),
	size(0),
	mmap_addr(NULL) {}
      long long header_size;
      long long height_offset;
      long long size_offset;
      long long height;
      long long size;
      void* mmap_addr;
    };
86
    template<class Stream>
87
88
89
      static MmapInfo _writeEdfHeader(Data&,CtSaving::HeaderMap&,
				      int framesPerFile,Stream&,
				      int nbCharReserved = 0);
90
91
    void _setBuffer(int frameNumber,ZBufferType*);
    ZBufferType* _takeBuffer(int dataId);
92
93
94
95
96
97
#ifdef WIN32
    class _OfStream
    {
    public:
      _OfStream();
      ~_OfStream();
seb's avatar
seb committed
98

99
100
101
102
103
104
105
      void clear();
      void exceptions(int exc);
      void open(const char* filename,
		std::ios_base::openmode openFlags = 
		std::ios_base::in | std::ios_base::out);
      bool is_open() const;
      void close();
106
      _int64 tellp() const;
107
108
109
110
111
112
113
114
115
116
      inline _OfStream& write(const char* data,int size);
      inline _OfStream& operator<< (const char *data);
      inline _OfStream& operator<< (const std::string& data);
      inline _OfStream& operator<< (const int data);
      inline _OfStream& operator<< (const long data);
    private:
      FILE* m_fout;
      int m_exc_flag;
    };
#else
117
    void*                        m_fout_buffer;
118
#endif
119
120
121
    CtSaving::FileFormat	 m_format;
    dataId2ZBufferType		 m_buffers;
    Mutex			 m_lock;
122
123
    MmapInfo			 m_mmap_info;
    std::string			 m_current_filename;
seb's avatar
seb committed
124
125
126
127
  };

}
#endif // CTSAVING_EDF_H