Jpp
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)
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
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
JException.hh
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JTRIGGER::JDOMToPMTMaskMap::read
virtual JReader & read(JReader &in)
Read from input.
Definition: JDOMToPMTMaskMap.hh:86
JTRIGGER::JDOMToPMTMaskMap::write
virtual JWriter & write(JWriter &out) const
Write to output.
Definition: JDOMToPMTMaskMap.hh:111
JIO::JSerialisable
Forward declaration of binary output.
Definition: JSerialisable.hh:31
JTRIGGER::JDOMToPMTMaskMap
Definition: JDOMToPMTMaskMap.hh:29
JDETECTOR::JModuleIdentifier
JLANG::JObjectID JModuleIdentifier
Definition: JModuleIdentifier.hh:16
JTOOLS::n
const int n
Definition: JPolint.hh:628
JModuleIdentifier.hh
JTRIGGER::JDOMToPMTMaskMap::getPMTMask
const JPMTMask & getPMTMask(const JModuleIdentifier &id)
Definition: JDOMToPMTMaskMap.hh:40
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JSerialisable.hh
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JTRIGGER::JDOMToPMTMaskMap::operator<<
friend std::ostream & operator<<(std::ostream &out, const JDOMToPMTMaskMap &masks)
Definition: JDOMToPMTMaskMap.hh:70
std::map
Definition: JSTDTypes.hh:16
JTRIGGER::JDOMToPMTMaskMap::operator>>
friend std::istream & operator>>(std::istream &in, JDOMToPMTMaskMap &masks)
Definition: JDOMToPMTMaskMap.hh:46
map
const char * map
Definition: elog.cc:87
std
Definition: jaanetDictionary.h:36
JTRIGGER::JPMTMask
Auxiliary class for pmt mask.
Definition: JPMTMask.hh:57
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35
JTRIGGER::JDOMToPMTMaskMap::JDOMToPMTMaskMap
JDOMToPMTMaskMap()
Definition: JDOMToPMTMaskMap.hh:35
JPMTMask.hh
JLANG::JException
General exception.
Definition: JException.hh:40