~mice-daq/equipmentlist-mice/trunk

« back to all changes in this revision

Viewing changes to src/toollib/EMRChannelMap.cc

  • Committer: Yordan Karadzhov
  • Date: 2013-10-01 19:36:26 UTC
  • Revision ID: yordan.karadzhov@cern.ch-20131001193626-9bm7j1jjqfureu64
Stable version of the EMR readout. Tested with maus-data revision 8 and unpacking-mice revision 7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
2
 
 *
3
 
 * MAUS is free software: you can redistribute it and/or modify
4
 
 * it under the terms of the GNU General Public License as published by
5
 
 * the Free Software Foundation, either version 3 of the License, or
6
 
 * (at your option) any later version.
7
 
 *
8
 
 * MAUS is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 */
17
 
 
18
 
#include "EMRChannelMap.hh"
19
 
 
20
 
namespace MAUS {
21
 
EMRChannelMap::~EMRChannelMap() {
22
 
  for (unsigned int i = 0;i < _emrKey.size();i++) {
23
 
    delete _emrKey[i];
24
 
    delete _dbbKey[i];
25
 
  }
26
 
  _dbbKey.resize(0);
27
 
  _emrKey.resize(0);
28
 
}
29
 
 
30
 
bool EMRChannelMap::InitFromFile(string filename) {
31
 
  ifstream stream(filename.c_str());
32
 
  if ( !stream ) {
33
 
    Squeak::mout(Squeak::error)
34
 
    << "Error in EMRChannelMap::InitFromFile : Can't open EMR cabling file "
35
 
    << filename << std::endl;
36
 
    return false;
37
 
  }
38
 
 
39
 
  EMRChannelKey* emrkey;
40
 
  DAQChannelKey* dbbkey;
41
 
  try {
42
 
    while (!stream.eof()) {
43
 
      emrkey = new EMRChannelKey();
44
 
      dbbkey = new DAQChannelKey();
45
 
      stream >> *emrkey >> *dbbkey;
46
 
      _emrKey.push_back(emrkey);
47
 
      _dbbKey.push_back(dbbkey);
48
 
    }
49
 
  } catch(Squeal e) {
50
 
    Squeak::mout(Squeak::error)
51
 
      << "Error in EMRChannelMap::InitFromFile : Error during loading." << std::endl
52
 
      << e.GetMessage() << std::endl;
53
 
    return false;
54
 
  }
55
 
 
56
 
  if (_emrKey.size() == 0) {
57
 
    Squeak::mout(Squeak::error)
58
 
    << "Error in EMRChannelMap::InitFromFile : Nothing is loaded. "  << std::endl;
59
 
    return false;
60
 
  }
61
 
  return true;
62
 
}
63
 
 
64
 
void EMRChannelMap::InitFromCDB() {}
65
 
 
66
 
EMRChannelKey* EMRChannelMap::find(DAQChannelKey *daqKey) {
67
 
  if (daqKey->eqType() == 141) {
68
 
    for (unsigned int i = 0;i < _emrKey.size();i++) {
69
 
      if ( _dbbKey[i]->ldc()     == daqKey->ldc() &&
70
 
           _dbbKey[i]->geo()     == daqKey->geo() &&
71
 
           _dbbKey[i]->channel() == daqKey->channel() ) {
72
 
        return _emrKey[i];
73
 
      }
74
 
    }
75
 
  }
76
 
  return NULL;
77
 
}
78
 
 
79
 
EMRChannelKey* EMRChannelMap::find(std::string daqKeyStr) {
80
 
  DAQChannelKey xDaqKey;
81
 
  stringstream xConv;
82
 
  try {
83
 
    xConv << daqKeyStr;
84
 
    xConv >> xDaqKey;
85
 
  }catch(Squeal e) {
86
 
    throw(Squeal(Squeal::recoverable,
87
 
                 std::string("corrupted DAQ Channel Key"),
88
 
                 "EMRChannelMap::find(std::string)"));
89
 
  }
90
 
  EMRChannelKey* xKlKey = find(&xDaqKey);
91
 
  return xKlKey;
92
 
}
93
 
 
94
 
 
95
 
//////////////////////////////////////////////////////////////////////////
96
 
 
97
 
EMRChannelKey::EMRChannelKey(string keyStr) throw(Squeal) {
98
 
  std::stringstream xConv;
99
 
  try {
100
 
    xConv << keyStr;
101
 
    xConv >> (*this);
102
 
  }catch(Squeal e) {
103
 
    throw(Squeal(Squeal::recoverable,
104
 
                 std::string("corrupted EMR Channel Key"),
105
 
                 "EMRChannelKey::EMRChannelKey(std::string)"));
106
 
  }
107
 
}
108
 
 
109
 
bool EMRChannelKey::operator==( EMRChannelKey const key ) {
110
 
  if ( _module == key._module &&
111
 
       _plane == key._plane &&
112
 
       _bar == key._bar &&
113
 
       _detector == key._detector) {
114
 
    return true;
115
 
  } else {
116
 
    return false;
117
 
  }
118
 
}
119
 
 
120
 
bool EMRChannelKey::operator!=( EMRChannelKey const key ) {
121
 
  if ( _module == key._module &&
122
 
       _plane == key._plane &&
123
 
       _bar == key._bar &&
124
 
       _detector == key._detector) {
125
 
    return false;
126
 
  } else {
127
 
    return true;
128
 
  }
129
 
}
130
 
 
131
 
ostream& operator<<( ostream& stream, EMRChannelKey key ) {
132
 
  stream << "EMRChannelKey " << key._module;
133
 
  stream << " " << key._plane;
134
 
  stream << " " << key._bar;
135
 
  stream << " " << key._detector;
136
 
  return stream;
137
 
}
138
 
 
139
 
istream& operator>>( istream& stream, EMRChannelKey &key ) throw(Squeal) {
140
 
  string xLabel;
141
 
  stream >> xLabel >> key._module >> key._plane >> key._bar >> key._detector;
142
 
  if (xLabel != "EMRChannelKey") {
143
 
    throw(Squeal(Squeal::recoverable,
144
 
                 std::string("corrupted EMR Channel Key"),
145
 
                 "istream& operator>>(istream& stream, EMRChannelKey)"));
146
 
  }
147
 
 
148
 
  return stream;
149
 
}
150
 
 
151
 
string EMRChannelKey::str() {
152
 
  stringstream xConv;
153
 
  xConv << (*this);
154
 
  return xConv.str();
155
 
}
156
 
}
157