/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/geometry/Board.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1751 $ * @modifiedby $Author: lcdet $ * @lastmodified $Date: 2012-05-30 17:01:35 +0200 (Wed, 30 May 2012) $ */
00002 
00003 #include "geometry/Channel.hh"
00004 #include "geometry/Chip.hh"
00005 #include "geometry/Board.hh"
00006 #include "geometry/Chamber.hh"
00007 
00008 #include "tools/MicroException.hh"
00009 #include "tools/Log.hh"
00010 
00011 #include <iostream>
00012 
00013 using namespace std;
00014 
00015 //--------------------------//
00016 std::ostream& operator <<(std::ostream& out, const Board& x) {
00017   return(x.operator <<(out));
00018 } // operator <<
00019 
00020 //--------------------------//
00021 Board::Board(const Chamber& _chamber,  const ui32 aCol, const ui32 aRow, const ui32 aNbColumns, const ui32 aNbRows,  const i32 aId)
00022 : chamber(_chamber), dif(NULL),  row(aRow), column(aCol), nbColumns(aNbColumns), nbRows(aNbRows),  id(aId)
00023 {
00024   FILE_LOG(logDEBUG1) << "Board constructor row " << row << ", column:" << column << endl;
00025 }
00026 
00027 //--------------------------//
00028 Board::~Board() {
00029   FILE_LOG(logDEBUG1) << "Board destructor" << endl;
00030   for (std::map<i32, Chip *>::const_iterator it = chips.begin(); it != chips.end(); ++it)
00031   {
00032     delete (it->second);
00033   }
00034 }
00035 
00036 //--------------------------//
00037 Board::Board(const Board &x) : chamber(x.chamber) {
00038   *this = x;
00039 }
00040 
00041 //--------------------------//
00042 Board& Board::operator=(const Board &x) {
00043 //  (Chamber)chamber = x.chamber;
00044   id = x.id;
00045   column = x.column, row= x.row;
00046   nbColumns = x.nbColumns, nbRows = x.nbRows;
00047   chips = x.chips;
00048 }
00049 
00050 //--------------------------//
00051 std::ostream& Board::operator <<(std::ostream& out) const {
00052   out << "    " << "Board id " << id << ", [x/y/z] @[" << getX() << ", " << getY() << ", " << chamber.getZ() << "], "
00053       << "[col/row]=>["<< column << "/" << row << "], "
00054       << "[Xlength/Ylength]=>["<< getXLength() << "/" << getYLength() << "], "
00055       << chips.size() << " chips" << endl;
00056   if (chips.size()) {
00057     for (std::map<i32, Chip *>::const_iterator it = chips.begin(); it != chips.end(); ++it) {
00058       out << *(it->second);
00059     }
00060   }
00061   return(out);
00062 } // operator <<
00063 
00064 //--------------------------//
00065 void Board::addChip(Chip *chip) {
00066   chips.insert(make_pair(chip->getId(), chip));
00067 } // Board.addChip
00068 
00069 //--------------------------//
00070  Chip &Board::getChipById(const i32 chipId) {
00071   std::map<i32, Chip *>::const_iterator itChip = chips.find(chipId);
00072   if (itChip == chips.end()) {
00073     throw MicroException("Board.getChipById : no Chip found for this id in this Board ");
00074   }
00075   return(*itChip->second);
00076 }
00077 
00078 //--------------------------//
00079   Chip &Board::getChipByRowCol(const i16 row, const i16 col )
00080 {
00081     for (std::map<i32, Chip *>::const_iterator it = chips.begin(); it != chips.end(); ++it) {
00082       Chip &chip = *(it->second);
00083       if ( chip.getRow() == row && chip.getColumn() == col )
00084       {
00085         return(chip);
00086       }
00087   }
00088   throw MicroException("Board.getChannelByRowCol : no Channel found with this col and row" );
00089 }
00090 //--------------------------//
00091 Channel &Board::getChannelById(const i32 channelId, const i32 chipId)
00092 {
00093   // for gassiplex boards the ChipId is the same as the channelId (every chip contains one and only one channel)
00094   try {
00095     Chip& chip = getChipById((chipId >= 0) ? chipId : channelId);
00096     Channel& ch = chip.getChannelById(channelId);
00097     return(ch);
00098   }
00099   catch (MicroException& e) {
00100   }
00101   throw MicroException("Board.getChannelById : no Channel found with this id" );
00102 };
00103 
00104 //-------------------------------------------//
00105 const float Board::getX() const
00106 {
00107 
00108   float result = 0.;
00109 
00110   if ( getChamber().getZrotation() == 90 )
00111   { result = getYRelative(); }
00112   else if ( getChamber().getZrotation() == -90 )
00113   { result = -getYRelative(); }
00114 
00115   else  { result = getXRelative(); }
00116 
00117  if ( getChamber().getYrotation())
00118   {
00119     result = - result;
00120   }
00121 
00122   return result + chamber.getX();//true);
00123 }
00124 
00125 //-------------------------------------------//
00126 const float Board::getXRelative() const
00127 {
00128   float result = - ( chamber.getXLength() / 2. ) + ( row * this->getXLength() )  + ( this->getXLength() / 2. ) + ( row ) * chamber.getXGap();
00129 
00130   return result;
00131 }
00132 //-------------------------------------------//
00133 const float Board::getY() const
00134 {
00135 
00136   float result = 0.;
00137   if ( getChamber().getZrotation() == 90 )
00138   { result = -getXRelative(); }
00139 
00140  else if ( getChamber().getZrotation() == -90 )
00141   { result = getXRelative(); }
00142 
00143 
00144   else {  result = getYRelative(); }  
00145 
00146   if ( getChamber().getXrotation())
00147   {
00148     result = - result;
00149   }
00150    return result + chamber.getY();//true);
00151 }
00152 
00153 
00154 //-------------------------------------------//
00155 const float Board::getYRelative() const
00156 {
00157   float result = 0.;
00158   result = - ( chamber.getYLength() / 2. ) + ( column * this->getYLength() )  + ( this->getYLength() / 2. )  + ( column  * chamber.getYGap());
00159 
00160   return result;
00161 
00162 }
00163 //-------------------------------------------//
00164 const float  Board::getXLength() const
00165 {
00166 
00167   if (chips.size())
00168   {
00169     Chip* ch = chips.begin()->second;
00170     return  (nbRows *  ch->getXLength())  +( (nbRows-1) * getXGap() ) ;
00171   }
00172 
00173   return 0.;
00174 }
00175 
00176 //-------------------------------------------//
00177 void Board::setDif( Dif *aDif)
00178 {
00179     dif = aDif;
00180 }
00181 
00182 //-------------------------------------------//
00183 const float  Board::getYLength() const
00184 {
00185   if (chips.size())
00186   {
00187     Chip *ch = chips.begin()->second;
00188     return  (nbColumns *  ch->getYLength()) +( (nbColumns-1) * getYGap() ) ;
00189 
00190   }
00191   return 0;
00192 }
00193 
00194 //-------------------------------------------//
00195 const float Board::getLeftBottomX() const
00196 {
00197   if ( getChamber().getZrotation() == 90 || getChamber().getZrotation() == -90 ) return ( getX() - getYLength() / 2.);
00198    return ( getX() - getXLength() / 2.);
00199 }
00200 //-------------------------------------------//
00201 const float Board::getLeftBottomY() const
00202 {
00203   if ( getChamber().getZrotation() == 90  || getChamber().getZrotation() == -90) return ( getY() - getXLength() / 2.);
00204    return ( getY() - getYLength() / 2.);
00205 }
00206 //-------------------------------------------//
00207 const float Board::getRightUpperX() const
00208 {
00209   if ( getChamber().getZrotation() == 90  || getChamber().getZrotation() == -90) return ( getX() + getYLength() / 2.);
00210    return ( getX() + getXLength() / 2.);
00211 }
00212 //-------------------------------------------//
00213 const float Board::getRightUpperY() const
00214 {
00215   if ( getChamber().getZrotation() == 90  || getChamber().getZrotation() == -90) return ( getY() + getXLength() / 2.);
00216    return ( getY() + getYLength() / 2.);
00217 }
00218 
00219 //-------------------------------------------//
00220 i32 Board::getMinChipId() const
00221 {
00222         i32     result = 0xffff;
00223   for (std::map<i32, Chip *>::const_iterator it = chips.begin(); it != chips.end(); ++it)
00224   {
00225     Chip* chip = it->second;
00226                 if (chip)
00227                 {
00228                                                 if ( chip->getId() < result) { result = chip->getId(); }
00229                 }
00230         }
00231                 return result;
00232 }
00233 
00234 //-------------------------------------------//
00235 i32 Board::getMaxChipId() const
00236 {
00237         i32     result = 0;
00238   for (std::map<i32, Chip *>::const_iterator it = chips.begin(); it != chips.end(); ++it)
00239   {
00240     Chip* chip = it->second;
00241                 if (chip)
00242                 {
00243                                                 if ( chip->getId() > result) { result = chip->getId(); }
00244                 }
00245         }
00246                 return result;
00247 }

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7