ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsEXP.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsEXP_H
8#define ngcdcsEXP_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <stdarg.h>
18#include <string.h>
19#include <unistd.h>
20#include <fcntl.h>
21#include <errno.h>
22
23#include <ngc/core/ngcbSocket.h>
25#include <ngc/core/ngcbFITS.hpp>
26
27/*
28 * Exposure states
29 */
30#define ngcdcsEXP_NONE 0 //< not configured
31#define ngcdcsEXP_INACTIVE 1 //< exposure is inactive
32#define ngcdcsEXP_PENDING 2 //< exposure is pending
33#define ngcdcsEXP_INTEGRATING 4 //< integrating
34#define ngcdcsEXP_PAUSED 8 //< exposure is paused
35#define ngcdcsEXP_READING 16 //< reading out
36#define ngcdcsEXP_PROCESSING 32 //< processing
37#define ngcdcsEXP_TRANSFERRING 64 //< transferring
38#define ngcdcsEXP_COMPL_SUCCESS 128 //< successful completion
39#define ngcdcsEXP_COMPL_FAILURE 256 //< failure
40#define ngcdcsEXP_COMPL_ABORTED 512 //< exposure has been aborted
41#define ngcdcsEXP_COMPL_STOPPED 1024 //< exposure has been stopped/ended
42
46#define ngcdcsEXP_STARTING (ngcdcsEXP_INTEGRATING | ngcdcsEXP_INACTIVE)
47
51#define ngcdcsEXP_WIPING (ngcdcsEXP_READING | ngcdcsEXP_INACTIVE)
52
56#define ngcdcsEXP_ACTIVE(status) ((status > ngcdcsEXP_INACTIVE) && \
57 (status < ngcdcsEXP_COMPL_SUCCESS))
58
59/*
60 * Exposure types
61 */
62#define ngcdcsEXP_SUSTAINED 1 //< sustained read-out
63#define ngcdcsEXP_SINGLE 2 //< single exposure
64
65/*
66 * Exposure data file format
67 */
68#define ngcdcsEXP_FORMAT_SINGLE 1 //< single FITS files
69#define ngcdcsEXP_FORMAT_CUBE 2 //< data cube
70#define ngcdcsEXP_FORMAT_EXTENSION 3 //< image extension
71#define ngcdcsEXP_FORMAT_SINGLE_EXT 4 //< image extension (as single files)
72#define ngcdcsEXP_FORMAT_CUBE_EXT 5 //< data cube (as extension)
73#define ngcdcsEXP_FORMAT_GENERIC_1 6 //< generic-1
74#define ngcdcsEXP_FORMAT_GENERIC_2 7 //< generic-2
75
76/*
77 * Exposure naming schemes
78 */
79#define ngcdcsEXP_NAMING_REQUEST 1 //< request name
80#define ngcdcsEXP_NAMING_SEQUENCE 2 //< name + sequence index
81#define ngcdcsEXP_NAMING_AUTO 3 //< name + automatic index
82#define ngcdcsEXP_NAMING_REC_ID 4 //< use recording id
83#define ngcdcsEXP_NAMING_AUTO_ID 5 //< name + automatic id
84
88#define ngcdcsEXP_MAX_CLIENTS 8
89
90/*
91 * Event tags
92 */
93#define ngcdcsEXP_EVT_IMG 0x01 //< image event
94#define ngcdcsEXP_EVT_2AG 0x02 //< secondary autoguiding event
95#define ngcdcsEXP_EVT_ERR 0x04 //< eror event
96#define ngcdcsEXP_EVT_LOCK 0x08 //< lock EVH
97#define ngcdcsEXP_EVT_UNLOCK 0x10 //< unlock EVH
98
103 float offsetX; //< Offset in x-direction
104 float offsetY; //< Offset in y-direction
105 float quality; //< Quality good (1.0), bad (-1.0) or unknown (0.0)
106 double ts; //< Timestamp
107};
108
113 int tag; //< Event tag
114 int instance; //< Instance
115 int merge; //< Merge flag
116 unsigned int status; //< Status
117 int errorId; //< Error id
118 int ioError; //< An i/o-error occured
119 char msg[1024]; //< Message
120 ngcdcs_2ag_t ag; //< 2AG event
121
125 instance = 0;
126 merge = 0;
128 errorId = 0;
129 ioError = 0;
130 msg[0] = '\0';
131 ag.offsetX = 0.0;
132 ag.offsetY = 0.0;
133 ag.quality = 0.0;
134 ag.ts = 0.0;
135 }
136};
137
142 char id[64]; //< Exposure id
143 char host[64]; //< Host name
144 char fileName[256]; //< File name
145 char status[32]; //< Status
146 int method; //< Requested publishing method
147
150 strcpy(id, other.id);
151 strcpy(host, other.host);
152 strcpy(fileName, other.fileName);
153 strcpy(status, other.status);
154 method = other.method;
155 return (*this);
156 }
157
160 strcpy(id, other.id);
161 strcpy(host, other.host);
162 strcpy(fileName, other.fileName);
163 strcpy(status, other.status);
164 method = other.method;
165 }
166
169 id[0] = '\0'; host[0] = '\0'; fileName[0] = '\0'; status[0] = '\0';
170 method = 0;
171 }
172};
173
178{
179public:
182
185
188
191
194
196 int split;
197
199 char fileName[512];
200
202 FILE *fd;
203
205 FILE *fdList;
206
208 int nopen;
209
211 int merge;
212
215
218
220 unsigned int status;
221
223 unsigned int statusSaved;
224
227
230
232 int time;
233
235 char baseName[256];
236
238 char lastName[256 + 16];
239
241 char id[64];
242
244 char uuid[48];
245
247 int rev;
248
251
254
257
260
263
266
269
272
275
277 struct timeval startTime;
278
280 unsigned int drvStatus;
281
284
286 char drvMsg[256];
287
289 char origin[80];
290
293 if (this != &other)
294 {
295 /*
296 * Initialize exposure class
297 */
298 Init_();
299
300 /*
301 * Exposure handling cannot be copied...
302 */
303 }
304 return (*this);
305 }
306
308 ngcdcsEXP(const ngcdcsEXP &other) {
309 /*
310 * Initialize exposure class
311 */
312 Init_();
313
314 /*
315 * Exposure handling cannot be copied...
316 */
317 }
318
321 /*
322 * Initialize exposure class
323 */
324 Init_();
325 }
326
328 virtual ~ngcdcsEXP() {
329
330 /*
331 * Close the communication pipe
332 */
333 Lock();
334 if (pipe_[0] >= 0)
335 {
336 if (fdIn_ == pipe_[0]) fdIn_ = -1;
337 close(pipe_[0]); pipe_[0] = -1;
338 }
339 if (pipe_[1] >= 0)
340 {
341 if (fdOut_ == pipe_[1]) fdOut_ = -1;
342 shutdown(pipe_[1], SHUT_WR);
343 close(pipe_[1]); pipe_[1] = -1;
344 }
345 Unlock();
346
347 /*
348 * Delete protection semaphore
349 */
350 if (semExpEvt_ != NULL) delete semExpEvt_;
351 if (semExpLock_ != NULL) delete semExpLock_;
352 if (semExpSync_ != NULL) delete semExpSync_;
353 }
354
356 void SetFdIn(int f) {fdIn_ = f;}
357
359 void SetFdOut(int f) {fdOut_ = f;}
360
362 void ResetFd() {fdIn_ = pipe_[0]; fdOut_ = pipe_[1];}
363
365 int StatusFdIn() {return (fdIn_);}
366
368 int StatusFdOut() {return (fdOut_);}
369
372
374 void Lock() {if (semExpEvt_ != NULL) semExpEvt_->Lock();}
375
377 void Unlock() {if (semExpEvt_ != NULL) semExpEvt_->Unlock();}
378
381 if (semExpSync_ != NULL) semExpSync_->Set(0);
382 }
383
385 void InitInstLock(int n) {
386 numInst_ = n;
387 if (semExpSync_ != NULL)
388 {
389 if (instLock) semExpSync_->Set(1);
390 else semExpSync_->Set(0);
391 }
392 }
393
395 void Lock(int inst) {
396 if (semExpSync_ != NULL) semExpSync_->WaitCnt(inst + 1);
397 }
398
400 void Unlock(int inst) {
401 if ((semExpSync_ != NULL) && (numInst_ != 0))
402 {
403 if (semExpSync_->Cnt() != 0)
404 {
405 semExpSync_->Set(((inst + 1) % numInst_) + 1);
406 }
407 }
408 }
409
411 void Release() {
412 if (semExpSync_ != NULL) ResetInstLock();
413 if (semExpEvt_ != NULL)
414 {
415 semExpEvt_->TryLock();
416 semExpEvt_->Unlock();
417 }
418 if (semExpLock_ != NULL) semExpLock_->Set(ngcdcsEXP_MAX_CLIENTS * 2);
419 }
420
422 void Attach(int inst) {
423 instanceList_ |= (1 << inst);
424 abortList_ &= ~(1 << inst);
425 }
426
428 void Detach() {
429 instanceList_ = 0;
430 abortList_ = 0;
431 lastTransferList_ = 0;
432 }
433
435 void Detach(int inst) {
436 instanceList_ &= ~(1 << inst);
437 abortList_ &= ~(1 << inst);
438 lastTransferList_ &= ~(1 << inst);
439 }
440
442 int LastTransfer(int inst) {return ((lastTransferList_ & (1 << inst)) != 0);}
443
445 int LastTransfer() {return ((lastTransferList_ == instanceList_));}
446
451 int Attached() {return ((instanceList_ != 0));}
452
457 int Aborted() {return ((abortList_ != 0));}
458
461 Lock();
462 if (StatusFdOut() >= 0)
463 {
464 char p[(7 * sizeof(int)) + sizeof(ngcdcs_2ag_t)]; // message buffer
465 int *buf;
466
467 /*
468 * Copy
469 */
470 buf = (int *)p;
471 buf[0] = evt.tag;
472 buf[1] = evt.instance;
473 buf[2] = evt.merge;
474 buf[3] = *(int *)&evt.status;
475 buf[4] = evt.errorId;
476 buf[5] = evt.ioError;
477 buf[6] = (int)strlen(evt.msg);
478 memcpy(buf + 7, &evt.ag, sizeof(ngcdcs_2ag_t));
479
480 /*
481 * Send event structure
482 */
483 if (write(StatusFdOut(), p, sizeof(p)) != sizeof(p))
484 {
485 sprintf(ErrMsg(), "internal pipe error - %s", strerror(errno));
486 CkFdOut_();
487 Unlock();
488 return (ngcbFAILURE);
489 }
490 else if (buf[6] > 0)
491 {
492 /*
493 * Send message buffer
494 */
495 if (write(StatusFdOut(), evt.msg, buf[6]) != buf[6])
496 {
497 sprintf(ErrMsg(), "internal pipe error - %s", strerror(errno));
498 CkFdOut_();
499 Unlock();
500 return (ngcbFAILURE);
501 }
502 }
503 }
504 Unlock();
505
506 return (ngcbSUCCESS);
507 }
508
511 if (StatusFdIn() >= 0)
512 {
513 char p[(7 * sizeof(int)) + sizeof(ngcdcs_2ag_t)]; // message buffer
514 int *buf;
515
516 /*
517 * Receive event structure
518 */
519 if (read(StatusFdIn(), p, sizeof(p)) != sizeof(p))
520 {
521 sprintf(ErrMsg(), "internal pipe error - %s", strerror(errno));
522 strcpy(evt->msg, ErrMsg());
523 evt->ioError = 0;
524 evt->status = ngcdcsEXP_NONE;
525 return (ngcbFAILURE);
526 }
527
528 /*
529 * Copy
530 */
531 buf = (int *)p;
532 evt->tag = buf[0];
533 evt->instance = buf[1];
534 evt->merge = buf[2];
535 evt->status = *(unsigned int *)&buf[3];
536 evt->errorId = buf[4];
537 evt->ioError = buf[5];
538 memcpy(&evt->ag, buf + 7, sizeof(ngcdcs_2ag_t));
539
540 if ((evt->tag == ngcdcsEXP_EVT_IMG) && (evt->status != ngcdcsEXP_NONE))
541 {
542 /*
543 * Update internal lists (instance management)
544 */
545 if (!ngcdcsEXP_ACTIVE(evt->status))
546 {
547 /*
548 * Mark instance as inactive
549 */
550 instanceList_ &= ~(1 << evt->instance);
551
552 /*
553 * We remove it also from the last-transfer-list
554 */
555 lastTransferList_ &= ~(1 << evt->instance);
556 }
557 else if (evt->status == ngcdcsEXP_TRANSFERRING)
558 {
559 /*
560 * Add instance to the last-transfer-list
561 */
562 lastTransferList_ |= (1 << evt->instance);
563 }
564
566 {
567 /*
568 * Mark instance as aborted
569 */
570 abortList_ |= (1 << evt->instance);
571 }
572 }
573
574 if (buf[6] > 0)
575 {
576 /*
577 * Receive message buffer
578 */
579 if (read(StatusFdIn(), evt->msg, buf[6]) != buf[6])
580 {
581 sprintf(ErrMsg(), "internal pipe error - %s", strerror(errno));
582 strcpy(evt->msg, ErrMsg());
583 evt->ioError = 0;
584 evt->status = ngcdcsEXP_NONE;
585 return (ngcbFAILURE);
586 }
587
588 /*
589 * Terminate the message string
590 */
591 evt->msg[buf[6]] = '\0';
592 }
593 else
594 {
595 /*
596 * Terminate the message string
597 */
598 evt->msg[0] = '\0';
599 }
600 }
601
602 return (ngcbSUCCESS);
603 }
604
607 /*
608 * Wait until application is locked
609 */
610 semExpLock_->Wait();
611
612 /*
613 * Check if lock has been cancelled
614 */
615 if (lockCancelled_)
616 {
617 skipLock_++;
618 return (0);
619 }
620
621 return (1);
622 }
623
625 void ApplLocked() {semExpLock_->Post();}
626
628 void ApplRelease() {
629 if (useLock)
630 {
631 /*
632 * Signal that lock has been cancelled
633 */
634 Lock();
635 lockCancelled_ = 1;
636 Unlock();
637 semExpLock_->Post();
638 }
639 }
640
642 void ApplClear() {
643 if (useLock && lockCancelled_)
644 {
645 Lock();
646 lockCancelled_ = 0;
647 Unlock();
648 while (semExpLock_->TryWait() == 0);
649 }
650 }
651
654 int flag;
655 Lock();
656 flag = lockCancelled_;
657 Unlock();
658 return (flag);
659 }
660
662 int ApplSkip() {
663 if (skipLock_ > 0)
664 {
665 skipLock_--;
666 return (1);
667 }
668 else
669 {
670 return (0);
671 }
672 }
673
675 char *ErrMsg() {return (erms_);}
676
678 int Format(const char *name) {
679 if ((strcmp(name, "single") == 0) ||
680 (strcmp(name, "fits-single") == 0))
681 {
683 }
684 else if ((strcmp(name, "cube") == 0) ||
685 (strcmp(name, "fits-cube") == 0))
686 {
688 }
689 else if ((strcmp(name, "extension") == 0) ||
690 (strcmp(name, "fits-mef") == 0))
691 {
693 }
694 else if ((strcmp(name, "single-ext") == 0) ||
695 (strcmp(name, "fits-sef") == 0))
696 {
698 }
699 else if ((strcmp(name, "cube-ext") == 0) ||
700 (strcmp(name, "fits-cef") == 0))
701 {
703 }
704 else if (strcmp(name, "generic-1") == 0)
705 {
707 }
708 else if (strcmp(name, "generic-2") == 0)
709 {
711 }
712 else
713 {
714 strcpy(ErrMsg(), "unsupported data file format");
715 return (ngcbFAILURE);
716 }
717 return (ngcbSUCCESS);
718 }
719
721 int Format(int newFormat) {
722 if ((newFormat != ngcdcsEXP_FORMAT_SINGLE) &&
723 (newFormat != ngcdcsEXP_FORMAT_CUBE) &&
724 (newFormat != ngcdcsEXP_FORMAT_SINGLE_EXT) &&
725 (newFormat != ngcdcsEXP_FORMAT_CUBE_EXT) &&
726 (newFormat != ngcdcsEXP_FORMAT_EXTENSION) &&
727 (newFormat != ngcdcsEXP_FORMAT_GENERIC_1) &&
728 (newFormat != ngcdcsEXP_FORMAT_GENERIC_2))
729 {
730 sprintf(ErrMsg(), "unsupported data file format (%d)", newFormat);
731 return (ngcbFAILURE);
732 }
733 else
734 {
735 format = newFormat;
736 return (ngcbSUCCESS);
737 }
738 }
739
741 int Format() {return (format);}
742
744 const char *FormatName() {
745 switch (format)
746 {
748 {
749 strcpy(formatName_, "single");
750 break;
751 }
753 {
754 strcpy(formatName_, "cube");
755 break;
756 }
758 {
759 strcpy(formatName_, "extension");
760 break;
761 }
763 {
764 strcpy(formatName_, "single-ext");
765 break;
766 }
768 {
769 strcpy(formatName_, "cube-ext");
770 break;
771 }
773 {
774 strcpy(formatName_, "generic-1");
775 break;
776 }
778 {
779 strcpy(formatName_, "generic-2");
780 break;
781 }
782 default:
783 {
784 strcpy(formatName_, "unknown");
785 break;
786 }
787 }
788
789 return (formatName_);
790 }
791
793 const char *FormatNameELT() {
794 switch (format)
795 {
797 {
798 strcpy(formatName_, "FITS-Single");
799 break;
800 }
802 {
803 strcpy(formatName_, "FITS-Cube");
804 break;
805 }
807 {
808 strcpy(formatName_, "FITS-MEF");
809 break;
810 }
812 {
813 strcpy(formatName_, "FITS-SEF");
814 break;
815 }
817 {
818 strcpy(formatName_, "FITS-CEF");
819 break;
820 }
822 {
823 strcpy(formatName_, "generic-1");
824 break;
825 }
827 {
828 strcpy(formatName_, "generic-2");
829 break;
830 }
831 default:
832 {
833 strcpy(formatName_, "unknown");
834 break;
835 }
836 }
837
838 return (formatName_);
839 }
840
842 int Naming(int newNaming) {
843 if ((newNaming != ngcdcsEXP_NAMING_REQUEST) &&
844 (newNaming != ngcdcsEXP_NAMING_SEQUENCE) &&
845 (newNaming != ngcdcsEXP_NAMING_REC_ID) &&
846 (newNaming != ngcdcsEXP_NAMING_AUTO_ID) &&
847 (newNaming != ngcdcsEXP_NAMING_AUTO))
848 {
849 sprintf(ErrMsg(), "unsupported naming scheme %d", newNaming);
850 return (ngcbFAILURE);
851 }
852 else
853 {
854 naming = newNaming;
855 return (ngcbSUCCESS);
856 }
857 }
858
860 int Naming() {return (naming);}
861
863 int DataPath(const char *path) {
864 if (strlen(path) > 0)
865 {
866 if (strlen(path) >= (256 - 64))
867 {
868 sprintf(ErrMsg(), "path name is too long");
869 return (ngcbFAILURE);
870 }
871
872 if (fileCheck)
873 {
874 /*
875 * Check permissions
876 */
877 if (!ngcbIsDir(path))
878 {
879 sprintf(ErrMsg(), "%s is no directory", path);
880 return (ngcbFAILURE);
881 }
882 else if (!ngcbWritePerm(path))
883 {
884 sprintf(ErrMsg(), "no write permission on %s", path);
885 return (ngcbFAILURE);
886 }
887 }
888
889 strcpy(dataPath_, path);
890 }
891 else
892 {
893 dataPath_[0] = '\0';
894 }
895
896 if ((baseName[0] != '/') && (baseName[0] != '.'))
897 {
898 if (strlen(dataPath_) > 0) sprintf(path_, "%s/%s", dataPath_, baseName);
899 else strcpy(path_, baseName);
900 }
901 else
902 {
903 strcpy(path_, baseName);
904 }
905
906 return (ngcbSUCCESS);
907 }
908
910 char *DataPath() {return (dataPath_);}
911
913 int BaseName(const char *name) {
914 char tmpPath[512];
915
916 if (strlen(name) == 0)
917 {
918 baseName[0] = '\0'; path_[0] = '\0';
919 return (ngcbSUCCESS);
920 }
921 else if (strlen(name) > (256 - 64))
922 {
923 sprintf(ErrMsg(), "exposure base name is too long");
924 return (ngcbFAILURE);
925 }
926 else if ((name[0] != '/') && (name[0] != '.'))
927 {
928 if (strlen(dataPath_) > 0) sprintf(tmpPath, "%s/%s", dataPath_, name);
929 else strcpy(tmpPath, name);
930 }
931 else
932 {
933 strcpy(tmpPath, name);
934 }
935
936 if (fileCheck)
937 {
938 char tmp[224];
939
940 /*
941 * Check permissions
942 */
943 ngcbParentDir(tmp, tmpPath);
944 if (!ngcbIsDir(tmp))
945 {
946 sprintf(ErrMsg(), "%s is no directory", tmp);
947 return (ngcbFAILURE);
948 }
949 else if (!ngcbWritePerm(tmp))
950 {
951 sprintf(ErrMsg(), "no write permission on %s", tmp);
952 return (ngcbFAILURE);
953 }
954 }
955
956 strcpy(baseName, name);
957 strcpy(path_, tmpPath);
958
959 return (ngcbSUCCESS);
960 }
961
963 const char *BaseName() {return (baseName);}
964
966 void AssignUUID(const char *value) {
967 str2str(uuid, value, sizeof(uuid) - 1);
968 }
969
971 const char *Path() {
973 {
974 if (strlen(id) == 0) path_[0] = '\0';
975 else if (strlen(dataPath_) > 0) sprintf(path_, "%s/%s", dataPath_, id);
976 else strcpy(path_, id);
977 }
978 else
979 {
980 if (strlen(baseName) == 0)
981 {
982 path_[0] = '\0';
983 }
984 else if ((baseName[0] != '/') && (baseName[0] != '.'))
985 {
986 if (strlen(dataPath_) > 0) sprintf(path_, "%s/%s", dataPath_, baseName);
987 else strcpy(path_, baseName);
988 }
989 else
990 {
991 strcpy(path_, baseName);
992 }
993 if ((naming == ngcdcsEXP_NAMING_AUTO_ID) && (strlen(uuid) > 0))
994 {
995 strcat(path_, "_");
996 strcat(path_, uuid);
997 }
998 }
999 return (path_);
1000 }
1001
1003 const char *TmpPath() {
1004 if (strlen(dataPath_) > 0) sprintf(path_, "%s/_ngctmp", dataPath_);
1005 else strcpy(path_, "_ngctmp");
1006 return (path_);
1007 }
1008
1012 {
1013 /*
1014 * Increment sequence number
1015 */
1017 return (ngcbSUCCESS);
1018 }
1019 else if (naming == ngcdcsEXP_NAMING_AUTO)
1020 {
1021 int idx;
1022 const char *p = Path();
1023
1024 if (p == NULL)
1025 {
1026 /*
1027 * We have no path where to look for the index
1028 */
1029 strcpy(ErrMsg(), "no valid path");
1030 return (ngcbFAILURE);
1031 }
1032
1033 /*
1034 * Find next matching index
1035 */
1036 idx = ngcbFindIndex(p, sequenceNumber, ErrMsg());
1037 if (idx < 0) return (ngcbFAILURE);
1038 else if (idx == 0) sequenceNumber = 1;
1039 else sequenceNumber = idx;
1040
1041 return (ngcbSUCCESS);
1042 }
1043
1044 return (ngcbSUCCESS);
1045 }
1046
1048 void StatStr(char *s) {Stat2Str(s, status);}
1049
1051 void Stat2Str(char *s, unsigned int stat) {
1052 switch (stat)
1053 {
1054 case ngcdcsEXP_NONE: s[0] = '\0'; break;
1055 case ngcdcsEXP_INACTIVE: strcpy(s, "inactive"); break;
1056 case ngcdcsEXP_PENDING: strcpy(s, "pending"); break;
1057 case ngcdcsEXP_STARTING: strcpy(s, "starting"); break;
1058 case ngcdcsEXP_WIPING: strcpy(s, "wiping"); break;
1059 case ngcdcsEXP_INTEGRATING: strcpy(s, "integrating"); break;
1060 case ngcdcsEXP_PAUSED: strcpy(s, "paused"); break;
1061 case ngcdcsEXP_READING: strcpy(s, "reading"); break;
1062 case ngcdcsEXP_PROCESSING: strcpy(s, "processing"); break;
1063 case ngcdcsEXP_TRANSFERRING: strcpy(s, "transferring"); break;
1064 case ngcdcsEXP_COMPL_ABORTED: strcpy(s, "aborted"); break;
1065 case ngcdcsEXP_COMPL_FAILURE: strcpy(s, "failure"); break;
1066 case ngcdcsEXP_COMPL_SUCCESS: strcpy(s, "success"); break;
1067 case ngcdcsEXP_COMPL_STOPPED: strcpy(s, "success"); break;
1068 default: strcpy(s, "unknown"); break;
1069 }
1070 }
1071
1073 void ExpStartTime(struct timeval &timeVal) {
1074 int hour, min;
1075 double sec;
1076 Lock();
1077 expStartTimeMJD_ = ngcbTime2MJD(timeVal);
1078 ngcbTime2UTC(timeVal, expStartTime_, 4);
1079 startTime.tv_sec = timeVal.tv_sec;
1080 startTime.tv_usec = timeVal.tv_usec;
1081 if (sscanf(expStartTime_, "%*[^T]%*[T]%2d:%2d:%80lf\n", &hour, &min, &sec) == 3)
1082 {
1083 expStartTimeUTC_ = (static_cast<double>(hour) * 3600.0) + (static_cast<double>(min) * 60.0) + sec;
1084 }
1085 Unlock();
1086 }
1087
1089 const char *ExpStartTime() {return (expStartTime_);}
1090
1092 double ExpStartTimeMJD() {return (expStartTimeMJD_);}
1093
1095 double ExpStartTimeUTC() {return (expStartTimeUTC_);}
1096
1098 void TimeStamp() {
1099 struct timeval timeVal;
1100 ngcbGetTime(&timeVal);
1101 Lock();
1102 expStartTimeMJD_ = ngcbTime2MJD(timeVal);
1103 ngcbTime2UTC(timeVal, expStartTime_, 4);
1104 Unlock();
1105 }
1106
1108 void DrvStatus(unsigned int stat) {
1109 drvStatus = stat;
1111 }
1112
1114 void EndFlag(int flag) {
1115 Lock();
1116 endFlag_ = flag;
1117 Unlock();
1118 }
1119
1121 int EndFlag() {
1122 int flag;
1123 Lock();
1124 flag = endFlag_;
1125 Unlock();
1126 return (flag);
1127 }
1128
1129protected:
1130
1131private:
1133 char erms_[256];
1134
1136 char path_[512];
1137
1139 char dataPath_[256];
1140
1142 char formatName_[64];
1143
1145 int pipe_[2];
1146
1148 ngcdcs_expevt_t expEvt_;
1149
1151 int numInst_;
1152
1154 ngcbSEM *semExpSync_;
1155
1157 ngcbSEM *semExpEvt_;
1158
1160 ngcbSEM *semExpLock_;
1161
1163 char expStartTime_[64];
1164
1166 double expStartTimeMJD_;
1167
1169 double expStartTimeUTC_;
1170
1172 int endFlag_;
1173
1175 int instanceList_;
1176
1178 int abortList_;
1179
1181 int lastTransferList_;
1182
1184 int fdIn_;
1185
1187 int fdOut_;
1188
1190 int lockCancelled_;
1191
1193 int skipLock_;
1194
1196 void Init_() {
1197 char *evar;
1198
1199 /*
1200 * Initialize with zero to avoid UMR
1201 */
1202 memset(baseName, 0, sizeof(baseName));
1203 memset(lastName, 0, sizeof(lastName));
1204 memset(dataPath_, 0, sizeof(dataPath_));
1205 memset(formatName_, 0, sizeof(formatName_));
1206
1207 /*
1208 * Construct basic data path
1209 */
1210 evar = getenv("INS_ROOT");
1211 if (evar != NULL)
1212 {
1213 sprintf(dataPath_, "%s/", evar);
1214 evar = getenv("INS_USER");
1215 if (evar != NULL) strcat(dataPath_, evar);
1216 else strcat(dataPath_, "SYSTEM");
1217 strcat(dataPath_, "/DETDATA");
1218 }
1219 else
1220 {
1221 evar = getenv("DATAROOT");
1222 if (evar != NULL)
1223 {
1224 sprintf(dataPath_, "%s/data", evar);
1225 }
1226 else
1227 {
1228 dataPath_[0] = '\0';
1229 }
1230 }
1231
1232 /*
1233 * Default exposure type
1234 */
1236
1237 /*
1238 * Default format and naming scheme
1239 */
1242 strcpy(baseName, "ngc");
1243 sprintf(path_, "%s/%s", dataPath_, baseName);
1244 extFits = 0;
1245 numExtBlocks = 2;
1246 sequenceNumber = 0;
1247 oneFile = 1;
1248 instLock = 0;
1249 split = 0;
1250 fileName[0] = '\0';
1251 fileCheck = 1;
1252 secure = 1;
1253 tmpFile = 0;
1254 checkFrames = 1;
1255 numFitsExt = 0;
1256 numFiles = 0;
1257
1258 /*
1259 * Exposure parameters
1260 */
1263 expStartTimeMJD_ = 0.0;
1264 expStartTimeUTC_ = 0.0;
1265 expStartTime_[0] = '\0';
1266 time = 0;
1267 integrationTime = 0.0;
1268 id[0] = '\0';
1269 uuid[0] = '\0';
1270 rev = 1;
1271 merge = 0;
1272 startTime.tv_sec = 0;
1273 startTime.tv_usec = 0;
1274 strcpy(origin, "ESO-PARANAL");
1275 endFlag_ = 0;
1276
1277 /*
1278 * For file sharing between multiple instances
1279 */
1280 nopen = 0;
1281 fd = NULL;
1282 fdList = NULL;
1283
1284 /*
1285 * Socket pair for internal event-communication
1286 */
1287 if (ngcbSocketPair(pipe_, 16384, NULL) != 0)
1288 {
1289 pipe_[0] = -1; pipe_[1] = -1;
1290 }
1291 fdIn_ = pipe_[0]; fdOut_ = pipe_[1];
1292
1293 /*
1294 * Protection semaphore for multiple instances
1295 */
1296 semExpEvt_ = new ngcbSEMC(1);
1297 semExpSync_ = new ngcbSEMC(0);
1298 numInst_ = 1;
1299
1300 /*
1301 * Signal semaphore for EVH lock
1302 */
1303 useLock = 0;
1304 semExpLock_ = new ngcbSEMC(0);
1305 lockCancelled_ = 0;
1306 skipLock_ = 0;
1307
1308 /*
1309 * Instance management
1310 */
1311 instanceList_ = 0;
1312 lastTransferList_ = 0;
1313 abortList_ = 0;
1314
1315 /*
1316 * Clear error message
1317 */
1318 erms_[0] = '\0';
1319
1320 /*
1321 * Exposure driver
1322 */
1323 memset(drvStatusName, 0, sizeof(drvStatusName));
1324 memset(drvMsg, 0, sizeof(drvMsg));
1326 }
1327
1329 void CkFdOut_() {
1330 if ((fdOut_ >= 0) && (fdOut_ == pipe_[1]))
1331 {
1332 close(pipe_[1]); pipe_[1] = -1; fdOut_ = -1;
1333 }
1334 }
1335};
1336
1337#endif
Definition ngcbFITS.hpp:24
Definition ngcbTHREAD.hpp:67
int naming
Naming scheme.
Definition ngcdcsEXP.hpp:229
char uuid[48]
Unique ID.
Definition ngcdcsEXP.hpp:244
int EndFlag()
Get end-flag.
Definition ngcdcsEXP.hpp:1121
int Naming(int newNaming)
Set naming scheme.
Definition ngcdcsEXP.hpp:842
void Detach()
Remove all instances from instance-management lists.
Definition ngcdcsEXP.hpp:428
const char * Path()
Get full path to base name.
Definition ngcdcsEXP.hpp:971
int StatusFdIn()
Get incoming file descriptor.
Definition ngcdcsEXP.hpp:365
void Attach(int inst)
Add instance to instance-management lists.
Definition ngcdcsEXP.hpp:422
virtual ~ngcdcsEXP()
Destructor.
Definition ngcdcsEXP.hpp:328
char * ErrMsg()
Return a pointer to the actual error message.
Definition ngcdcsEXP.hpp:675
void ResetInstLock()
Reset synchronous instance locking.
Definition ngcdcsEXP.hpp:380
int extFits
Flag for extended FITS header.
Definition ngcdcsEXP.hpp:181
int tmpFile
Store tmeporary file.
Definition ngcdcsEXP.hpp:265
int RecvEvt(ngcdcs_expevt_t *evt)
Receive status event.
Definition ngcdcsEXP.hpp:510
unsigned int statusSaved
Saved exposure status.
Definition ngcdcsEXP.hpp:223
int DataPath(const char *path)
Set data path.
Definition ngcdcsEXP.hpp:863
double ExpStartTimeMJD()
Get exposure start time (MJD)
Definition ngcdcsEXP.hpp:1092
void ApplLocked()
Signal that application is locked.
Definition ngcdcsEXP.hpp:625
void InitInstLock(int n)
Initialize synchronous instance locking.
Definition ngcdcsEXP.hpp:385
void Stat2Str(char *s, unsigned int stat)
Map status to string.
Definition ngcdcsEXP.hpp:1051
void ResetFd()
Reset in/out file descriptors.
Definition ngcdcsEXP.hpp:362
void TimeStamp()
Generate exposure start time-stamp.
Definition ngcdcsEXP.hpp:1098
void Unlock(int inst)
Synchronous instance unlock with defined order.
Definition ngcdcsEXP.hpp:400
int secure
Secure mode.
Definition ngcdcsEXP.hpp:262
ngcdcsEXP()
Constructor.
Definition ngcdcsEXP.hpp:320
int instLock
Lock instances for guaranteed order.
Definition ngcdcsEXP.hpp:193
int BaseName(const char *name)
Set exposure base name.
Definition ngcdcsEXP.hpp:913
const char * BaseName()
Get exposure base name.
Definition ngcdcsEXP.hpp:963
ngcdcsEXP & operator=(const ngcdcsEXP &other)
Operator =.
Definition ngcdcsEXP.hpp:292
void Lock(int inst)
Synchronous instance lock with defined order.
Definition ngcdcsEXP.hpp:395
int Format(const char *name)
Set exposure data file format (as string)
Definition ngcdcsEXP.hpp:678
void ApplRelease()
Release application lock.
Definition ngcdcsEXP.hpp:628
int sequenceNumber
Sequence number.
Definition ngcdcsEXP.hpp:187
int merge
Merge flag.
Definition ngcdcsEXP.hpp:211
int LastTransfer(int inst)
Check if the given instance is in last-transfer state.
Definition ngcdcsEXP.hpp:442
char fileName[512]
Common file name for this file.
Definition ngcdcsEXP.hpp:199
void SetFdIn(int f)
Set incoming file descriptor.
Definition ngcdcsEXP.hpp:356
int useLock
Flag to use application locking mechanism.
Definition ngcdcsEXP.hpp:256
int Active()
Check if exposure is active.
Definition ngcdcsEXP.hpp:371
ngcbFITS fits
FITS-keyword object.
Definition ngcdcsEXP.hpp:214
ngcdcsEXP(const ngcdcsEXP &other)
Copy constructor.
Definition ngcdcsEXP.hpp:308
void Unlock()
Unlock access to exposure handler.
Definition ngcdcsEXP.hpp:377
const char * FormatNameELT()
Return exposure file format name (ELT)
Definition ngcdcsEXP.hpp:793
int numFiles
Number of files generated during last exposure.
Definition ngcdcsEXP.hpp:274
const char * ExpStartTime()
Get exposure start time (string)
Definition ngcdcsEXP.hpp:1089
void Detach(int inst)
Remove instance from instance-management lists.
Definition ngcdcsEXP.hpp:435
int ApplSkip()
Skip locking message.
Definition ngcdcsEXP.hpp:662
struct timeval startTime
Start time-stamp.
Definition ngcdcsEXP.hpp:277
unsigned int drvStatus
Exposure driver status.
Definition ngcdcsEXP.hpp:280
void DrvStatus(unsigned int stat)
Update exposure sequence driver status.
Definition ngcdcsEXP.hpp:1108
ngcbFITS appHdr
FITS-keyword object for application specific extension.
Definition ngcdcsEXP.hpp:217
int NextIndex()
Create next exposure sequence index.
Definition ngcdcsEXP.hpp:1010
int format
Data file format.
Definition ngcdcsEXP.hpp:226
int numFitsExt
Number of FITS-extensions generated during last exposure.
Definition ngcdcsEXP.hpp:271
int LastTransfer()
Check if all attached (active) instances are in last-transfer state.
Definition ngcdcsEXP.hpp:445
char lastName[256+16]
Last base name incl. sequence number.
Definition ngcdcsEXP.hpp:238
int split
Split glued images into extensions.
Definition ngcdcsEXP.hpp:196
char * DataPath()
Return data path.
Definition ngcdcsEXP.hpp:910
int Aborted()
Definition ngcdcsEXP.hpp:457
void AssignUUID(const char *value)
Assign UUID.
Definition ngcdcsEXP.hpp:966
int expType
Exposure type.
Definition ngcdcsEXP.hpp:259
int WaitApplLocked()
Wait until application is locked.
Definition ngcdcsEXP.hpp:606
void StatStr(char *s)
Get status string.
Definition ngcdcsEXP.hpp:1048
char drvMsg[256]
Exposure driver status message.
Definition ngcdcsEXP.hpp:286
void ExpStartTime(struct timeval &timeVal)
Set exposure start time.
Definition ngcdcsEXP.hpp:1073
double ExpStartTimeUTC()
Get exposure start time (UTC seconds since midnight)
Definition ngcdcsEXP.hpp:1095
void EndFlag(int flag)
Set/clear end-flag.
Definition ngcdcsEXP.hpp:1114
int fileCheck
Check file permissions.
Definition ngcdcsEXP.hpp:253
char drvStatusName[32]
Exposure driver status name.
Definition ngcdcsEXP.hpp:283
int Attached()
Definition ngcdcsEXP.hpp:451
int time
Estimation for exposure time.
Definition ngcdcsEXP.hpp:232
FILE * fdList
List file descriptor.
Definition ngcdcsEXP.hpp:205
const char * TmpPath()
Get tmp-file path.
Definition ngcdcsEXP.hpp:1003
char origin[80]
ORIGIN keyword.
Definition ngcdcsEXP.hpp:289
double integrationTime
Integration time (for FITS header EXPTIME)
Definition ngcdcsEXP.hpp:250
int IssueEvt(ngcdcs_expevt_t evt)
Issue status event.
Definition ngcdcsEXP.hpp:460
int Format(int newFormat)
Set exposure data file format.
Definition ngcdcsEXP.hpp:721
char baseName[256]
Base name.
Definition ngcdcsEXP.hpp:235
int Naming()
Return naming scheme.
Definition ngcdcsEXP.hpp:860
int rev
Exposure handling revision.
Definition ngcdcsEXP.hpp:247
int Format()
Return exposure file format.
Definition ngcdcsEXP.hpp:741
unsigned int status
Exposure status.
Definition ngcdcsEXP.hpp:220
void Lock()
Lock access to exposure handler.
Definition ngcdcsEXP.hpp:374
int oneFile
All in one file ("Extension" format only)
Definition ngcdcsEXP.hpp:190
void Release()
Release exposure handler locking.
Definition ngcdcsEXP.hpp:411
int nopen
Counts how many objects access this file.
Definition ngcdcsEXP.hpp:208
void SetFdOut(int f)
Set outgoing file descriptor.
Definition ngcdcsEXP.hpp:359
void ApplClear()
Clear application lock.
Definition ngcdcsEXP.hpp:642
int checkFrames
Check frame selection at exposure start.
Definition ngcdcsEXP.hpp:268
const char * FormatName()
Return exposure file format name.
Definition ngcdcsEXP.hpp:744
FILE * fd
Shared file descriptor.
Definition ngcdcsEXP.hpp:202
int numExtBlocks
Number of extension header blocks to be reserved.
Definition ngcdcsEXP.hpp:184
int ApplCancelled()
Check if application lock was cancelled.
Definition ngcdcsEXP.hpp:653
int StatusFdOut()
Get outgoing file descriptor.
Definition ngcdcsEXP.hpp:368
int ngcbSocketPair(int fd[2], int bufferSize, char *erms)
Definition ngcbSocket.c:321
int ngcbWritePerm(const char *path)
Definition ngcbFile.c:447
int ngcbFindIndex(const char *path, int minIndex, char *erms)
Definition ngcbFile.c:656
#define str2str(s1, s2, n)
Definition ngcb.h:73
void ngcbTime2UTC(struct timeval t, char *utc, int precision)
Definition ngcbTime.c:156
void ngcbParentDir(char *path, const char *fileName)
Definition ngcbFile.c:334
int ngcbIsDir(const char *path)
Definition ngcbFile.c:433
int ngcbGetTime(struct timeval *t)
Definition ngcbTime.c:40
double ngcbTime2MJD(struct timeval t)
Definition ngcbTime.c:194
#define ngcbSUCCESS
Definition ngcb.h:137
#define ngcbFAILURE
Definition ngcb.h:139
#define ngcdcsEXP_STARTING
Definition ngcdcsEXP.hpp:46
#define ngcdcsEXP_FORMAT_CUBE_EXT
Definition ngcdcsEXP.hpp:72
#define ngcdcsEXP_PENDING
Definition ngcdcsEXP.hpp:32
#define ngcdcsEXP_ACTIVE(status)
Definition ngcdcsEXP.hpp:56
#define ngcdcsEXP_FORMAT_CUBE
Definition ngcdcsEXP.hpp:69
#define ngcdcsEXP_COMPL_STOPPED
Definition ngcdcsEXP.hpp:41
#define ngcdcsEXP_SUSTAINED
Definition ngcdcsEXP.hpp:62
#define ngcdcsEXP_FORMAT_GENERIC_1
Definition ngcdcsEXP.hpp:73
#define ngcdcsEXP_NONE
Definition ngcdcsEXP.hpp:30
#define ngcdcsEXP_MAX_CLIENTS
Definition ngcdcsEXP.hpp:88
#define ngcdcsEXP_NAMING_SEQUENCE
Definition ngcdcsEXP.hpp:80
#define ngcdcsEXP_EVT_IMG
Definition ngcdcsEXP.hpp:93
#define ngcdcsEXP_NAMING_REQUEST
Definition ngcdcsEXP.hpp:79
#define ngcdcsEXP_FORMAT_SINGLE_EXT
Definition ngcdcsEXP.hpp:71
#define ngcdcsEXP_PROCESSING
Definition ngcdcsEXP.hpp:36
#define ngcdcsEXP_COMPL_FAILURE
Definition ngcdcsEXP.hpp:39
#define ngcdcsEXP_COMPL_SUCCESS
Definition ngcdcsEXP.hpp:38
#define ngcdcsEXP_NAMING_REC_ID
Definition ngcdcsEXP.hpp:82
#define ngcdcsEXP_WIPING
Definition ngcdcsEXP.hpp:51
#define ngcdcsEXP_FORMAT_SINGLE
Definition ngcdcsEXP.hpp:68
#define ngcdcsEXP_NAMING_AUTO
Definition ngcdcsEXP.hpp:81
#define ngcdcsEXP_COMPL_ABORTED
Definition ngcdcsEXP.hpp:40
#define ngcdcsEXP_FORMAT_EXTENSION
Definition ngcdcsEXP.hpp:70
#define ngcdcsEXP_PAUSED
Definition ngcdcsEXP.hpp:34
#define ngcdcsEXP_INTEGRATING
Definition ngcdcsEXP.hpp:33
#define ngcdcsEXP_NAMING_AUTO_ID
Definition ngcdcsEXP.hpp:83
#define ngcdcsEXP_TRANSFERRING
Definition ngcdcsEXP.hpp:37
#define ngcdcsEXP_READING
Definition ngcdcsEXP.hpp:35
#define ngcdcsEXP_FORMAT_GENERIC_2
Definition ngcdcsEXP.hpp:74
#define ngcdcsEXP_INACTIVE
Definition ngcdcsEXP.hpp:31
Definition ngcdcsEXP.hpp:102
double ts
Definition ngcdcsEXP.hpp:106
float offsetY
Definition ngcdcsEXP.hpp:104
float offsetX
Definition ngcdcsEXP.hpp:103
float quality
Definition ngcdcsEXP.hpp:105
char status[32]
Definition ngcdcsEXP.hpp:145
char id[64]
Definition ngcdcsEXP.hpp:142
char host[64]
Definition ngcdcsEXP.hpp:143
int method
Definition ngcdcsEXP.hpp:146
char fileName[256]
Definition ngcdcsEXP.hpp:144
ngcdcs_exp_topic()
Constructor.
Definition ngcdcsEXP.hpp:168
ngcdcs_exp_topic(const ngcdcs_exp_topic &other)
Copy constructor.
Definition ngcdcsEXP.hpp:159
ngcdcs_exp_topic & operator=(const ngcdcs_exp_topic &other)
Operator =.
Definition ngcdcsEXP.hpp:149
Definition ngcdcsEXP.hpp:112
int instance
Definition ngcdcsEXP.hpp:114
ngcdcs_2ag_t ag
Definition ngcdcsEXP.hpp:120
int tag
Definition ngcdcsEXP.hpp:113
int errorId
Definition ngcdcsEXP.hpp:117
int ioError
Definition ngcdcsEXP.hpp:118
int merge
Definition ngcdcsEXP.hpp:115
ngcdcs_expevt_t()
Constructor.
Definition ngcdcsEXP.hpp:123
char msg[1024]
Definition ngcdcsEXP.hpp:119
unsigned int status
Definition ngcdcsEXP.hpp:116