Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTimekeeper.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "Jeep/JTimekeeper.hh"
6 #include "JSystem/JTime.hh"
7 
8 #include "Jeep/JPrint.hh"
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 
12 
13 /**
14  * \file
15  * Example program to test JEEP::JTimekeeper class.
16  * \author mdejong
17  */
18 int main(int argc, char* argv[])
19 {
20  using namespace std;
21 
22  int intervalTime_ms;
23  int totalTime_s;
24  int debug;
25 
26  try {
27 
28  JParser<> zap;
29 
30  zap['t'] = make_field(intervalTime_ms) = 100;
31  zap['s'] = make_field(totalTime_s) = 2;
32  zap['d'] = make_field(debug) = 1;
33 
34  zap(argc, argv);
35  }
36  catch(const exception &error) {
37  FATAL(error.what() << endl);
38  }
39 
40 
41  using namespace JPP;
42 
43  if (intervalTime_ms <= 0) { FATAL("interval time [ms] " << intervalTime_ms << " < 0." << endl); }
44  if (totalTime_s <= 0) { FATAL("total time [s] " << totalTime_s << " < 0." << endl); }
45 
46  JFileDescriptorMask mask;
47 
48  cout << "hit <return> to interrupt" << endl;
49 
50  JTimekeeper clock;
51 
52  clock.setInterval(intervalTime_ms * 1000);
53  clock.reset();
54 
55  const long long int t0 = getLocalTime();
56 
57  string buffer;
58  int numberOfInterrupts = 0;
59 
60  for (int i = 0; i < 1000 * totalTime_s / intervalTime_ms; ) {
61 
62  DEBUG(setw(5) << i << rewind);
63 
64  mask.set(STDIN_FILENO); // hit <return> to interrupt wait(..)
65 
66  if (clock.wait(mask)) {
67 
68  getline(cin, buffer); // flush input
69 
70  ++numberOfInterrupts;
71 
72  } else {
73 
74  ++i;
75  }
76  }
77  NOTICE(endl);
78 
79  const long long int t1 = getLocalTime();
80 
81  NOTICE("Number of interrupts " << setw(8) << right << numberOfInterrupts << endl);
82  NOTICE("Total delay [ms] " << setw(8) << right << clock.getDelay() / 1000 << endl);
83  NOTICE("Elapsed time [ms] " << setw(8) << right << (t1 - t0) / 1000 << endl);
84 
85  if (numberOfInterrupts != 0) {
86  NOTICE("Time per interrupt [us] " << setw(8) << right << (t1 - t0 - clock.getDelay()) / numberOfInterrupts << endl);
87  }
88 }
89 
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
std::ostream & rewind(std::ostream &out)
Rewind character.
Definition: JManip.hh:222
Scheduling of actions via fixed latency intervals.
I/O formatting auxiliaries.
static const JLocalTime getLocalTime
Function object to get local time in micro seconds.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
System time information.