Jpp
 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 <map>
7 
8 #include "JLang/JException.hh"
9 #include "JLang/JSingleton.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 namespace JACOUSTICS {}
16 namespace JPP { using namespace JACOUSTICS; }
17 
18 namespace JACOUSTICS {
19 
20  using JLANG::JSingleton;
22 
23 
24  /**
25  * Auxiliary class for emitter identification.
26  *
27  * This class can be used to map the identfier of a waveform (JDATABASE::JToAshort::EMITTERID /
28  * column "TMITTERID" the database table "toashort")
29  * to the identifier of the corresponding emitter (c.q. tripod).
30  */
31  class JEmitterID :
32  public std::map<int, int>,
33  public JSingleton<JEmitterID>
34  {
35  public:
36  /**
37  * Get emitter identifier for given waveform identifier.
38  *
39  * \param id waveform identifier
40  * \return emitter identifier
41  */
42  int operator()(const int id) const
43  {
44  const_iterator p = this->find(id);
45 
46  if (p != this->end())
47  return p->second;
48  else
49  THROW(JValueOutOfRange, "Invalid waveform identifier " << id);
50  }
51 
52 
53  /**
54  * Configure emitter identification for given detector.
55  *
56  * \param id detector identifier
57  */
58  static void configure(const int id)
59  {
60  getInstance().clear();
61 
62  switch (id) {
63 
64  case 49:
65  getInstance()[ 12] = 1;
66  getInstance()[-13] = 1;
67  getInstance()[ 14] = 2;
68  getInstance()[-15] = 2;
69  getInstance()[ 16] = 3;
70  getInstance()[-17] = 3;
71  break;
72 
73  case 42:
74  getInstance()[ 12] = 1;
75  getInstance()[ 14] = 2;
76  getInstance()[ 16] = 3;
77  break;
78 
79  default:
80  THROW(JValueOutOfRange, "Invalid detector identifier " << id);
81  break;
82  }
83  }
84  };
85 
86 
87  /**
88  * Function object for emitter identification.
89  */
91 }
92 
93 #endif
Exceptions.
Simple singleton class.
Definition: JSingleton.hh:18
static JEmitterID & getEmitterID
Function object for emitter identification.
Definition: JEmitterID.hh:90
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
int operator()(const int id) const
Get emitter identifier for given waveform identifier.
Definition: JEmitterID.hh:42
static void configure(const int id)
Configure emitter identification for given detector.
Definition: JEmitterID.hh:58
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Auxiliary class for emitter identification.
Definition: JEmitterID.hh:31