Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
examples/JDB/JCompass.cc File Reference

Example program to monitor AHRS data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TGraph.h"
#include "JDB/JAHRS.hh"
#include "JDB/JSupport.hh"
#include "JROOT/JGraph.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JCompass.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JGeometry3D/JDirection3D.hh"
#include "JLang/JComparator.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to monitor AHRS data.

Author
mdejong

Definition in file examples/JDB/JCompass.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 37 of file examples/JDB/JCompass.cc.

38 {
39  using namespace std;
40  using namespace JPP;
41 
43  JLimit_t& numberOfEvents = inputFile.getLimit();
44  string outputFile;
45  string detectorFile;
46  double Tmax_s;
47  size_t numberOfModules;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Example program to monitor AHRS data.");
53 
54  zap['f'] = make_field(inputFile);
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['o'] = make_field(outputFile) = "ahrs.root";
57  zap['a'] = make_field(detectorFile);
58  zap['T'] = make_field(Tmax_s) = 600.0; // [s]
59  zap['N'] = make_field(numberOfModules) = 10;
60  zap['d'] = make_field(debug) = 2;
61 
62  zap(argc, argv);
63  }
64  catch(const exception &error) {
65  FATAL(error.what() << endl);
66  }
67 
69 
70  try {
71  load(detectorFile, detector);
72  }
73  catch(const JException& error) {
74  FATAL(error);
75  }
76 
77  const JModuleRouter router(detector);
78 
79  typedef vector<JAHRS> buffer_type; // data type
80  typedef map<int, buffer_type> map_type; // string -> data
81 
82  map_type data;
83 
84  for (int counter = 0; inputFile.hasNext(); ++counter) {
85 
86  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
87 
88  const JAHRS* parameters = inputFile.next();
89 
90  if (router.hasModule(parameters->DOMID)) {
91 
92  const JLocation location = router.getModule(parameters->DOMID);
93 
94  data[location.getString()].push_back(*parameters);
95  }
96  }
97  STATUS(endl);
98 
99 
102 
103  for (map_type::iterator string = data.begin(); string != data.end(); ++string) {
104 
105  if (!string->second.empty()) {
106 
107  sort(string->second.begin(), string->second.end(), make_comparator(&JAHRS::UNIXTIME));
108 
109  for (buffer_type::const_iterator p = string->second.begin(); p != string->second.end(); ) {
110 
111  set<int> buffer;
112 
113  buffer_type::const_iterator q = p;
114 
115  for ( ; q != string->second.end() && q->UNIXTIME - p->UNIXTIME <= Tmax_s * 1.0e3; ++q) {
116  buffer.insert(q->DOMID);
117  }
118 
119  if (buffer.size() > numberOfModules) {
120 
122 
123  for (buffer_type::const_iterator i = p; i != q; ++i) {
125  }
126 
127  Q.normalise();
128 
129  JDirection3D u(0.0, 0.0, 1.0);
130 
131  u.rotate(Q);
132 
133  const double t1 = p->UNIXTIME * 1.0e-3 + 0.5*Tmax_s;
134 
135  ZO[string->first].put(t1, atan2(u.getDY(), u.getDX()));
136  ZA[string->first].put(t1, sqrt(u.getDX()*u.getDX() + u.getDY()* u.getDY()));
137  }
138 
139  p = q;
140  }
141  }
142  }
143 
144 
145  TFile out(outputFile.c_str(), "recreate");
146 
147  for (map<int, JGraph_t>::const_iterator i = ZO.begin(); i != ZO.end(); ++i) {
148  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].orientation"));
149  }
150 
151  for (map<int, JGraph_t>::const_iterator i = ZA.begin(); i != ZA.end(); ++i) {
152  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].amplitude"));
153  }
154 
155  out.Write();
156  out.Close();
157 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Q(UTCMax_s-UTCMin_s)-livetime_s
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
JQuaternion3D getQuaternion() const
Get quaternion.
Definition: JCompass.hh:201
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Data structure for compass in three dimensions.
Definition: JCompass.hh:49
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
Data structure for unit quaternion in three dimensions.
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
JQuaternion3D & normalise()
Normalise quaternion.
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:739
then usage $script< detector file >< tripodfile >< stage > input file nInput files correspond to the output of JAcousticsEventBuilder[.sh] nFirst stage eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY eval JPrintDetector a $DETECTOR O CAN source JAcoustics sh $DETECTOR_ID typeset A CONFIGURATION for key in Tmax_s