ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcdcsMERGE.hpp
Go to the documentation of this file.
1
8#ifndef ngcdcsMERGE_H
9#define ngcdcsMERGE_H
10
11
12#ifndef __cplusplus
13#error This is a C++ include file and cannot be used from plain C
14#endif
15#include <stdio.h>
16#include <stdlib.h>
17#include <fcntl.h>
18#include <unistd.h>
19
20#include <ngc/core/ngcb.h>
21#include <ngc/core/ngcbSocket.h>
23
27#define ngcdcsMERGE_CHUNK (1024 * 64)
28
32#define ngcdcsMERGE_MAX_FILESIZE (2147483647 - ngcbFITS_BLOCK_LEN)
33
34/* ---- just for test
35#define ngcdcsMERGE_MAX_FILESIZE ((1024 * 1024 * 2 * 5) - ngcbFITS_BLOCK_LEN)
36---- */
37
43 size_t hdrSize;
44
46 int bitPix;
47
49 int naxis1;
50
52 int naxis2;
53
55 int naxis3;
56
59
61 double bzero;
62
64 int ftype;
65
67 char expId[64];
68
70 char fname[84];
71
73 unsigned int chunkSize;
74
77
79 int single;
80
86
88 void Clear() {
89 hdrSize = 0;
90 naxis1 = 0;
91 naxis2 = 0;
92 naxis3 = -1; // not set
93 bitPix = 8;
94 divisor = 1;
95 bzero = 0.0;
96 ftype = 0; // unresolved
97 expId[0] = '\0';
98 fname[0] = '\0';
99 cube2Ext = 0;
100 single = 0;
101 }
102
104 size_t FrameSize() {
105 return ((size_t)(abs(bitPix) / 8) * (size_t)naxis1 * (size_t)naxis2);
106 }
107};
108
114 FILE *stream;
115
117 int level;
118
121 stream = NULL;
122 level = 1;
123 }
124};
125
126
131{
132public:
135
138
141
143 unsigned int chunkSize;
144
147
150
152 char targetName[512];
153
155 char listItem[512];
156
159
162
164 ngcdcsMERGE();
165
167 explicit ngcdcsMERGE(void (*signalHandler)(int));
168
170 virtual ~ngcdcsMERGE();
171
173 int Initialized() {return (initialized_);}
174
176 int BigEndian();
177
179 void Id(int val) {id_ = val;}
180
182 int Id() {return (id_);}
183
185 char *ErrMsg() {return (erms_);}
186
188 int Run(int argc, char **argv);
189
191 void ExitSignal(int sig);
192
194 int Check(const char *name);
195
197 int Process(const char *name, int process=1);
198
200 int ProcessList(FILE *fd, const char *item=NULL);
201
203 int ProcessList(const char *fileName, const char *item=NULL);
204
206 int DeleteList(const char *fileName);
207
209 int DeleteList(FILE *fd);
210
212 int ProcessHdr(const char *fileName);
213
215 int ProcessFits(const char *source, const char *target=NULL);
216
218 int DeleteFits(const char *source);
219
221 int VerifyList(const char *fileName);
222
224 int VerifyHdr(const char *fileName);
225
227 int VerifyFits(const char *source, const char *target=NULL);
228
230 double Size() {return (vsize_);}
231
233 int NotificationStream(FILE *stream, int level=1);
234
236 void NotifySize(double size);
237
239 int Aborted() {return (aborted_);}
240
242 const char *Stat2Str(int stat);
243
245 void AttachDisplay();
246
248 void WaitForDisplay();
249
251 void Status(int stat);
252
254 void Completed(int stat, const char *msg=NULL);
255
256protected:
258 void Initialized(int flag) {initialized_ = flag;}
259
261 virtual int Args(int argc, char **argv);
262
264 virtual FILE *Usage();
265
267 virtual int InitCB();
268
270 virtual void StatusCB(int stat);
271
273 virtual void CompletedCB(int stat, const char *msg=NULL);
274
276 virtual void Notify(double size);
277
279 virtual void FileEvent(const char *id, const char *fileName);
280
282 virtual void NotifySizeCB(double size);
283
285 virtual int CheckPoint();
286
287 // Verbose message if verbose level exceeds level
288 virtual void Verbose(int level, const char *format, ...)
289 __attribute__ ((format(printf, 3, 4)));
290
292 virtual void Verbose(const char *format, ...)
293 __attribute__ ((format(printf, 2, 3)));
294
296 virtual void Log(int level, const char *format, ...)
297 __attribute__ ((format(printf, 3, 4)));
298
300 virtual void Log(const char *format, ...)
301 __attribute__ ((format(printf, 2, 3)));
302
303private:
305 void (*signalHandler_)(int);
306
308 int initialized_;
309
311 int endian_;
312
314 int id_;
315
317 char erms_[256];
318
320 char statDisp_[32];
321
323 void Init_();
324
326 void Usage_(FILE *stream);
327
329 void Cleanup_(char *s);
330
332 void CardReset_(char *line);
333
335 int ProcessList_(FILE *fd, const char *fileName, const char *item=NULL);
336
338 int DeleteList_(FILE *fd, const char *fileName);
339
341 char *Where_(char *buf, const char *key);
342
344 int GetKey_(char *buf, const char *key, int *value);
345
347 int GetKey_(char *buf, const char *key, double *value);
348
350 int GetKey_(char *buf, const char *key, char *value);
351
353 int SetKey_(char *buf, const char *fitsLine);
354
356 char *RdFitsLine_(FILE *fd);
357
359 int UpdateFitsLine_(FILE *fd, ngcb_off_t pos, const char *line);
360
362 int verificationRun_;
363
365 int justVerify_;
366
368 double vsize_;
369
371 double tsize_;
372
374 ngcdcs_ns_t ns_[4];
375
377 int numNs_;
378
380 int notifyLinkStat_;
381
383 void Notify_(double size);
384
386 void FileEventStart_(const char *fileName);
387
389 void FileEvent_(const char *id, const char *fileName);
390
392 int CheckPoint_();
393
395 int aborted_;
396
398 ngcb_pipe_t statPipe_;
399
401 int statDispClose_;
402
404 char statStr_[32];
405
407 int srvSocket_;
408
410 FILE *statusStream_;
411
413 int ServerMode_(int execHandle);
414
415 // Check if file descriptor has an event pending
416 int CheckFd_(int fd);
417
419 char thisHost_[64];
420
422 char padBlock_[ngcbFITS_BLOCK_LEN];
423
425 char fitsLine_[ngcbFITS_LINE_LEN + 1];
426
428 void ScaleReal32_(float *buf, int scale, size_t size);
429
431 void ScaleInt32_(int *buf, int scale, size_t size);
432
434 void ScaleInt16_(short *buf, int scale, size_t size);
435
437 void ScaleUInt16_(unsigned short *buf, int scale, size_t size);
438
440 void Scale_(char *buf, size_t size, int bitPix, int divisor);
441
443 char *AllocHdr_(const char *fileName, ngcdcs_merge_t *minfo);
444
446 int Copy_(FILE *fdOut, const char *host, const char *fileName,
447 ngcdcs_merge_t *minfo);
448
450 ngcdcsMRGSHM *shm_;
451
453 int ignoreFormat_;
454
456 int slow_;
457};
458
459#endif
void AttachDisplay()
Attach status display.
Definition ngcdcsMERGE_PUBLIC.cpp:3324
unsigned int chunkSize
Chunk size (bytes)
Definition ngcdcsMERGE.hpp:143
void Completed(int stat, const char *msg=NULL)
Completion event.
Definition ngcdcsMERGE_PUBLIC.cpp:3228
int DeleteList(const char *fileName)
Delete list file and the data sources specified therein.
Definition ngcdcsMERGE_PUBLIC.cpp:903
virtual void Notify(double size)
Transfer-progress notification call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3718
ngcdcsMERGE()
Constructor.
Definition ngcdcsMERGE_PUBLIC.cpp:29
int Check(const char *name)
Check item to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:2990
char listItem[512]
Requested list item name.
Definition ngcdcsMERGE.hpp:155
int largeFile
Flag to enable/disable large file extension.
Definition ngcdcsMERGE.hpp:149
int ProcessFits(const char *source, const char *target=NULL)
Process FITS-extension file.
Definition ngcdcsMERGE_PUBLIC.cpp:1523
int Aborted()
Return aborted-flag.
Definition ngcdcsMERGE.hpp:239
int ProcessList(FILE *fd, const char *item=NULL)
Process open list file.
Definition ngcdcsMERGE_PUBLIC.cpp:89
int Run(int argc, char **argv)
A data file merger main function.
Definition ngcdcsMERGE_PUBLIC.cpp:3389
int Process(const char *name, int process=1)
Process item (list file, header file or FITS-extension file)
Definition ngcdcsMERGE_PUBLIC.cpp:2560
int verify
Flag to initiate a verification run before processing.
Definition ngcdcsMERGE.hpp:137
virtual FILE * Usage()
Print-Usage call-back returning an apropriate error stream.
Definition ngcdcsMERGE_PUBLIC.cpp:3749
int parStream
Parallel streaming.
Definition ngcdcsMERGE.hpp:146
void Status(int stat)
Status update event.
Definition ngcdcsMERGE_PUBLIC.cpp:3199
virtual void Verbose(int level, const char *format,...) __attribute__((format(printf
Definition ngcdcsMERGE_PUBLIC.cpp:3783
void ExitSignal(int sig)
Exit signal handler.
Definition ngcdcsMERGE_PUBLIC.cpp:3703
virtual void StatusCB(int stat)
Status update event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3728
int NotificationStream(FILE *stream, int level=1)
Attach stream to notification list.
Definition ngcdcsMERGE_PUBLIC.cpp:3118
int cleanup
Flag to just perform a cleanup (delete the source files)
Definition ngcdcsMERGE.hpp:134
virtual int Args(int argc, char **argv)
Command line argument parser call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3743
int VerifyList(const char *fileName)
Verify list file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:2995
void Id(int val)
Set merger id.
Definition ngcdcsMERGE.hpp:179
virtual void NotifySizeCB(double size)
Call-back to communicate the expected size.
Definition ngcdcsMERGE_PUBLIC.cpp:3723
double Size()
Return the verification size (bytes)
Definition ngcdcsMERGE.hpp:230
void NotifySize(double size)
Communicate the expected size.
Definition ngcdcsMERGE_PUBLIC.cpp:3140
int logLevel
Logging level.
Definition ngcdcsMERGE.hpp:161
virtual int CheckPoint()
Check-point call-back for abort.
Definition ngcdcsMERGE_PUBLIC.cpp:3738
virtual ~ngcdcsMERGE()
Destructor.
Definition ngcdcsMERGE_PUBLIC.cpp:49
int invalidate
Flag to invalidate the source after successful merging.
Definition ngcdcsMERGE.hpp:140
int Id()
Return merger id.
Definition ngcdcsMERGE.hpp:182
int VerifyHdr(const char *fileName)
Verify FITS-header file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:3036
void Initialized(int flag)
Set initialization flag.
Definition ngcdcsMERGE.hpp:258
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:3829
int verboseLevel
Verbose level.
Definition ngcdcsMERGE.hpp:158
int Initialized()
Return intitialization flag.
Definition ngcdcsMERGE.hpp:173
virtual int InitCB()
Initialization call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3756
const char * Stat2Str(int stat)
Convert status to string.
Definition ngcdcsMERGE_PUBLIC.cpp:3285
virtual void CompletedCB(int stat, const char *msg=NULL)
Completion event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3733
int BigEndian()
Endianess.
Definition ngcdcsMERGE_PUBLIC.cpp:3772
virtual void FileEvent(const char *id, const char *fileName)
File event call-back.
Definition ngcdcsMERGE_PUBLIC.cpp:3713
void WaitForDisplay()
Wait for status display termination.
Definition ngcdcsMERGE_PUBLIC.cpp:3377
int ProcessHdr(const char *fileName)
Process header file.
Definition ngcdcsMERGE_PUBLIC.cpp:1137
char * ErrMsg()
Error message.
Definition ngcdcsMERGE.hpp:185
int VerifyFits(const char *source, const char *target=NULL)
Verify FITS-extension file to be processed.
Definition ngcdcsMERGE_PUBLIC.cpp:3077
char targetName[512]
Requested targetName.
Definition ngcdcsMERGE.hpp:152
int DeleteFits(const char *source)
Delete FITS source file and the data sources specified therein.
Definition ngcdcsMERGE_PUBLIC.cpp:2205
Definition ngcdcsMRGSHM.hpp:124
off_t ngcb_off_t
Definition ngcb.h:46
#define ngcbFITS_LINE_LEN
Definition ngcb.h:176
#define ngcbFITS_BLOCK_LEN
Definition ngcb.h:191
#define ngcdcsMERGE_CHUNK
Definition ngcdcsMERGE.hpp:27
Definition ngcbSocket.h:50
Definition ngcdcsMERGE.hpp:41
int naxis3
Cube size.
Definition ngcdcsMERGE.hpp:55
int divisor
Pixel divisor.
Definition ngcdcsMERGE.hpp:58
int naxis1
Dimension in x-direction.
Definition ngcdcsMERGE.hpp:49
int naxis2
Dimension in y-direction.
Definition ngcdcsMERGE.hpp:52
int bitPix
BITPIX value.
Definition ngcdcsMERGE.hpp:46
unsigned int chunkSize
Chunk size (bytes)
Definition ngcdcsMERGE.hpp:73
size_t FrameSize()
Return frame size in bytes.
Definition ngcdcsMERGE.hpp:104
ngcdcs_merge_t()
Constructor.
Definition ngcdcsMERGE.hpp:82
char fname[84]
Frame name.
Definition ngcdcsMERGE.hpp:70
double bzero
BZERO value.
Definition ngcdcsMERGE.hpp:61
size_t hdrSize
Header size.
Definition ngcdcsMERGE.hpp:43
int cube2Ext
Move cube to FITS extension.
Definition ngcdcsMERGE.hpp:76
char expId[64]
Exposure id.
Definition ngcdcsMERGE.hpp:67
int single
Store to single files.
Definition ngcdcsMERGE.hpp:79
void Clear()
Clear structure.
Definition ngcdcsMERGE.hpp:88
int ftype
Frame type.
Definition ngcdcsMERGE.hpp:64
Definition ngcdcsMERGE.hpp:112
ngcdcs_ns_t()
Constructor.
Definition ngcdcsMERGE.hpp:120
int level
Level.
Definition ngcdcsMERGE.hpp:117
FILE * stream
Stream.
Definition ngcdcsMERGE.hpp:114