PAASS
Software suite to Acquire and Analyze Data from Pixie16
poll2_core.h
Go to the documentation of this file.
1 
18 #ifndef POLL2_CORE_H
19 #define POLL2_CORE_H
20 
21 #include <vector>
22 
23 #include "PixieInterface.h"
24 #include "hribf_buffers.h"
25 #define maxEventSize 4095 // (0x1FFE0000 >> 17)
26 
27 #define POLL2_CORE_VERSION "1.4.14"
28 #define POLL2_CORE_DATE "Aug. 17th, 2016"
29 
30 // Maximum length of UDP data packet (in bytes)
31 #define MAX_ORPH_DATA 1464
32 
35 
36 class MCA;
37 
38 class MCA_args{
39  private:
40  bool running;
41  bool useRoot;
42  int totalTime;
43  std::string basename;
44 
45  MCA *mca;
46 
47  public:
48  MCA_args();
49 
50  MCA_args(bool useRoot_, int totalTime_, std::string basename_);
51 
52  ~MCA_args();
53 
54  bool IsRunning(){ return running; }
55 
56  bool UseRoot(){ return useRoot; }
57 
58  int GetTotalTime(){ return totalTime; }
59 
60  std::string GetBasename(){ return basename; }
61 
62  MCA *GetMCA(){ return mca; }
63 
64  void SetUseRoot(bool state_=true){ useRoot = state_; }
65 
66  void SetTotalTime(int totalTime_){ totalTime = totalTime_; }
67 
68  void SetBasename(std::string basename_){ basename = basename_; }
69 
70  bool Initialize(PixieInterface *pif_);
71 
72  bool Step();
73 
74  bool CheckTime();
75 
76  void Zero();
77 
78  void Close(PixieInterface *pif_);
79 };
80 
81 struct UDP_Packet {
82  int Sequence;
83  int DataSize;
84  unsigned char Data[MAX_ORPH_DATA];
85 };
86 
87 struct data_pack{
88  int Sequence;
89  int DataSize;
91  unsigned short Events;
92  unsigned short Cont;
93  unsigned char Data[4*(4050 + 4)];
94  int BufLen;
95 };
96 
97 // Forward class declarations
98 class StatsHandler;
99 class Client;
100 class Server;
101 class Terminal;
102 
103 class Poll{
104  private:
107  std::vector<word_t> *partialEvents;
108 
109  double startTime;
110  double lastSpillTime;
111 
112  struct tm *time_info;
113 
116 
118 
119  // System flags and variables
120  std::string sys_message_head;
121  bool kill_all;
123  bool do_stop_acq;
124  bool record_data;
125  bool do_reboot;
126  bool force_spill;
127  bool acq_running;
129  bool had_error;
130  bool file_open;
131  time_t raw_time;
132 
133  // System MCA flags
134  bool do_MCA_run;
136 
137  // Run control variables
138  bool boot_fast; //
140  bool is_quiet; //
141  bool send_alarm; //
143  bool zero_clocks; //
144  bool debug_mode; //
145  bool shm_mode;
146  bool pac_mode;
147  bool init; //
148  double runTime;
149 
150  // Options relating to output data file
151  std::string output_directory;
152  std::string filename_prefix;
153  std::string output_title;
154  unsigned int next_run_num;
155  unsigned int output_format;
156 
157  // The main output data file and related variables
160 
162  unsigned int udp_sequence;
163  unsigned int total_spill_chunks;
164 
165  size_t n_cards;
166  size_t threshWords;
167 
168  typedef std::pair<unsigned int, unsigned int> chanid_t;
169  std::map<chanid_t, PixieInterface::Histogram> histoMap;
170 
172  static const int statsInterval_ = 3;
173 
174  const static std::vector<std::string> runControlCommands_;
175  const static std::vector<std::string> paramControlCommands_;
176  const static std::vector<std::string> pollStatusCommands_;
177  std::vector<std::string> commands_;
178 
180 
182  void help();
183 
185  void pchan_help();
186 
188  void pmod_help();
189 
191  bool start_run(const bool &record_=true, const double &time_=-1.0);
192 
194  bool stop_run();
195 
197  void show_status();
198 
200  void show_thresh();
201 
203  void get_traces(int mod_, int chan_, int thresh_=0);
204 
206  std::vector<std::string> TabComplete(const std::string &value_, const std::vector<std::string> &valid_);
207 
209  bool ReadFIFO();
210 
212  void ReadScalers();
213 
215  void UpdateStatus();
216 
218  bool synch_mods();
219 
221  std::string get_filename();
222 
224  bool CloseOutputFile(const bool continueRun = false);
225 
227  bool OpenOutputFile(bool continueRun = false);
228 
230  int write_data(word_t *data, unsigned int nWords);
231 
233  void broadcast_data(word_t *data, unsigned int nWords);
234 
236  void broadcast_pac_data();
237 
243  bool SplitParameterArgs(const std::string &arg, int &start, int &stop);
244 
245  public:
247  Poll();
248 
250  ~Poll();
251 
253  bool Initialize();
254 
255  // Set methods.
256  void SetBootFast(bool input_=true){ boot_fast = input_; }
257 
258  void SetWallClock(bool input_=true){ insert_wall_clock = input_; }
259 
260  void SetQuietMode(bool input_=true){ is_quiet = input_; }
261 
262  void SetSendAlarm(bool input_=true){ send_alarm = input_; }
263 
264  void SetShowRates(bool input_=true){ show_module_rates = input_; }
265 
266  void SetZeroClocks(bool input_=true){ zero_clocks = input_; }
267 
268  void SetDebugMode(bool input_=true){ debug_mode = input_; }
269 
270  void SetShmMode(bool input_=true){ shm_mode = input_; }
271 
272  void SetPacmanMode(bool input_=true){ pac_mode = input_; }
273 
274  void SetNcards(const size_t &n_cards_){ n_cards = n_cards_; }
275 
276  void SetThreshWords(const size_t &thresh_){ threshWords = thresh_; }
277 
279  void SetTerminal(Terminal *term){ poll_term_ = term; };
280 
281  // Get methods.
282  bool GetBootFast(){ return boot_fast; }
283 
284  bool GetWallClock(){ return insert_wall_clock; }
285 
286  bool GetQuietMode(){ return is_quiet; }
287 
288  bool GetSendAlarm(){ return send_alarm; }
289 
290  bool GetShowRates(){ return show_module_rates; }
291 
292  bool GetZeroClocks(){ return zero_clocks; }
293 
294  bool GetDebugMode(){ return debug_mode; }
295 
296  bool GetShmMode(){ return shm_mode; }
297 
298  bool GetPacmanMode(){ return pac_mode; }
299 
300  size_t GetNcards(){ return n_cards; }
301 
302  size_t GetThreshWords(){ return threshWords; }
303 
305  void PrintModuleInfo();
306 
308  void CommandControl();
309 
311  void RunControl();
312 
314  bool Close();
315 };
316 
323 bool IsNumeric(const std::string &input_, const std::string &prefix_="", const std::string &msg_="");
324 
326 std::string humanReadable(double size);
327 
329 std::string pad_string(const std::string &input_, unsigned int length_);
330 
332 std::string yesno(bool value_);
333 
334 #endif
bool GetPacmanMode()
Definition: poll2_core.h:298
std::vector< word_t > * partialEvents
A vector to store the partial events.
Definition: poll2_core.h:107
double runTime
Definition: poll2_core.h:148
std::string output_directory
Time to run the acquisition, in seconds.
Definition: poll2_core.h:151
bool file_open
Definition: poll2_core.h:130
Server * server
UDP client for network access.
Definition: poll2_core.h:115
bool Initialize(PixieInterface *pif_)
Definition: poll2_core.cpp:114
static const std::vector< std::string > pollStatusCommands_
Definition: poll2_core.h:176
bool record_data
Set to true when the command is given to stop a run.
Definition: poll2_core.h:124
double startTime
Definition: poll2_core.h:109
std::string sys_message_head
The main pixie interface pointer.
Definition: poll2_core.h:120
int DataSize
Sequence number for reliable transport.
Definition: poll2_core.h:89
int Sequence
Definition: poll2_core.h:82
bool do_reboot
Set to true if data is to be recorded to disk.
Definition: poll2_core.h:125
void help(const char *progName_)
Definition: poll2.cpp:27
StatsHandler * statsHandler
Definition: poll2_core.h:171
bool GetWallClock()
Definition: poll2_core.h:284
std::vector< std::string > commands_
Definition: poll2_core.h:177
PixieInterface * pif
UDP server to listen for pacman commands.
Definition: poll2_core.h:117
int totalTime
Definition: poll2_core.h:42
double lastSpillTime
Time when the acquistion was started.
Definition: poll2_core.h:110
bool insert_wall_clock
Definition: poll2_core.h:139
int DataSize
Sequence number for reliable transport.
Definition: poll2_core.h:83
bool do_start_acq
Set to true when the program is exiting.
Definition: poll2_core.h:122
void SetQuietMode(bool input_=true)
Definition: poll2_core.h:260
bool useRoot
Definition: poll2_core.h:41
void SetThreshWords(const size_t &thresh_)
Definition: poll2_core.h:276
void SetNcards(const size_t &n_cards_)
Definition: poll2_core.h:274
bool GetDebugMode()
Definition: poll2_core.h:294
#define maxEventSize
Definition: poll2_core.h:25
std::map< chanid_t, PixieInterface::Histogram > histoMap
Definition: poll2_core.h:169
bool kill_all
Command line message header.
Definition: poll2_core.h:121
bool do_stop_acq
Set to true when the command is given to start a run.
Definition: poll2_core.h:123
MCA * GetMCA()
Definition: poll2_core.h:62
bool IsNumeric(const std::string &input_, const std::string &prefix_="", const std::string &msg_="")
Definition: poll2_core.cpp:67
void SetUseRoot(bool state_=true)
Definition: poll2_core.h:64
std::string basename
Definition: poll2_core.h:43
unsigned int total_spill_chunks
Total number of poll data spill chunks sent over the network.
Definition: poll2_core.h:163
Abstract MCA class.
Definition: MCA.h:11
void SetDebugMode(bool input_=true)
Definition: poll2_core.h:268
void SetSendAlarm(bool input_=true)
Definition: poll2_core.h:262
static const std::vector< std::string > runControlCommands_
Definition: poll2_core.h:174
bool acq_running
Force poll2 to dump the current data spill.
Definition: poll2_core.h:127
void SetTotalTime(int totalTime_)
Definition: poll2_core.h:66
bool do_MCA_run
Definition: poll2_core.h:134
bool shm_mode
Definition: poll2_core.h:145
unsigned int next_run_num
Set with &#39;htit&#39; command.
Definition: poll2_core.h:154
unsigned int udp_sequence
Pacman related variables.
Definition: poll2_core.h:162
std::string pad_string(const std::string &input_, unsigned int length_)
Pad a string with periods until it is the specified length_.
void SetWallClock(bool input_=true)
Definition: poll2_core.h:258
MCA * mca
Definition: poll2_core.h:45
size_t GetThreshWords()
Definition: poll2_core.h:302
std::pair< unsigned int, unsigned int > chanid_t
Definition: poll2_core.h:168
bool GetZeroClocks()
Definition: poll2_core.h:292
bool GetSendAlarm()
Definition: poll2_core.h:288
bool debug_mode
Definition: poll2_core.h:144
static const std::vector< std::string > paramControlCommands_
Definition: poll2_core.h:175
size_t threshWords
Definition: poll2_core.h:166
Client * client
Definition: poll2_core.h:114
void SetShowRates(bool input_=true)
Definition: poll2_core.h:264
void Zero()
Definition: poll2_core.cpp:151
int GetTotalTime()
Definition: poll2_core.h:58
bool init
Pacman shared-memory mode.
Definition: poll2_core.h:147
size_t n_cards
Definition: poll2_core.h:165
bool had_error
Set to true when run_command exits.
Definition: poll2_core.h:129
int BufLen
The data to be transmitted.
Definition: poll2_core.h:94
int Sequence
Definition: poll2_core.h:88
MCA_args mca_args
Set to true when the "mca" command is received.
Definition: poll2_core.h:135
bool CheckTime()
Definition: poll2_core.cpp:146
bool show_module_rates
Definition: poll2_core.h:142
bool GetBootFast()
Definition: poll2_core.h:282
bool running
Definition: poll2_core.h:40
#define MAX_ORPH_DATA
Definition: poll2_core.h:31
bool force_spill
Set to true when the user tells POLL to reboot PIXIE.
Definition: poll2_core.h:126
PixieInterface::word_t word_t
Definition: poll2_core.h:33
size_t GetNcards()
Definition: poll2_core.h:300
void SetBootFast(bool input_=true)
Definition: poll2_core.h:256
void SetZeroClocks(bool input_=true)
Definition: poll2_core.h:266
bool pac_mode
New style shared-memory mode.
Definition: poll2_core.h:146
PollOutputFile output_file
Definition: poll2_core.h:159
std::string output_title
Set with &#39;ouf&#39; command.
Definition: poll2_core.h:153
bool run_ctrl_exit
Set to true when run_command is recieving data from PIXIE.
Definition: poll2_core.h:128
bool GetQuietMode()
Definition: poll2_core.h:286
bool zero_clocks
Definition: poll2_core.h:143
bool Step()
Definition: poll2_core.cpp:141
void SetPacmanMode(bool input_=true)
Definition: poll2_core.h:272
void SetBasename(std::string basename_)
Definition: poll2_core.h:68
Terminal * poll_term_
Definition: poll2_core.h:105
word_t eventdata_t[maxEventSize]
Definition: poll2_core.h:34
time_t raw_time
Definition: poll2_core.h:131
int TotalEvents
Number of useable bytes in Data.
Definition: poll2_core.h:90
std::string yesno(bool value_)
Return a string containing "yes" for value_==true and "no" for value_==false.
std::string GetBasename()
Definition: poll2_core.h:60
bool UseRoot()
Definition: poll2_core.h:56
bool GetShowRates()
Definition: poll2_core.h:290
unsigned int output_format
Set with &#39;hnum&#39; command.
Definition: poll2_core.h:155
bool send_alarm
Definition: poll2_core.h:141
Handles poll2 output data files.
void Close(PixieInterface *pif_)
Definition: poll2_core.cpp:163
std::string filename_prefix
Set with &#39;fdir&#39; command.
Definition: poll2_core.h:152
data_pack AcqBuf
Definition: poll2_core.h:179
bool IsRunning()
Definition: poll2_core.h:54
unsigned short Events
Total number of events.
Definition: poll2_core.h:91
std::string humanReadable(double size)
Convert a rate number to more useful form.
void SetShmMode(bool input_=true)
Definition: poll2_core.h:270
int current_file_num
Set with &#39;oform&#39; command.
Definition: poll2_core.h:158
unsigned short Cont
Number of events in this packet.
Definition: poll2_core.h:92
void SetTerminal(Terminal *term)
Set the terminal pointer.
Definition: poll2_core.h:279
bool boot_fast
Structure to hold arguments for MCA program.
Definition: poll2_core.h:138
bool GetShmMode()
Definition: poll2_core.h:296
struct tm * time_info
Time when the last spill finished.
Definition: poll2_core.h:112
bool is_quiet
Definition: poll2_core.h:140