CtSaving.sip 6.54 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
25
26
27
28
29
30
31
32
33
34
35
36
%MappedType HeaderMap
{
%TypeHeaderCode
#include <map>
#include <string>
typedef std::map<std::string,std::string> HeaderMap;
typedef std::pair<std::string, std::string> HeaderValue;
%End

%ConvertToTypeCode
if (sipIsErr == NULL)
   return PyDict_Check(sipPy);

    *sipCppPtr = new HeaderMap();
    PyObject *key, *value;
37
    SIP_SSIZE_T pos = 0;
seb's avatar
seb committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

    while (PyDict_Next(sipPy, &pos, &key, &value)) 
    {
	if(PyString_Check(key) && PyString_Check(value))
	   (*sipCppPtr)->insert(HeaderValue(PyString_AS_STRING(key),PyString_AS_STRING(value)));
    }

    return sipGetState(sipTransferObj);
%End

%ConvertFromTypeCode
    PyObject* aReturnDict = PyDict_New();
    for(HeaderMap::iterator i = sipCpp->begin();i != sipCpp->end();++i)
	{
	  PyObject *value = PyString_FromString(i->second.c_str());
	  PyDict_SetItemString(aReturnDict,i->first.c_str(),value);
	  Py_DECREF(value);
	}
return aReturnDict;
%End

};

%MappedType HeaderValue
{
%TypeHeaderCode
#include <string>
#include <map>
typedef std::pair<std::string, std::string> HeaderValue;
%End

%ConvertToTypeCode
if (sipIsErr == NULL)
   {
     bool aCheckFlag = PySequence_Check(sipPy) && PySequence_Length(sipPy) == 2;
     if(aCheckFlag)
	{
	 PyObject *first = PySequence_GetItem(sipPy,0);
	 PyObject *second = PySequence_GetItem(sipPy,1);
	 aCheckFlag = (PyString_Check(first) && PyString_Check(second));
	 Py_DECREF(first);Py_DECREF(second);
	}
     return aCheckFlag;
   }
    PyObject *first = PySequence_GetItem(sipPy,0);
    PyObject *second = PySequence_GetItem(sipPy,1);
    *sipCppPtr = new HeaderValue(PyString_AS_STRING(first),PyString_AS_STRING(second));
    Py_DECREF(first);Py_DECREF(second);

    return sipGetState(sipTransferObj);
%End

%ConvertFromTypeCode
PyObject *key = PyString_FromString(sipCpp->first.c_str());
PyObject *value = PyString_FromString(sipCpp->second.c_str());
PyObject* aReturnTuple = PyTuple_Pack(2,key,value);
Py_DECREF(key);Py_DECREF(value);

return aReturnTuple;
%End

};

class CtSaving 
{
%TypeHeaderCode
#include <CtSaving.h>
105
#include <sstream>
seb's avatar
seb committed
106
107
108
109
110
111
using namespace lima;
%End
  public:

    CtSaving(CtControl&);
    ~CtSaving();
112
113
114
115
116
117

    enum ManagedMode
      {
	Software,
	Hardware
      };
seb's avatar
seb committed
118
119
  
    enum FileFormat {
120
121
122
123
124
125
126
	HARDWARE_SPECIFIC = -1,
	RAW,
	EDF,
	CBFFormat,
	NXS,
	FITS,
	EDFGZ,
seb's avatar
seb committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    };

    enum SavingMode {
      Manual,
      AutoFrame,
      AutoHeader,
    };
	
    enum OverwritePolicy {
      Abort,
      Overwrite,
      Append,
    };	

    struct Parameters {
      std::string directory;
      std::string prefix;
      std::string suffix;
145
      ImageType   imageType;
seb's avatar
seb committed
146
147
148
149
      long nextNumber;
      CtSaving::FileFormat fileFormat;
      CtSaving::SavingMode savingMode;
      CtSaving::OverwritePolicy overwritePolicy;
150
      std::string indexFormat;
seb's avatar
seb committed
151
      long framesPerFile;
152
153
      long nbframes;

154
      Parameters();
155
156
      void checkValid() const;

157
158
159
160
      const char* __repr__();
%MethodCode
	std::ostringstream str;
	str << *sipCpp;	
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
161
	const std::string& tmpString = str.str();
162
	sipRes = tmpString.c_str();
163
%End
seb's avatar
seb committed
164
165
166
167
168
    };


