Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JCALIBRATE::JTDC_t Struct Reference

Auxiliary class for TDC constraints. More...

#include <JTDC_t.hh>

Inheritance diagram for JCALIBRATE::JTDC_t:
std::multimap< int, int >

Public Types

enum  { WILDCARD = -1 }
 Wild card for module identifier and TDC. More...
 
typedef std::multimap< int, int > multimap_type
 
typedef std::pair< const_iterator, const_iterator > range_type
 Type definition for range of TDC constraints of a given module identfier.
 

Public Member Functions

void insert (const value_type &value)
 Insert constraint.
 
void insert (const int id, const int tdc)
 Insert constraint.
 
range_type equal_range (const int id)
 Get range of constraints for given module.
 
bool has (const int id, const int tdc)
 Check if TDC is constraint.
 
void reverse ()
 Reverse constraints.
 
bool is_valid (const bool option=false) const
 Check validity of TDC constrants.
 

Public Attributes

JComment comment
 

Friends

std::istream & operator>> (std::istream &in, JTDC_t &tdc)
 Read TDC constraints from input.
 
std::ostream & operator<< (std::ostream &out, const JTDC_t &tdc)
 Write TDC constraints to output.
 

Detailed Description

Auxiliary class for TDC constraints.

Definition at line 36 of file JTDC_t.hh.

Member Typedef Documentation

◆ multimap_type

Definition at line 39 of file JTDC_t.hh.

◆ range_type

std::pair<const_iterator, const_iterator> JCALIBRATE::JTDC_t::range_type

Type definition for range of TDC constraints of a given module identfier.

Definition at line 44 of file JTDC_t.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Wild card for module identifier and TDC.

Enumerator
WILDCARD 

Definition at line 50 of file JTDC_t.hh.

50{ WILDCARD = -1 };

Member Function Documentation

◆ insert() [1/2]

void JCALIBRATE::JTDC_t::insert ( const value_type & value)
inline

Insert constraint.

Note that if TDC equals JTDC_t::WILDCARD, all possible TDCs in the given module are inserted.

Parameters
valuemodule identifier and TDC

Definition at line 61 of file JTDC_t.hh.

62 {
63 if (value.second == WILDCARD) {
64
65 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
66 multimap_type::insert(value_type(value.first, pmt));
67 }
68
69 } else {
70
71 multimap_type::insert(value);
72 }
73 }

◆ insert() [2/2]

void JCALIBRATE::JTDC_t::insert ( const int id,
const int tdc )
inline

Insert constraint.

Note that if TDC equals JTDC_t::WILDCARD, all possible TDCs in the given module are inserted.

Parameters
idmodule identifier
tdcTDC

Definition at line 85 of file JTDC_t.hh.

86 {
87 this->insert(value_type(id, tdc));
88 }
void insert(const value_type &value)
Insert constraint.
Definition JTDC_t.hh:61

◆ equal_range()

range_type JCALIBRATE::JTDC_t::equal_range ( const int id)
inline

Get range of constraints for given module.

Note that if no data are available for given module identifier, the data corresponding to JTDC_t::WILDCARD are returned.

Parameters
idmodule identifier
Returns
range of constraints

Definition at line 100 of file JTDC_t.hh.

101 {
102 range_type range = multimap_type::equal_range(id);
103
104 if (range.first == range.second) {
105 range = multimap_type::equal_range(WILDCARD);
106 }
107
108 return range;
109 }
std::pair< const_iterator, const_iterator > range_type
Type definition for range of TDC constraints of a given module identfier.
Definition JTDC_t.hh:44

◆ has()

bool JCALIBRATE::JTDC_t::has ( const int id,
const int tdc )
inline

Check if TDC is constraint.

Parameters
idmodule identifier
tdcTDC channel
Returns
true if given TDC is constraint; else false

Definition at line 119 of file JTDC_t.hh.

120 {
121 const range_type range = equal_range(id);
122
123 for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) {
124 if (tdc == i->second) {
125 return true;
126 }
127 }
128
129 return false;
130 }
range_type equal_range(const int id)
Get range of constraints for given module.
Definition JTDC_t.hh:100

◆ reverse()

void JCALIBRATE::JTDC_t::reverse ( )
inline

Reverse constraints.

Definition at line 136 of file JTDC_t.hh.

137 {
138 JTDC_t buffer;
139
140 for (JTDC_t::const_iterator p = this->begin(); p != this->end(); ) {
141
142 JTDC_t::const_iterator q = p;
143
144 for ( ; q != this->end() && q->first == p->first; ++q) {}
145
146 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
147
148 JTDC_t::const_iterator i = p;
149
150 for ( ; i != q && i->second != pmt; ++i) {}
151
152 if (i == q) {
153 buffer.insert(value_type(p->first, pmt));
154 }
155 }
156
157 p = q;
158 }
159
160 this->swap(buffer);
161 }

◆ is_valid()

bool JCALIBRATE::JTDC_t::is_valid ( const bool option = false) const
inline

Check validity of TDC constrants.

Parameters
optionoption (if true, throw exception if not valid)
Returns
true if valid; else false

Definition at line 170 of file JTDC_t.hh.

171 {
172 for (const_iterator i = this->begin(); i != this->end(); ++i) {
173
174 if (i->first < WILDCARD) {
175
176 if (option) {
177 THROW(JValueOutOfRange, "Invalid module identifier: " << i->first << " < " << WILDCARD);
178 }
179
180 return false;
181 }
182
183 if (i->second < 0 || i->second >= NUMBER_OF_PMTS) {
184
185 if (option) {
186 THROW(JValueOutOfRange, "Invalid TDC: " << i->second << " {0, .., " << NUMBER_OF_PMTS - 1 << "}");
187 }
188
189 return false;
190 }
191 }
192
193 return true;
194 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JTDC_t & tdc )
friend

Read TDC constraints from input.

Parameters
ininput stream
tdcTDC constraints
Returns
input stream

Definition at line 204 of file JTDC_t.hh.

205 {
206 using namespace std;
207 using namespace JPP;
208
209 JStringStream is(in);
210
211 is >> tdc.comment;
212
213 for (int id, pmt; is >> id >> pmt; ) {
214 tdc.insert(JTDC_t::value_type(id, pmt));
215 }
216
217 return in;
218 }
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JTDC_t & tdc )
friend

Write TDC constraints to output.

Parameters
outoutput stream
tdcTDC constraints
Returns
output stream

Definition at line 228 of file JTDC_t.hh.

229 {
230 using namespace std;
231
232 out << tdc.comment;
233
234 for (JTDC_t::const_iterator i = tdc.begin(); i != tdc.end(); ++i) {
235 out << setw(10) << i->first << ' ' << setw(2) << i->second << endl;
236 }
237
238 return out;
239 }

Member Data Documentation

◆ comment

JComment JCALIBRATE::JTDC_t::comment

Definition at line 241 of file JTDC_t.hh.


The documentation for this struct was generated from the following file: