~jan.greis/maus/1811

« back to all changes in this revision

Viewing changes to src/common_cpp/Utils/EMRChannelMap.cc

  • Committer: Adam Dobbs
  • Date: 2016-01-13 11:31:12 UTC
  • mfrom: (659.2.18 release-candidate)
  • Revision ID: phuccj@gmail.com-20160113113112-bhbguupn50eyvd0z
Tags: MAUS-v1.4, MAUS-v1.4.0
MAUS-v1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
namespace MAUS {
22
22
 
 
23
EMRChannelKey::EMRChannelKey()
 
24
  : _plane(-999), _orientation(-999), _bar(-999), _detector("unknown") {
 
25
}
 
26
 
 
27
EMRChannelKey::EMRChannelKey(int pl, int o, int b, string d)
 
28
  : _plane(pl), _orientation(o), _bar(b), _detector(d) {
 
29
}
 
30
 
 
31
EMRChannelKey::~EMRChannelKey() {
 
32
}
 
33
 
 
34
EMRChannelKey::EMRChannelKey(string keyStr) throw(Exception) {
 
35
 
 
36
  std::stringstream xConv;
 
37
  try {
 
38
    xConv << keyStr;
 
39
    xConv >> (*this);
 
40
  } catch (Exception e) {
 
41
    throw(Exception(Exception::recoverable,
 
42
                 std::string("corrupted EMR Channel Key"),
 
43
                 "EMRChannelKey::EMRChannelKey(std::string)"));
 
44
  }
 
45
}
 
46
 
 
47
bool EMRChannelKey::operator==( EMRChannelKey const key ) const {
 
48
 
 
49
  if ( _orientation == key._orientation &&
 
50
       _plane == key._plane &&
 
51
       _bar == key._bar &&
 
52
       _detector == key._detector ) {
 
53
    return true;
 
54
  } else {
 
55
    return false;
 
56
  }
 
57
}
 
58
 
 
59
bool EMRChannelKey::operator!=( EMRChannelKey const key ) const {
 
60
 
 
61
  if ( _orientation == key._orientation &&
 
62
       _plane == key._plane &&
 
63
       _bar == key._bar &&
 
64
       _detector == key._detector ) {
 
65
    return false;
 
66
  } else {
 
67
    return true;
 
68
  }
 
69
}
 
70
 
 
71
ostream& operator<<( ostream& stream, EMRChannelKey key ) {
 
72
 
 
73
  stream << "EMRChannelKey " << key._plane;
 
74
  stream << " " << key._orientation;
 
75
  stream << " " << key._bar;
 
76
  stream << " " << key._detector;
 
77
  return stream;
 
78
}
 
79
 
 
80
istream& operator>>( istream& stream, EMRChannelKey &key ) throw(Exception) {
 
81
 
 
82
  string xLabel;
 
83
  stream >> xLabel >> key._plane >> key._orientation >> key._bar >> key._detector;
 
84
 
 
85
  if (xLabel != "EMRChannelKey") {
 
86
    throw(Exception(Exception::recoverable,
 
87
                 std::string("corrupted EMR Channel Key"),
 
88
                 "istream& operator>>(istream& stream, EMRChannelKey)"));
 
89
  }
 
90
 
 
91
  return stream;
 
92
}
 
93
 
 
94
string EMRChannelKey::str() {
 
95
 
 
96
  stringstream xConv;
 
97
  xConv << (*this);
 
98
  return xConv.str();
 
99
}
 
100
 
 
101
 
 
102
 
 
103
EMRChannelMap::EMRChannelMap() {
 
104
}
 
105
 
23
106
EMRChannelMap::~EMRChannelMap() {
24
 
  for (unsigned int i = 0;i < _emrKey.size();i++) {
 
107
  for (size_t i = 0;i < _emrKey.size();i++) {
 
108
 
25
109
    delete _emrKey[i];
26
 
    delete _dbbKey[i];
 
110
    delete _daqKey[i];
27
111
  }
28
 
  _dbbKey.resize(0);
 
112
  _daqKey.resize(0);
29
113
  _emrKey.resize(0);
30
114
}
31
115
 
32
 
bool EMRChannelMap::InitFromFile(string filename) {
 
116
bool EMRChannelMap::InitializeFromFile(string filename) {
 
117
 
33
118
  ifstream stream(filename.c_str());
34
119
  if ( !stream ) {
35
120
    Squeak::mout(Squeak::error)
36
 
    << "Error in EMRChannelMap::InitFromFile : Can't open EMR cabling file "
 
121
    << "Error in EMRChannelMap::InitializeFromFile : Can't open EMR cabling file "
37
122
    << filename << std::endl;
38
123
    return false;
39
124
  }
40
125
 
41
126
  EMRChannelKey* emrkey;
42
 
  DAQChannelKey* dbbkey;
 
127
  DAQChannelKey* daqKey;
43
128
  try {
44
129
    while (!stream.eof()) {
45
130
      emrkey = new EMRChannelKey();
46
 
      dbbkey = new DAQChannelKey();
47
 
      stream >> *emrkey >> *dbbkey;
 
131
      daqKey = new DAQChannelKey();
 
132
      stream >> *emrkey >> *daqKey;
48
133
 
49
134
      _emrKey.push_back(emrkey);
50
 
      _dbbKey.push_back(dbbkey);
 
135
      _daqKey.push_back(daqKey);
51
136
    }
52
137
  } catch (Exception e) {
53
138
    Squeak::mout(Squeak::error)
54
 
      << "Error in EMRChannelMap::InitFromFile : Error during loading." << std::endl
 
139
      << "Error in EMRChannelMap::InitializeFromFile : Error during loading." << std::endl
55
140
      << e.GetMessage() << std::endl;
56
141
    return false;
57
142
  }
58
143
 
59
144
  if (_emrKey.size() == 0) {
60
145
    Squeak::mout(Squeak::error)
61
 
    << "Error in EMRChannelMap::InitFromFile : Nothing is loaded. "  << std::endl;
 
146
    << "Error in EMRChannelMap::InitializeFromFile : Nothing is loaded. "  << std::endl;
62
147
    return false;
63
148
  }
64
149
  return true;
65
150
}
66
151
 
67
 
void EMRChannelMap::InitFromCDB() {}
68
 
 
69
 
EMRChannelKey* EMRChannelMap::find(DAQChannelKey *daqKey) const {
70
 
    for (unsigned int i = 0;i < _emrKey.size();i++) {
71
 
      if ( _dbbKey[i]->eqType()  == daqKey->eqType() &&
72
 
           _dbbKey[i]->ldc()     == daqKey->ldc() &&
73
 
           _dbbKey[i]->geo()     == daqKey->geo() &&
74
 
           _dbbKey[i]->channel() == daqKey->channel() ) {
 
152
void EMRChannelMap::InitializeFromCDB() {}
 
153
 
 
154
EMRChannelKey* EMRChannelMap::Find(DAQChannelKey *daqKey) const {
 
155
 
 
156
    for (size_t i = 0;i < _emrKey.size();i++) {
 
157
      if ( _daqKey[i]->eqType()  == daqKey->eqType() &&
 
158
           _daqKey[i]->ldc()     == daqKey->ldc() &&
 
159
           _daqKey[i]->geo()     == daqKey->geo() &&
 
160
           _daqKey[i]->channel() == daqKey->channel() ) {
75
161
        return _emrKey[i];
76
162
      }
77
163
    }
78
164
  return NULL;
79
165
}
80
166
 
81
 
EMRChannelKey* EMRChannelMap::find(std::string daqKeyStr) {
 
167
EMRChannelKey* EMRChannelMap::Find(std::string daqKeyStr) {
 
168
 
82
169
  DAQChannelKey xDaqKey;
83
170
  stringstream xConv;
84
171
  try {
89
176
                 std::string("corrupted DAQ Channel Key"),
90
177
                 "EMRChannelMap::find(std::string)"));
91
178
  }
92
 
  EMRChannelKey* xKlKey = find(&xDaqKey);
 
179
  EMRChannelKey* xKlKey = Find(&xDaqKey);
93
180
  return xKlKey;
94
181
}
95
182
 
96
 
int EMRChannelMap::getOrientation(int plane) {
97
 
  for (unsigned int i = 0;i < _emrKey.size();i++) {
98
 
    if ( _emrKey[i]->plane() == plane )
99
 
      return _emrKey[i]->orientation();
 
183
int EMRChannelMap::GetOrientation(int plane) {
 
184
 
 
185
  for (size_t i = 0;i < _emrKey.size();i++) {
 
186
    if ( _emrKey[i]->GetPlane() == plane )
 
187
      return _emrKey[i]->GetOrientation();
100
188
  }
101
189
 
102
190
  return -999;
103
191
}
104
 
//////////////////////////////////////////////////////////////////////////
105
 
 
106
 
EMRChannelKey::EMRChannelKey(string keyStr) throw(Exception) {
107
 
  std::stringstream xConv;
108
 
  try {
109
 
    xConv << keyStr;
110
 
    xConv >> (*this);
111
 
  }catch(Exception e) {
112
 
    throw(Exception(Exception::recoverable,
113
 
                 std::string("corrupted EMR Channel Key"),
114
 
                 "EMRChannelKey::EMRChannelKey(std::string)"));
115
 
  }
116
 
}
117
 
 
118
 
bool EMRChannelKey::operator==( EMRChannelKey const key ) const {
119
 
  if ( _orientation == key._orientation &&
120
 
       _plane == key._plane &&
121
 
       _bar == key._bar &&
122
 
       _detector == key._detector) {
123
 
    return true;
124
 
  } else {
125
 
    return false;
126
 
  }
127
 
}
128
 
 
129
 
bool EMRChannelKey::operator!=( EMRChannelKey const key ) const {
130
 
  if ( _orientation == key._orientation &&
131
 
       _plane == key._plane &&
132
 
       _bar == key._bar &&
133
 
       _detector == key._detector) {
134
 
    return false;
135
 
  } else {
136
 
    return true;
137
 
  }
138
 
}
139
 
 
140
 
ostream& operator<<( ostream& stream, EMRChannelKey key ) {
141
 
  stream << "EMRChannelKey " << key._plane;
142
 
  stream << " " << key._orientation;
143
 
  stream << " " << key._bar;
144
 
  stream << " " << key._detector;
145
 
  return stream;
146
 
}
147
 
 
148
 
istream& operator>>( istream& stream, EMRChannelKey &key ) throw(Exception) {
149
 
  string xLabel;
150
 
  stream >> xLabel >> key._plane >> key._orientation >> key._bar >> key._detector;
151
 
 
152
 
  if (xLabel != "EMRChannelKey") {
153
 
    throw(Exception(Exception::recoverable,
154
 
                 std::string("corrupted EMR Channel Key"),
155
 
                 "istream& operator>>(istream& stream, EMRChannelKey)"));
156
 
  }
157
 
 
158
 
  return stream;
159
 
}
160
 
 
161
 
string EMRChannelKey::str() {
162
 
  stringstream xConv;
163
 
  xConv << (*this);
164
 
  return xConv.str();
 
192
 
 
193
void EMRChannelMap::Print() {
 
194
 
 
195
  for (size_t i = 0; i < _emrKey.size(); i++)
 
196
    std::cerr << *(_emrKey[i]) << " " << *(_daqKey[i]) << std::endl;
165
197
}
166
198
}