00001
00002
00003 #include "geometry/Chamber.hh"
00004 #include "geometry/Dif.hh"
00005 #include "geometry/Board.hh"
00006 #include "geometry/Chip.hh"
00007 #include "geometry/Channel.hh"
00008
00009 #include "tools/MicroException.hh"
00010 #include "tools/Log.hh"
00011 #include <iostream>
00012 #include "mTypes.h"
00013
00014 using namespace std;
00015
00016
00017 std::ostream& operator <<(std::ostream& out, const Chamber& x) {
00018 return(x.operator <<(out));
00019 }
00020
00021
00022 std::ostream& Chamber::operator <<(std::ostream& out) const {
00023 out << description << " id " << id << " @[" << xPos << ", " << yPos << ", " << zPos << "] x rotation[" << xRotation << "][ y rotation[" << yRotation << "] [ z rotation[" << zRotation << "]" << boards.size() << " boards, " << difs.size() << " difs" << endl;
00024
00025
00026 if (difs.size()) {
00027 for (DifMap_t::const_iterator it = difs.begin(); it != difs.end(); ++it) {
00028 out << *(it->second) << endl;
00029 }
00030 }
00031 else {
00032 for (std::map<i32, Board *>::const_iterator it = boards.begin(); it != boards.end(); ++it) {
00033 out << *(it->second) << endl;
00034 }
00035 }
00036 return(out);
00037 }
00038
00039
00040
00041 Chamber::Chamber(const float aX, const float aY, const float aZ,const bool axRotation, const bool ayRotation , const i16 azRotation , const ui32 aNbColumns, const ui32 aNbRows, const i32 aId)
00042 : id(aId), xPos(aX), yPos(aY), zPos(aZ), xRotation(axRotation), yRotation(ayRotation), zRotation(azRotation) , description(""), nbColumns(aNbColumns) , nbRows(aNbRows)
00043 {
00044
00045
00046 }
00047
00048
00049
00050 Chamber::Chamber(const Chamber &source)
00051 {
00052
00053 *this = source;
00054 }
00055
00056
00057
00058 Chamber& Chamber::operator =(const Chamber &source)
00059 {
00060
00061 xPos = source.xPos;
00062 yPos = source.yPos;
00063 zPos = source.zPos;
00064 xRotation = source.xRotation;
00065 yRotation = source.yRotation;
00066 zRotation = source.zRotation;
00067 id = source.id;
00068 description = source.description;
00069 boards = source.boards;
00070
00071 return *this;
00072 }
00073
00074
00075 Chamber::~Chamber()
00076 {
00077
00078 for (std::map<i32, Board *>::const_iterator it = boards.begin(); it != boards.end(); ++it) {
00079 delete (it->second);
00080 }
00081 }
00082
00083
00084 void Chamber::addDif(Dif *dif)
00085 {
00086 difs.insert(make_pair(dif->getId(), dif));
00087 }
00088
00089 void Chamber::addBoard(Board *board)
00090 {
00091 boards.insert(make_pair(board->getId(), board));
00092 }
00093
00094
00095 const BoardMap_t& Chamber::getBoardsByDifId(const i32 difId) const {
00096 DifMap_t::const_iterator difIt = difs.find(difId);
00097 if (difIt == difs.end()) {
00098 throw MicroException("no Dif found with this id: ");
00099 }
00100 return(difIt->second->getBoards());
00101 }
00102
00103
00104 const Channel& Chamber::getChannelById(const i32 channelId, const i32 chipId, const i32 difId) const
00105 {
00106
00107
00108 const BoardMap_t& boardMap = (chipId < 0) ? boards : getBoardsByDifId(difId);
00109
00110
00111
00112 for (BoardMap_t::const_iterator boardIt = boardMap.begin(); boardIt != boardMap.end(); ++boardIt) {
00113 try {
00114 Channel& channel = boardIt->second->getChannelById(channelId, chipId);
00115 return(channel);
00116 }
00117 catch (MicroException &e) {
00118
00119 }
00120 }
00121
00122 throw MicroException("Chamber.getChannelById : no Channel found for this id and this chamber ");
00123 }
00124
00125
00126 float Chamber::getX() const
00127 {
00128 return xPos;
00129 }
00130
00131 float Chamber::getY() const
00132 {
00133
00134 return yPos;
00135 }
00136
00137
00138 const float Chamber::getLeftBottomX() const
00139 {
00140 if ( getZrotation() == 90 || getZrotation() == -90 ) return ( getX() - getYLength() / 2.);
00141 return ( getX() - getXLength() / 2.);
00142 }
00143
00144 const float Chamber::getLeftBottomY() const
00145 {
00146 if ( getZrotation() == 90 || getZrotation() == -90) return ( getY() - getXLength() / 2.);
00147 return ( getY() - getYLength() / 2.);
00148 }
00149
00150 const float Chamber::getRightUpperX() const
00151 {
00152 if ( getZrotation() == 90 || getZrotation() == -90) return ( getX() + getYLength() / 2.);
00153 return ( getX() + getXLength() / 2.);
00154 }
00155
00156 const float Chamber::getRightUpperY() const
00157 {
00158 if ( getZrotation() == 90 || getZrotation() == -90) return ( getY() + getXLength() / 2.);
00159 return ( getY() + getYLength() / 2.);
00160 }
00161
00162
00163 const float Chamber::getXLength() const
00164 {
00165 const Board& board = *(boards.begin()->second);
00166
00167 return (this->nbRows * board.getXLength()) + ( (this->nbRows -1 ) * this->getXGap() );
00168 }
00169
00170
00171 const float Chamber::getYLength() const
00172 {
00173 const Board& board = *(boards.begin()->second);
00174 return (this->nbColumns * board.getYLength() )+ ((this->nbColumns-1 ) * this->getYGap() );
00175 }
00176
00177
00178
00179 const Dif& Chamber::getDifById(const i32 difId) const
00180 {
00181 std::map<i32, Dif *>::const_iterator it = difs.find(difId);
00182 if (it == difs.end())
00183 throw MicroException("Chanber.getDifById : no Dif found for this id");
00184
00185 return(*(it->second));
00186 };