Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CMap.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CMap.cxx,v 1.3 2008/10/10 20:41:33 jpaley Exp $
00003 //
00004 // cmap::CMap class source code
00005 //
00006 // \author $Author: jpaley $
00007 //
00009 
00010 #include "CMap/CMap.h"
00011 #include "JobControl/Exception.h"
00012 #include <string>
00013 #include <iostream>
00014 
00015 using namespace cmap;
00016 
00017 FDCMap*   FDCMap::fInstance   = 0;
00018 NDCMap*   NDCMap::fInstance   = 0;
00019 IPNDCMap* IPNDCMap::fInstance = 0;
00020 
00021 //----------------------------------------------------------------------
00022 
00023 CMap::CMap(std::string& fname) : 
00024   db::Table(fname)
00025 {
00026 
00027 }
00028 
00029 //----------------------------------------------------------------------
00030 
00031 CMap::~CMap()
00032 {
00033 
00034 }
00035 
00036 //----------------------------------------------------------------------
00037 
00038 bool CMap::ChanToCell(int board_id, int chan_id, 
00039                       int& plane, int& cell)
00040 {
00041   plane = board_id;
00042   cell = chan_id;
00043   return true;
00044 }
00045 
00046 //----------------------------------------------------------------------
00047 
00048 bool CMap::CellToChan(int plane, int cell, 
00049                       int& board_id, int& chan_id)
00050 {
00051   board_id = plane;
00052   chan_id = cell;
00053   return true;
00054 }
00055 
00056 //----------------------------------------------------------------------
00057 
00058 bool CMap::ChanToCellException(int board_id, int chan_id, 
00059                                int& plane, int& cell)
00060 {
00061   int bid, cid;
00062 
00063   // look for exceptions in the table... if found, set plane/cell 
00064   // according to table entries
00065   for (unsigned int i=0; i<this->size(); ++i) {
00066     dbi::Row& row = (*this)[i];
00067     row.Get(std::string("board_id"),bid);
00068     row.Get(std::string("chan_id"),cid);
00069     if (bid == board_id && cid == chan_id) {
00070       row.Get(std::string("plane"),plane);
00071       row.Get(std::string("cell"),cell);
00072       return true;
00073     }
00074   }
00075 
00076   return false;
00077 }
00078 
00079 //----------------------------------------------------------------------
00080 
00081 bool CMap::CellToChanException(int plane, int cell,
00082                                int& board_id, int& chan_id)
00083 {  
00084   int pl, ce;
00085 
00086   // look for exceptions in the table... if found, set plane/cell 
00087   // according to table entries
00088   for (unsigned int i=0; i<this->size(); ++i) {
00089     dbi::Row& row = (*this)[i];
00090     row.Get(std::string("plane"),pl);
00091     row.Get(std::string("cell"),ce);
00092     if (pl == plane && ce == cell) {
00093       row.Get(std::string("board_id"),board_id);
00094       row.Get(std::string("chan_id"),chan_id);
00095       return true;
00096     }
00097   }
00098   
00099   return false;
00100 }
00101 
00102 //----------------------------------------------------------------------
00103 
00104 FDCMap::FDCMap(std::string& fname) : CMap(fname)
00105 {
00106 
00107 }
00108 
00109 //----------------------------------------------------------------------
00110 
00111 FDCMap::~FDCMap()
00112 {
00113 
00114 }
00115 
00116 //----------------------------------------------------------------------
00117 
00118 FDCMap& FDCMap::Instance(time_t& t)
00119 {
00120   if (!fInstance) {
00121     std::string fname = "cmapfd.xml";
00122     fInstance = new FDCMap(fname);
00123   }
00124   
00125   if (t >= fInstance->MinTime() && 
00126       t <= fInstance->MaxTime()) return *fInstance;
00127   
00128   assert_jobc(!fInstance->Init(t), "Failed to initialize!");
00129   
00130   return *fInstance;
00131 }
00132 
00133 //----------------------------------------------------------------------
00134 // For now we assume a 1-1 mapping, and that the board_id is actually the
00135 // plane number, and the chan_id is the cell number
00136 
00137 bool FDCMap::ChanToCell(int board_id, int chan_id,
00138                         int& plane, int& cell)
00139 {
00140   if (fInstance->ChanToCellException(board_id, chan_id, plane, cell))
00141     return true;
00142 
00143   // if no exceptions were found, use algorithmic mapping
00144   plane = board_id;
00145   cell = chan_id;
00146   
00147   return true;
00148 }
00149 
00150 //----------------------------------------------------------------------
00151 // For now we assume a 1-1 mapping, and that the board_id is actually the
00152 // plane number, and the chan_id is the cell number
00153 
00154 bool FDCMap::CellToChan(int plane, int cell,
00155                         int& board_id, int& chan_id)
00156 {
00157   if (fInstance->CellToChanException(board_id, chan_id, plane, cell))
00158     return true;
00159 
00160   // if no exceptions were found, use algorithmic mapping
00161   board_id = plane;
00162   chan_id = cell;
00163 
00164   return true;
00165 }
00166 
00167 //----------------------------------------------------------------------
00168 
00169 NDCMap::NDCMap(std::string& fname) : CMap(fname)
00170 {
00171 
00172 }
00173 
00174 //----------------------------------------------------------------------
00175 
00176 NDCMap::~NDCMap()
00177 {
00178 
00179 }
00180 
00181 //----------------------------------------------------------------------
00182 
00183 NDCMap& NDCMap::Instance(time_t& t)
00184 {
00185   if (!fInstance) {
00186     std::string fname = "cmapnd.xml";
00187     fInstance = new NDCMap(fname);
00188   }
00189   
00190   if (t >= fInstance->MinTime() && 
00191       t <= fInstance->MaxTime()) return *fInstance;
00192 
00193   assert_jobc(!fInstance->Init(t), "Failed to initialize!");
00194   
00195   return *fInstance;
00196 }
00197 
00198 //----------------------------------------------------------------------
00199 // For now we assume a 1-1 mapping, and that the board_id is actually the
00200 // plane number, and the chan_id is the cell number
00201 
00202 bool NDCMap::ChanToCell(int board_id, int chan_id,
00203                         int& plane, int& cell)
00204 {
00205   if (fInstance->ChanToCellException(board_id, chan_id, plane, cell))
00206     return true;
00207 
00208   // if no exceptions were found, use algorithmic mapping
00209   plane = board_id;
00210   cell = chan_id;
00211 
00212   return true;
00213 }
00214 
00215 //----------------------------------------------------------------------
00216 // For now we assume a 1-1 mapping, and that the board_id is actually the
00217 // plane number, and the chan_id is the cell number
00218 
00219 bool NDCMap::CellToChan(int plane, int cell,
00220                         int& board_id, int& chan_id)
00221 {
00222   if (fInstance->CellToChanException(board_id, chan_id, plane, cell))
00223     return true;
00224 
00225   // if no exceptions were found, use algorithmic mapping
00226   board_id = plane;
00227   chan_id = cell;
00228 
00229   return true;
00230 }
00231 
00232 //----------------------------------------------------------------------
00233 
00234 IPNDCMap::IPNDCMap(std::string& fname) : CMap(fname)
00235 {
00236 
00237 }
00238 
00239 //----------------------------------------------------------------------
00240 
00241 IPNDCMap::~IPNDCMap()
00242 {
00243 
00244 }
00245 
00246 //----------------------------------------------------------------------
00247 
00248 IPNDCMap& IPNDCMap::Instance(time_t& t)
00249 {
00250   if (!fInstance) {
00251     std::string fname = "cmapipnd.xml";
00252     fInstance = new IPNDCMap(fname);
00253   }
00254   
00255   if (t >= fInstance->MinTime() && 
00256       t <= fInstance->MaxTime()) return *fInstance;
00257 
00258   assert_jobc(!fInstance->Init(t), "Failed to initialize!");
00259   
00260   return *fInstance;
00261 }
00262 
00263 //----------------------------------------------------------------------
00264 // For now we assume a 1-1 mapping, and that the board_id is actually the
00265 // plane number, and the chan_id is the cell number
00266 
00267 bool IPNDCMap::ChanToCell(int board_id, int chan_id,
00268                         int& plane, int& cell)
00269 {
00270   if (fInstance->ChanToCellException(board_id, chan_id, plane, cell))
00271     return true;
00272 
00273   // if no exceptions were found, use algorithmic mapping
00274   plane = board_id;
00275   cell = chan_id;
00276 
00277   return true;
00278 }
00279 
00280 //----------------------------------------------------------------------
00281 // For now we assume a 1-1 mapping, and that the board_id is actually the
00282 // plane number, and the chan_id is the cell number
00283 
00284 bool IPNDCMap::CellToChan(int plane, int cell,
00285                         int& board_id, int& chan_id)
00286 {
00287   if (fInstance->CellToChanException(board_id, chan_id, plane, cell))
00288     return true;
00289 
00290   // if no exceptions were found, use algorithmic mapping
00291   board_id = plane;
00292   chan_id = cell;
00293 
00294   return true;
00295 }
00296 
00298 

Generated on Mon Dec 1 02:35:17 2008 for NOvA Offline by  doxygen 1.3.9.1