00001 #include "emcRejectList.h"
00002 #include <cassert>
00003 #include <iomanip>
00004
00005 using namespace std;
00006
00007 namespace
00008 {
00009 void warning(const char* type, unsigned int value)
00010 {
00011 std::cerr << __FILE__ << ":" << __LINE__ << " "
00012 << type << "=" << value << " is more than the required 4 bits. "
00013 << "Will be tripped down to 4 bits only"
00014 << std::endl;
00015 }
00016
00017 void trip(unsigned int& amperror, unsigned int& ampwarning,
00018 unsigned int& toferror, unsigned int& tofwarning)
00019 {
00020
00021 if ( amperror & 0xFFF0 )
00022 {
00023 warning("amperror",amperror);
00024 }
00025 if ( ampwarning & 0xFFF0 )
00026 {
00027 warning("ampwarning",ampwarning);
00028 }
00029 if ( toferror & 0xFFF0 )
00030 {
00031 warning("toferror",toferror);
00032 }
00033 if ( tofwarning & 0xFFF0 )
00034 {
00035 warning("tofwarning",tofwarning);
00036 }
00037
00038 amperror = amperror & 0xF;
00039 ampwarning = ampwarning & 0xF;
00040 toferror = toferror & 0xF;
00041 tofwarning = tofwarning & 0xF;
00042 }
00043 }
00044
00045
00046 emcRejectList::SixInts::SixInts(unsigned int amperror, unsigned int ampwarning,
00047 unsigned int toferror, unsigned int tofwarning)
00048 {
00049 set(amperror,ampwarning,toferror,tofwarning);
00050 }
00051
00052
00053 bool
00054 emcRejectList::SixInts::nonZero() const
00055 {
00056 return ( error_ != 0 || warning_ != 0 );
00057 }
00058
00059
00060 void
00061 emcRejectList::SixInts::set(unsigned int amperror, unsigned int ampwarning,
00062 unsigned int toferror, unsigned int tofwarning)
00063 {
00064 trip(amperror,ampwarning,toferror,tofwarning);
00065
00066 ampError_ = amperror;
00067 ampWarning_ = ampwarning;
00068 tofError_ = toferror;
00069 tofWarning_ = tofwarning;
00070
00071 error_ = ( tofError_ << 4 ) | ampError_;
00072 warning_ = ( tofWarning_ << 4 ) | ampWarning_;
00073 }
00074
00075
00076 void
00077 emcRejectList::SixInts::set_or(unsigned int amperror, unsigned int ampwarning,
00078 unsigned int toferror, unsigned int tofwarning)
00079 {
00080 trip(amperror,ampwarning,toferror,tofwarning);
00081
00082 ampError_ |= amperror;
00083 ampWarning_ |= ampwarning;
00084 tofError_ |= toferror;
00085 tofWarning_ |= tofwarning;
00086
00087 error_ = ( tofError_ << 4 ) | ampError_;
00088 warning_ = ( tofWarning_ << 4 ) | ampWarning_;
00089 }
00090
00091
00092 void
00093 emcRejectList::SixInts::zero()
00094 {
00095 ampWarning_=ampError_=tofError_=tofWarning_=0;
00096 error_=warning_=0;
00097 }
00098
00099
00100 emcRejectList::emcRejectList()
00101 : emcManageable("emcRejectList","List of EMCAL towers known to be bad",
00102 "emcRejectList")
00103 {
00104 fStart.setToSystemTime();
00105 fEnd.setToFarFuture();
00106 Reset();
00107 }
00108
00109
00110 emcRejectList::emcRejectList(const emcRejectList& o) : emcManageable()
00111 {
00112 o.Copy(*this);
00113 }
00114
00115
00116 emcRejectList&
00117 emcRejectList::operator=(const emcRejectList& o)
00118 {
00119 if ( this != &o )
00120 {
00121 Reset();
00122 o.Copy(*this);
00123 }
00124 return *this;
00125 }
00126
00127
00128 emcRejectList&
00129 emcRejectList::operator+=(const emcRejectList& o)
00130 {
00131 for ( size_t itower = 0; itower < o.maxsize(); ++itower )
00132 {
00133 if ( o.nonZero(itower) )
00134 {
00135 set_or(itower,
00136 o.AmplitudeError(itower),o.AmplitudeWarning(itower),
00137 o.TimingError(itower),o.TimingWarning(itower));
00138 }
00139 }
00140 return *this;
00141 }
00142
00143
00144 emcRejectList&
00145 emcRejectList::operator-=(const emcRejectList& o)
00146 {
00147 for ( size_t itower = 0; itower < o.maxsize(); ++itower )
00148 {
00149 if ( o.nonZero(itower) )
00150 {
00151 if ( nonZero(itower) )
00152 {
00153 fTowers.erase(itower);
00154 }
00155 }
00156 }
00157 return *this;
00158 }
00159
00160
00161 emcRejectList::~emcRejectList()
00162 {
00163 }
00164
00165
00166 emcRejectList::SixInts
00167 emcRejectList::getTower(int towerid) const
00168 {
00169 TMAP::const_iterator it = fTowers.find(towerid);
00170 if ( it != fTowers.end() )
00171 {
00172 return it->second;
00173 }
00174 else
00175 {
00176 return emcRejectList::SixInts();
00177 }
00178 }
00179
00180
00181 unsigned int
00182 emcRejectList::AmplitudeError(int towerid) const
00183 {
00184 return getTower(towerid).ampError();
00185 }
00186
00187
00188 unsigned int
00189 emcRejectList::AmplitudeWarning(int towerid) const
00190 {
00191 return getTower(towerid).ampWarning();
00192 }
00193
00194
00195 void
00196 emcRejectList::Copy(emcRejectList& to) const
00197 {
00198 to.fTowers = fTowers;
00199 to.fStart = fStart;
00200 to.fEnd = fEnd;
00201 }
00202
00203
00204 unsigned int
00205 emcRejectList::Error(int towerid) const
00206 {
00207 return getTower(towerid).error();
00208 }
00209
00210
00211 bool
00212 emcRejectList::nonZero(int towerid) const
00213 {
00214 return getTower(towerid).nonZero();
00215 }
00216
00217
00218 void
00219 emcRejectList::print(std::ostream& out) const
00220 {
00221 std::ostream::fmtflags oldflags = out.flags();
00222
00223 TMAP::const_iterator it;
00224 for ( it = fTowers.begin(); it != fTowers.end(); ++it )
00225 {
00226 if ( it->second.nonZero() )
00227 {
00228 out << dec << "TOWERID=" << setw(6) << it->first
00229 << " AMP ERR=" << setw(6) << hex << it->second.ampError()
00230 << " AMP WARN =" << setw(6) << hex << it->second.ampWarning()
00231 << " TOF ERR=" << setw(6) << hex << it->second.tofError()
00232 << " TOF WARN =" << setw(6) << hex << it->second.tofWarning()
00233 << std::endl;
00234 }
00235 }
00236 out.setf(oldflags);
00237 }
00238
00239
00240 void
00241 emcRejectList::Reset()
00242 {
00243 fTowers.clear();
00244 }
00245
00246
00247 void
00248 emcRejectList::set(int towerid,
00249 unsigned int amp_error, unsigned int amp_warning,
00250 unsigned int timing_error, unsigned int timing_warning)
00251 {
00252 SixInts& v = fTowers[towerid];
00253 v.set(amp_error,amp_warning,timing_error,timing_warning);
00254 }
00255
00256
00257 void
00258 emcRejectList::set_or(int towerid,
00259 unsigned int amp_error, unsigned int amp_warning,
00260 unsigned int timing_error, unsigned int timing_warning)
00261 {
00262 SixInts& v = fTowers[towerid];
00263 v.set_or(amp_error,amp_warning,timing_error,timing_warning);
00264 }
00265
00266
00267 unsigned int
00268 emcRejectList::TimingError(int towerid) const
00269 {
00270 return getTower(towerid).tofError();
00271 }
00272
00273
00274 unsigned int
00275 emcRejectList::TimingWarning(int towerid) const
00276 {
00277 return getTower(towerid).tofWarning();
00278 }
00279
00280
00281
00282 unsigned int
00283 emcRejectList::Warning(int towerid) const
00284 {
00285 return getTower(towerid).warning();
00286 }