    // --- file parameters

169
170
    void setParameters(const Parameters &pars, int stream_idx=0);
    void getParameters(Parameters& pars /Out/, int stream_idx=0) const;
seb's avatar
seb committed
171

172
173
    void setDirectory(const std::string &directory, int stream_idx=0);
    void getDirectory(std::string &directory /Out/, int stream_idx=0) const;
seb's avatar
seb committed
174

175
176
    void setPrefix(const std::string &prefix, int stream_idx=0);
    void getPrefix(std::string &prefix /Out/, int stream_idx=0) const;
seb's avatar
seb committed
177

178
179
    void setSuffix(const std::string &suffix, int stream_idx=0);
    void getSuffix(std::string &suffix /Out/, int stream_idx=0) const;
seb's avatar
seb committed
180

181
182
    void setNextNumber(long number, int stream_idx=0);
    void getNextNumber(long& number, int stream_idx=0) const;
seb's avatar
seb committed
183

184
185
    void setFormat(FileFormat format, int stream_idx=0);
    void getFormat(FileFormat &format /Out/, int stream_idx=0) const;
seb's avatar
seb committed
186
187
188
189

    // --- saving modes

    void setSavingMode(SavingMode mode);
seb's avatar
seb committed
190
    void getSavingMode(SavingMode& mode /Out/) const;
seb's avatar
seb committed
191

192
193
194
    void setOverwritePolicy(OverwritePolicy policy, int stream_idx=0);
    void getOverwritePolicy(OverwritePolicy& policy /Out/, 
                            int stream_idx=0) const;
seb's avatar
seb committed
195

196
197
198
    void setFramesPerFile(unsigned long frames_per_file, int stream_idx=0);
    void getFramePerFile(unsigned long& frames_per_file /Out/, 
                         int stream_idx=0) const;
seb's avatar
seb committed
199

200
201
    void setManagedMode(ManagedMode mode);
    void getManagedMode(ManagedMode &mode /Out/) const;
seb's avatar
seb committed
202
203
204
205
206
    // --- common headers

    void resetCommonHeader();
    void setCommonHeader(const HeaderMap &header);
    void updateCommonHeader(const HeaderMap &header);
seb's avatar
seb committed
207
    void getCommonHeader(HeaderMap &header /Out/) const;
seb's avatar
seb committed
208
209
210
211
212
213
214
215

    void addToCommonHeader(const HeaderValue &value);

    // --- frame headers

    void updateFrameHeader(long frame_nr, const HeaderMap &header);
    void addToFrameHeader(long frame_nr,const HeaderValue &value);
    void validateFrameHeader(long frame_nr);
seb's avatar
seb committed
216
217
    void getFrameHeader(long frame_nr,HeaderMap &header /Out/) const;
    void takeFrameHeader(long frame_nr,HeaderMap &header /Out/);
seb's avatar
seb committed
218
219
220
221
222

    void removeFrameHeader(long frame_nr);
    void removeAllFrameHeaders();

    void frameReady(Data &);
seb's avatar
Saving:    
seb committed
223
224
225
226
227
    void resetLastFrameNb();

    void setEndCallback(TaskEventCallback *);
    // --- statistic

228
229
230
    void getWriteTimeStatistic(std::list<double>& /Out/, 
                               int stream_idx=0) const;
    void setStatisticHistorySize(int aSize, int stream_idx=0);
seb's avatar
Saving:    
seb committed
231
232
233
234

    // --- misc

    void clear();
235
236
    void writeFrame(int frame_nr = -1, int nb_frames = 1,
		    bool synchronous = true);
237
238
239

    void setStreamActive(int stream_idx, bool  active);
    void getStreamActive(int stream_idx, bool& active /Out/) const;
seb's avatar
seb committed
240
 };