Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDOMToPMTMaskMap.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JDOMTOPMTMASKMAP__
2 #define __JTRIGGER__JDOMTOPMTMASKMAP__
3 
4 #include <istream>
5 #include <ostream>
6 #include <map>
7 
8 #include "JTrigger/JPMTMask.hh"
10 #include "JLang/JException.hh"
11 #include "JIO/JSerialisable.hh"
12 
13 /**
14  * \author rbruijn
15  */
16 
17 namespace JTRIGGER {}
18 namespace JPP { using namespace JTRIGGER; }
19 
20 namespace JTRIGGER {
21 
23  using JLANG::JException;
24  using JIO::JSerialisable;
25  using JIO::JReader;
26  using JIO::JWriter;
27  using JTRIGGER::JPMTMask;
28 
30  public std::map<JModuleIdentifier, JPMTMask>,
31  public JIO::JSerialisable
32  {
33  public:
34 
38  {}
39 
41  {
42  return at(id);
43  }
44 
45 
46  friend inline std::istream& operator>>(std::istream& in, JDOMToPMTMaskMap& masks)
47  {
48  masks.clear();
49 
50  unsigned int n;
51 
52  if(in >> n) {
53 
55  JPMTMask mask;
56 
57  for(; n !=0 && in; --n) {
58 
59  in >> id >>mask;
60 
61  if(!(masks.insert(std::make_pair(id,mask))).second) {
62  throw JException("Key already exists in map.");
63  }
64  }
65  }
66 
67  return in;
68  }
69 
70  friend inline std::ostream& operator<<(std::ostream& out, const JDOMToPMTMaskMap& masks)
71  {
72  using namespace std;
73 
74  out << masks.size();
75  out << endl;
76 
77  for(std::map<JModuleIdentifier, JPMTMask>::const_iterator dommask = masks.begin();
78  dommask!=masks.end();++dommask)
79  {
80  out << dommask->first << ' ' << dommask->second << endl;
81 
82  }
83  return out;
84  }
85 
86  virtual JReader& read(JReader & in) override
87  {
88  clear();
89 
90  unsigned int n;
91 
92  if(in >> n) {
93 
95  JPMTMask mask;
96 
97  for(; n !=0 && in; --n) {
98 
99  in >> id >>mask;
100 
101  if(!(insert(std::make_pair(id,mask))).second) {
102  throw JException("Key already exists in map.");
103  }
104  }
105  }
106 
107  return in;
108  }
109 
110 
111  virtual JWriter& write(JWriter& out) const override
112  {
113  using namespace std;
114 
115  unsigned int n = size();
116 
117  out << n;
118 
119  for(std::map<JModuleIdentifier, JPMTMask>::const_iterator dommask= this->begin();
120  dommask!=this->end(); ++dommask )
121  {
122  out << dommask->first
123  << dommask->second;
124 
125  }
126  return out;
127  }
128 
129 
130  // ClassDef(JDOMToPMTMaskMap,1);
131  };
132 
133 
134  }
135 
136 
137 
138 #endif
friend std::istream & operator>>(std::istream &in, JDOMToPMTMaskMap &masks)
General exception.
Definition: JException.hh:23
virtual JWriter & write(JWriter &out) const override
Write to output.
Exceptions.
Interface for binary output.
friend std::ostream & operator<<(std::ostream &out, const JDOMToPMTMaskMap &masks)
Auxiliary class for PMT mask.
Definition: JPMTMask.hh:56
JLANG::JObjectID JModuleIdentifier
Forward declaration of binary output.
const int n
Definition: JPolint.hh:676
Interface for binary input.
virtual JReader & read(JReader &in) override
Read from input.
const char * map
Definition: elog.cc:87
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
const JPMTMask & getPMTMask(const JModuleIdentifier &id)