ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsMERGE.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsMERGE_H
8#define ngcdcsMERGE_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14#include <stdio.h>
15#include <stdlib.h>
16#include <fcntl.h>
17#include <unistd.h>
18
19#include <ngc/core/ngcb.h>
20#include <ngc/core/ngcbSocket.h>
22
26#define ngcdcsMERGE_CHUNK (1024 * 64)
27
31#define ngcdcsMERGE_MAX_FILESIZE (2147483647 - ngcbFITS_BLOCK_LEN)
32
33/* ---- just for test
34#define ngcdcsMERGE_MAX_FILESIZE ((1024 * 1024 * 2 * 5) - ngcbFITS_BLOCK_LEN)
35---- */
36
42 size_t hdrSize;
43
45 int bitPix;
46
48 int naxis1;
49
51 int naxis2;
52
54 int naxis3;
55
58
60 double bzero;
61
63 int ftype;
64
66 char expId[64];
67
69 char fname[84];
70
72 unsigned int chunkSize;
73
76
78 int single;
79
85
87 void Clear() {
88 hdrSize = 0;
89 naxis1 = 0;
90 naxis2 = 0;
91 naxis3 = -1; // not set
92 bitPix = 8;
93 divisor = 1;
94 bzero = 0.0;
95 ftype = 0; // unresolved
96 expId[0] = '\0';
97 fname[0] = '\0';
98 cube2Ext = 0;
99 single = 0;
100 }
101
103 size_t FrameSize() {
104 return ((size_t)(abs(bitPix) / 8) * (size_t)naxis1 * (size_t)naxis2);
105 }
106};
107
113 FILE *stream;
114
116 int level;
117
120 stream = NULL;
121 level = 1;
122 }
123};
124
125
130{
131public:
134
137
140
142 unsigned int chunkSize;
143
146
149
151 char targetName[512];
152
154 char listItem[512];
155
158
161
163 ngcdcsMERGE();
164
166 explicit ngcdcsMERGE(void (*signalHandler)(int));
167
169 virtual ~ngcdcsMERGE();
170
172 int Initialized() {return (initialized_);}
173
175 int BigEndian();
176
178 void Id(int val) {id_ = val;}
179
181 int Id() {return (id_);}
182
184 char *ErrMsg() {return (erms_);}
185
187 int Run(int argc, char **argv);
188
190 void ExitSignal(int sig);
191
193 int Check(const char *name);
194
196 int Process(const char *name, int process=1);
197
199 int ProcessList(FILE *fd, const char *item=NULL);
200
202 int ProcessList(const char *fileName, const char *item=NULL);
203
205 int DeleteList(const char *fileName);
206
208 int DeleteList(FILE *fd);
209
211 int ProcessHdr(const char *fileName);
212
214 int ProcessFits(const char *source, const char *target=NULL);
215
217 int DeleteFits(const char *source);
218
220 int VerifyList(const char *fileName);
221
223 int VerifyHdr(const char *fileName);
224
226 int VerifyFits(const char *source, const char *target=NULL);
227
229 double Size() {return (vsize_);}
230
232 int NotificationStream(FILE *stream, int level=1);
233
235 void NotifySize(double size);
236
238 int Aborted() {return (aborted_);}
239
241 const char *Stat2Str(int stat);
242
244 void AttachDisplay();
245
247 void WaitForDisplay();
248
250 void Status(int stat);
251
253 void Completed(int stat, const char *msg=NULL);
254
255protected:
257 void Initialized(int flag) {initialized_ = flag;}
258
260 virtual int Args(int argc, char **argv);
261
263 virtual FILE *Usage();
264
266 virtual int InitCB();
267
269 virtual void StatusCB(int stat);
270
272 virtual void CompletedCB(int stat, const char *msg=NULL);
273
275 virtual void Notify(double size);
276
278 virtual void FileEvent(const char *id, const char *fileName);
279
281 virtual void NotifySizeCB(double size);
282
284 virtual int CheckPoint();
285
286 // Verbose message if verbose level exceeds level
287 virtual void Verbose(int level, const char *format, ...)
288 __attribute__ ((format(printf, 3, 4)));
289
291 virtual void Verbose(const char *format, ...)
292 __attribute__ ((format(printf, 2, 3)));
293
295 virtual void Log(int level, const char *format, ...)
296 __attribute__ ((format(printf, 3, 4)));
297
299 virtual void Log(const char *format, ...)
300 __attribute__ ((format(printf, 2, 3)));
301
302private:
304 void (*signalHandler_)(int);
305
307 int initialized_;
308
310 int endian_;
311
313 int id_;
314
316 char erms_[256];
317
319 char statDisp_[32];
320
322 void Init_();
323
325 void Usage_(FILE *stream);
326
328 void Cleanup_(char *s);
329
331 void CardReset_(char *line);
332
334 int ProcessList_(FILE *fd, const char *fileName, const char *item=NULL);
335
337 int DeleteList_(FILE *fd, const char *fileName);
338
340 char *Where_(char *buf, const char *key);
341
343 int GetKey_(char *buf, const char *key, int *value);
344
346 int GetKey_(char *buf, const char *key, double *value);
347
349 int GetKey_(char *buf, const char *key, char *value);
350
352 int SetKey_(char *buf, const char *fitsLine);
353
355 char *RdFitsLine_(FILE *fd);
356
358 int UpdateFitsLine_(FILE *fd, ngcb_off_t pos, const char *line);
359
361 int verificationRun_;
362
364 int justVerify_;
365
367 double vsize_;
368
370 double tsize_;
371
373 ngcdcs_ns_t ns_[4];
374
376 int numNs_;
377
379 int notifyLinkStat_;
380
382 void Notify_(double size);
383
385 void FileEventStart_(const char *fileName);
386
388 void FileEvent_(const char *id, const char *fileName);
389
391 int CheckPoint_();
392
394 int aborted_;
395
397 ngcb_pipe_t statPipe_;
398
400 int statDispClose_;
401
403 char statStr_[32];
404
406 int srvSocket_;
407
409 FILE *statusStream_;
410
412 int ServerMode_(int execHandle);
413
414 // Check if file descriptor has an event pending
415 int CheckFd_(int fd);
416
418 char thisHost_[64];
419
421 char padBlock_[ngcbFITS_BLOCK_LEN];
422
424 char fitsLine_[ngcbFITS_LINE_LEN + 1];
425
427 void ScaleReal32_(float *buf, int scale, size_t size);
428
430 void ScaleInt32_(int *buf, int scale, size_t size);
431
433 void ScaleInt16_(short *buf, int scale, size_t size);
434
436 void ScaleUInt16_(unsigned short *buf, int scale, size_t size);
437
439 void Scale_(char *buf, size_t size, int bitPix, int divisor);
440
442 char *AllocHdr_(const char *fileName, ngcdcs_merge_t *minfo);
443
445 int Copy_(FILE *fdOut, const char *host, const char *fileName,
446 ngcdcs_merge_t *minfo);
447
449 ngcdcsMRGSHM *shm_;
450
452 int ignoreFormat_;
453
455 int slow_;
456};
457
458#endif
void AttachDisplay()
Attach status display.
Definition ngcdcsMERGE_PUBLIC.cpp:3323
unsigned int chunkSize
Chunk size (bytes)
Definition ngcdcsMERGE.hpp:142
void Completed(int stat, const char *msg=NULL)
Completion event.
Definition ngcdcsMERGE_PUBLIC.cpp:3227
int DeleteList(const char *fileName)
Delete list file and the data sources specified therein.
Definition ngcdcsMERGE_PUBLIC.cpp:902
virtual void Notify(double size)
Transfer-progress notification call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3717
ngcdcsMERGE()
Constructor.
Definition ngcdcsMERGE_PUBLIC.cpp:28
int Check(const char *name)
Check item to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:2989
char listItem[512]
Requested list item name.
Definition ngcdcsMERGE.hpp:154
int largeFile
Flag to enable/disable large file extension.
Definition ngcdcsMERGE.hpp:148
int ProcessFits(const char *source, const char *target=NULL)
Process FITS-extension file.
Definition ngcdcsMERGE_PUBLIC.cpp:1522
int Aborted()
Return aborted-flag.
Definition ngcdcsMERGE.hpp:238
int ProcessList(FILE *fd, const char *item=NULL)
Process open list file.
Definition ngcdcsMERGE_PUBLIC.cpp:88
int Run(int argc, char **argv)
A data file merger main function.
Definition ngcdcsMERGE_PUBLIC.cpp:3388
int Process(const char *name, int process=1)
Process item (list file, header file or FITS-extension file)
Definition ngcdcsMERGE_PUBLIC.cpp:2559
int verify
Flag to initiate a verification run before processing.
Definition ngcdcsMERGE.hpp:136
virtual FILE * Usage()
Print-Usage call-back returning an apropriate error stream.
Definition ngcdcsMERGE_PUBLIC.cpp:3748
int parStream
Parallel streaming.
Definition ngcdcsMERGE.hpp:145
void Status(int stat)
Status update event.
Definition ngcdcsMERGE_PUBLIC.cpp:3198
virtual void Verbose(int level, const char *format,...) __attribute__((format(printf
Definition ngcdcsMERGE_PUBLIC.cpp:3782
void ExitSignal(int sig)
Exit signal handler.
Definition ngcdcsMERGE_PUBLIC.cpp:3702
virtual void StatusCB(int stat)
Status update event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3727
int NotificationStream(FILE *stream, int level=1)
Attach stream to notification list.
Definition ngcdcsMERGE_PUBLIC.cpp:3117
int cleanup
Flag to just perform a cleanup (delete the source files)
Definition ngcdcsMERGE.hpp:133
virtual int Args(int argc, char **argv)
Command line argument parser call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3742
int VerifyList(const char *fileName)
Verify list file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:2994
void Id(int val)
Set merger id.
Definition ngcdcsMERGE.hpp:178
virtual void NotifySizeCB(double size)
Call-back to communicate the expected size.
Definition ngcdcsMERGE_PUBLIC.cpp:3722
double Size()
Return the verification size (bytes)
Definition ngcdcsMERGE.hpp:229
void NotifySize(double size)
Communicate the expected size.
Definition ngcdcsMERGE_PUBLIC.cpp:3139
int logLevel
Logging level.
Definition ngcdcsMERGE.hpp:160
virtual int CheckPoint()
Check-point call-back for abort.
Definition ngcdcsMERGE_PUBLIC.cpp:3737
virtual ~ngcdcsMERGE()
Destructor.
Definition ngcdcsMERGE_PUBLIC.cpp:48
int invalidate
Flag to invalidate the source after successful merging.
Definition ngcdcsMERGE.hpp:139
int Id()
Return merger id.
Definition ngcdcsMERGE.hpp:181
int VerifyHdr(const char *fileName)
Verify FITS-header file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:3035
void Initialized(int flag)
Set initialization flag.
Definition ngcdcsMERGE.hpp:257
virtual void virtual void virtual void Log(int level, const char *format,...) __attribute__((format(printf
Log message if logging level exceeds level.
Definition ngcdcsMERGE_PUBLIC.cpp:3828
int verboseLevel
Verbose level.
Definition ngcdcsMERGE.hpp:157
int Initialized()
Return intitialization flag.
Definition ngcdcsMERGE.hpp:172
virtual int InitCB()
Initialization call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3755
const char * Stat2Str(int stat)
Convert status to string.
Definition ngcdcsMERGE_PUBLIC.cpp:3284
virtual void CompletedCB(int stat, const char *msg=NULL)
Completion event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3732
int BigEndian()
Endianess.
Definition ngcdcsMERGE_PUBLIC.cpp:3771
virtual void FileEvent(const char *id, const char *fileName)
File event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3712
void WaitForDisplay()
Wait for status display termination.
Definition ngcdcsMERGE_PUBLIC.cpp:3376
int ProcessHdr(const char *fileName)
Process header file.
Definition ngcdcsMERGE_PUBLIC.cpp:1136
char * ErrMsg()
Error message.
Definition ngcdcsMERGE.hpp:184
int VerifyFits(const char *source, const char *target=NULL)
Verify FITS-extension file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:3076
char targetName[512]
Requested targetName.
Definition ngcdcsMERGE.hpp:151
int DeleteFits(const char *source)
Delete FITS source file and the data sources specified therein.
Definition ngcdcsMERGE_PUBLIC.cpp:2204
Definition ngcdcsMRGSHM.hpp:123
off_t ngcb_off_t
Definition ngcb.h:45
#define ngcbFITS_LINE_LEN
Definition ngcb.h:175
#define ngcbFITS_BLOCK_LEN
Definition ngcb.h:190
#define ngcdcsMERGE_CHUNK
Definition ngcdcsMERGE.hpp:26
Definition ngcbSocket.h:49
Definition ngcdcsMERGE.hpp:40
int naxis3
Cube size.
Definition ngcdcsMERGE.hpp:54
int divisor
Pixel divisor.
Definition ngcdcsMERGE.hpp:57
int naxis1
Dimension in x-direction.
Definition ngcdcsMERGE.hpp:48
int naxis2
Dimension in y-direction.
Definition ngcdcsMERGE.hpp:51
int bitPix
BITPIX value.
Definition ngcdcsMERGE.hpp:45
unsigned int chunkSize
Chunk size (bytes)
Definition ngcdcsMERGE.hpp:72
size_t FrameSize()
Return frame size in bytes.
Definition ngcdcsMERGE.hpp:103
ngcdcs_merge_t()
Constructor.
Definition ngcdcsMERGE.hpp:81
char fname[84]
Frame name.
Definition ngcdcsMERGE.hpp:69
double bzero
BZERO value.
Definition ngcdcsMERGE.hpp:60
size_t hdrSize
Header size.
Definition ngcdcsMERGE.hpp:42
int cube2Ext
Move cube to FITS extension.
Definition ngcdcsMERGE.hpp:75
char expId[64]
Exposure id.
Definition ngcdcsMERGE.hpp:66
int single
Store to single files.
Definition ngcdcsMERGE.hpp:78
void Clear()
Clear structure.
Definition ngcdcsMERGE.hpp:87
int ftype
Frame type.
Definition ngcdcsMERGE.hpp:63
Definition ngcdcsMERGE.hpp:111
ngcdcs_ns_t()
Constructor.
Definition ngcdcsMERGE.hpp:119
int level
Level.
Definition ngcdcsMERGE.hpp:116
FILE * stream
Stream.
Definition ngcdcsMERGE.hpp:113