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