Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEmitterID.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JEMITTERID__
2 #define __JACOUSTICS__JEMITTERID__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <map>
8 
9 #include "JSystem/JStat.hh"
10 
11 #include "JLang/JStringStream.hh"
12 #include "JLang/JException.hh"
13 
14 #include "Jeep/JComment.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Emitter identification.
21  * \author mdejong
22  */
23 namespace JACOUSTICS {}
24 namespace JPP { using namespace JACOUSTICS; }
25 
26 namespace JACOUSTICS {
27 
29  using JEEP::JComment;
30 
31 
32  /**
33  * Auxiliary class for emitter identification.
34  *
35  * This class can be used to map the identfier of a waveform
36  * (i.e.\ column "EMITTERID" the database table "toashort" or JDATABASE::JToAshort::EMITTERID)
37  * to the identifier of the corresponding emitter (c.q.\ tripod).
38  */
39  struct JEmitterID :
40  public std::map<int, int>
41  {
42  /**
43  * Get emitter identifier for given waveform identifier.
44  *
45  * \param id waveform identifier
46  * \return emitter identifier
47  */
48  int operator()(const int id) const
49  {
50  const_iterator p = this->find(id);
51 
52  if (p != this->end())
53  return p->second;
54  else
55  THROW(JValueOutOfRange, "Invalid waveform identifier " << id);
56  }
57 
58 
59  /**
60  * Read emitter data from input.
61  *
62  * \param in input stream
63  * \param object emitter data
64  * \return input stream
65  */
66  friend inline std::istream& operator>>(std::istream& in, JEmitterID& object)
67  {
68  using namespace JPP;
69 
70  JStringStream is(in);
71 
72  if (getFileStatus(is.str().c_str())) {
73  is.load();
74  }
75 
76  object.clear();
77 
78  is >> object.comment;
79 
80  int waveform;
81  int emitter;
82 
83  while (is >> waveform >> emitter) {
84  object[waveform] = emitter;
85  }
86 
87  return in;
88  }
89 
90 
91  /**
92  * Write emitter data to output.
93  *
94  * \param out output stream
95  * \param object emitter data
96  * \return output stream
97  */
98  friend inline std::ostream& operator<<(std::ostream& out, const JEmitterID& object)
99  {
100  using namespace std;
101 
102  out << object.comment;
103 
104  for (JEmitterID::const_iterator i = object.begin(); i != object.end(); ++i) {
105  out << setw(3) << i->first << ' ' << setw(2) << i->second << endl;
106  }
107 
108  return out;
109  }
110 
111 
113  };
114 
115 
116  /**
117  * Function object for emitter identification.
118  */
120 }
121 
122 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
Auxiliary class for emitter identification.
Definition: JEmitterID.hh:39
is
Definition: JDAQCHSM.chsm:167
friend std::ostream & operator<<(std::ostream &out, const JEmitterID &object)
Write emitter data to output.
Definition: JEmitterID.hh:98
int operator()(const int id) const
Get emitter identifier for given waveform identifier.
Definition: JEmitterID.hh:48
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
friend std::istream & operator>>(std::istream &in, JEmitterID &object)
Read emitter data from input.
Definition: JEmitterID.hh:66
Auxiliary class for comment.
Definition: JComment.hh:41
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
static JEmitterID getEmitterID
Function object for emitter identification.
Definition: JEmitterID.hh:119
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
File status.