1 | #ifndef DAQREADOUT_H_SEEN
|
---|
2 | #define DAQREADOUT_H_SEEN
|
---|
3 |
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <stdarg.h>
|
---|
6 | #include <ctype.h>
|
---|
7 | #include <time.h>
|
---|
8 | #include <errno.h>
|
---|
9 | #include <sys/socket.h>
|
---|
10 | #include <pthread.h>
|
---|
11 | #include <fcntl.h>
|
---|
12 | #include <dirent.h>
|
---|
13 | #include <sys/vfs.h>
|
---|
14 | #include <signal.h>
|
---|
15 |
|
---|
16 | #include "RawDataCTX.h"
|
---|
17 | #include "DRS.h"
|
---|
18 | #include "HVFeedback.h"
|
---|
19 |
|
---|
20 | #define RUN_NUM_FILE "/ct3data/LastRunNumber"
|
---|
21 | #define MAX_PATH 256 // also used for filename length
|
---|
22 | #define MAX_COM_SIZE 10000
|
---|
23 | #define MAX_NUM_TOKEN 10
|
---|
24 |
|
---|
25 | #define MsgToConsole 1
|
---|
26 | #define MsgToLog 2
|
---|
27 | #define MsgToSocket 4
|
---|
28 |
|
---|
29 | enum state_enum {active, stopped};
|
---|
30 | enum runtype_enum {data, pedestal, test};
|
---|
31 |
|
---|
32 | class DAQReadout {
|
---|
33 | time_t StartTime;
|
---|
34 | DRS *drs;
|
---|
35 | pthread_t thread_DAQ;
|
---|
36 | unsigned int CmdNumber;
|
---|
37 | FILE *Logfile;
|
---|
38 | void PrintUsage();
|
---|
39 | bool CalibrationRead;
|
---|
40 |
|
---|
41 | public:
|
---|
42 | RunHeader* RHeader;
|
---|
43 | EventHeader* EHeader;
|
---|
44 |
|
---|
45 | short (*WaveForm)[kNumberOfChips][kNumberOfChannels][kNumberOfBins];
|
---|
46 | pthread_mutex_t control_mutex;
|
---|
47 | int Rawfile;
|
---|
48 | class HVFeedback* HVFB;
|
---|
49 | class SlowData *SlowDataClass;
|
---|
50 |
|
---|
51 | // Configuration data
|
---|
52 | char fLogFile[MAX_PATH];
|
---|
53 | unsigned int fMaxLogLines;
|
---|
54 | char fRawDataPath[MAX_PATH];
|
---|
55 | int fMinDiskSpaceMB; // Minimum required disk space in MBytes
|
---|
56 | int fMaxFileSizeMB; // Maximum File size in Bytes
|
---|
57 | unsigned int fFirstSample;
|
---|
58 | unsigned int fLastSample;
|
---|
59 | short fRotateWave;
|
---|
60 | int fCCPort;
|
---|
61 | int fLastVMESlot;
|
---|
62 | int fFirstVMESlot;
|
---|
63 | char fHVFeedbackConfig[MAX_PATH];
|
---|
64 |
|
---|
65 | // Status variables
|
---|
66 | int NParam; // Number of command parameters
|
---|
67 | const char *Param[MAX_NUM_TOKEN]; // Pointers to parameters
|
---|
68 | bool CmdFromSocket; // Current command issued via socket
|
---|
69 | int NumBoards;
|
---|
70 | int FirstBoard;
|
---|
71 | int LastBoard;
|
---|
72 | float *DRSFreq; // DRS sampling frequency [GHz]
|
---|
73 | BoardStructure *BStruct;
|
---|
74 | state_enum daq_state;
|
---|
75 | runtype_enum daq_runtype;
|
---|
76 | int Socket; // -1 if not connected
|
---|
77 | pthread_t *SocketThread; // exit function sends signal to this thread
|
---|
78 | bool Exit;
|
---|
79 | bool Stop; // Set to true to stop run
|
---|
80 | unsigned int NumEvents; // Number of event taken
|
---|
81 | unsigned int NumEventsRequested; // Number of events requested
|
---|
82 | unsigned int RunNumber, FileNumber;
|
---|
83 | char FileName[MAX_PATH];
|
---|
84 | char Prompt[MAX_COM_SIZE];
|
---|
85 |
|
---|
86 | // Public functions
|
---|
87 | DAQReadout(const char*);
|
---|
88 | ~DAQReadout();
|
---|
89 |
|
---|
90 | void cmd_exit(); void cmd_help();
|
---|
91 | void cmd_board(); void cmd_status();
|
---|
92 | void cmd_led(); void cmd_freq();
|
---|
93 | void cmd_calib(); void cmd_serial();
|
---|
94 | void cmd_trigger(); void cmd_delayed();
|
---|
95 | void cmd_wmode(); void cmd_rmode();
|
---|
96 | void cmd_mode(); void cmd_read();
|
---|
97 | void cmd_stop(); void cmd_test();
|
---|
98 | void cmd_regtest(); void cmd_ramtest();
|
---|
99 | void cmd_start(); void cmd_take();
|
---|
100 | void cmd_config(); void cmd_events();
|
---|
101 | void cmd_disk(); void cmd_uptime();
|
---|
102 |
|
---|
103 | void cmd_fmode(); void cmd_faverage();
|
---|
104 | void cmd_ftarget(); void cmd_fgain();
|
---|
105 | void cmd_fresponse(); void cmd_fconfig();
|
---|
106 |
|
---|
107 | void CommandControl(char*);
|
---|
108 | void StartDRS();
|
---|
109 | void StopDRS();
|
---|
110 | void StopRun();
|
---|
111 | bool IsDRSBusy();
|
---|
112 | bool IsDRSFreqSet();
|
---|
113 | void SetDRSFrequency(double, bool);
|
---|
114 | void CalibrateDRS(char*, double, double);
|
---|
115 | void SetDOMINOMode(int);
|
---|
116 | void SetDOMINOReadMode(int);
|
---|
117 | void SetDOMINOWaveMode(int);
|
---|
118 | void SetDelayedStart(int);
|
---|
119 | void HWTrigger(int);
|
---|
120 | bool ReadCalibration();
|
---|
121 | bool IsCalibrationRead();
|
---|
122 | void ReadCalibratedDRSData();
|
---|
123 | void PrintMessage(int, const char*, ...);
|
---|
124 | void PrintMessage(const char*, ...);
|
---|
125 | void PrintMessage(int, const char*, va_list);
|
---|
126 | bool OpenRawFile();
|
---|
127 | bool WriteRunHeader();
|
---|
128 | bool UpdateRunHeader(unsigned int, bool);
|
---|
129 | bool WriteEventHeader();
|
---|
130 | };
|
---|
131 |
|
---|
132 | void DAQ(DAQReadout *);
|
---|
133 | bool Match(const char*, const char*);
|
---|
134 | int ParseInput(char*, const char *Param[]);
|
---|
135 | int CheckDisk(char*);
|
---|
136 | bool ReadCard(const char *, void *, char, FILE *, unsigned int=1);
|
---|
137 |
|
---|
138 | #endif
|
---|