Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

TkrBadStripsSvc.cxx

Go to the documentation of this file.
00001 
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/SvcFactory.h"
00004 #include "TkrRecon/TkrBadStripsSvc.h"
00005 #include <fstream>
00006 #include <algorithm>
00007 #include <iostream>
00008 
00009 #include "xml/IFile.h"
00010 
00011 static const SvcFactory<TkrBadStripsSvc> s_factory;
00012 const ISvcFactory& TkrBadStripsSvcFactory = s_factory;
00013 
00014 //------------------------------------------------------------------------------
00017 
00018 TkrBadStripsSvc::TkrBadStripsSvc(const std::string& name, ISvcLocator* pSvcLocator) :
00019 Service(name, pSvcLocator)
00020 {
00021     //Name of the file to get data from   
00022     declareProperty("badStripsFile", m_badStripsFile);
00023 
00024     return;     
00025 }
00026 
00027 
00028 StatusCode TkrBadStripsSvc::initialize()
00029 {
00030     bool debug = false;
00031 
00032     MsgStream log(msgSvc(), name());
00033     StatusCode sc = StatusCode::SUCCESS;
00034        
00035     Service::initialize();
00036 
00037         m_badStripsFile = "";
00038 
00039     setProperties();
00040 
00041     //int size = 0;
00042     //makeCol(size); //make sure that Collection is sensibly initialized
00043 
00044     if (m_badStripsFile=="") {        
00045         log << MSG::INFO << "No bad strips file was requested." << endreq;
00046         log << MSG::INFO << "  No strip filtering will be done." << endreq;
00047         return sc;
00048     }
00049 
00050         //test 1
00051         log << MSG::DEBUG << "Test 1"<< endreq;
00052 
00053     xml::IFile::extractEnvVar(&m_badStripsFile);    
00054     log << MSG::INFO << "Input file for bad strips: " << m_badStripsFile << endreq;
00055 
00056         //test 2
00057         log << MSG::DEBUG << "Test 2"<< endreq;
00058 
00059     std::ifstream file;
00060         file.open( m_badStripsFile.c_str());
00061         
00062     if (!file) {
00063         log << MSG::ERROR << "  File not found: check jobOptions." << endreq;
00064         return StatusCode::FAILURE;
00065     }
00066         
00067 
00068     sc = service("TkrGeometrySvc", pTkrGeom, true);
00069     
00070     m_ntowers = pTkrGeom->numYTowers()*pTkrGeom->numYTowers();
00071 
00072     m_nlayers = pTkrGeom->numLayers();
00073     m_nviews  = pTkrGeom->numViews();
00074 
00075     //This is to test that TkrGeometrySvc is initialized... is there a better way?
00076         
00077     if ((m_ntowers<1) || (m_ntowers>25) || (m_nlayers<1) 
00078         || (m_nlayers>20) || (m_nviews != 2)) { 
00079         log << MSG::ERROR << "TkrGeometrySvc must precede BadStripsSvc"
00080             << " in the jobOptions file." << endreq;
00081         return StatusCode::FAILURE;
00082     }//
00083         
00084     //int size = m_ntowers*m_nlayers*m_nviews;    
00085     //makeCol(size);
00086     
00087     readFromFile(&file);
00088         
00089         file.close();
00090         
00091         //log << MSG::DEBUG<< "m_stripsCol has " << 
00092                 //m_stripsCol.size() << " elements" << endreq;
00093         log << MSG::DEBUG<< "m_stripsCol has " << 
00094                 576 << " elements" << endreq;
00095     /*
00096         for (int i = 0; i < m_stripsCol.size(); i++) {
00097                 log << "Element " << i << ": " ;
00098                 v_strips v = m_stripsCol[i];
00099                 log << MSG::DEBUG << v.size() << " strips" << endreq;
00100                 for (int j = 0; j < v.size(); j++) {
00101                         log << v[j] << " " ;
00102                 }
00103                 log << MSG::DEBUG << endreq;
00104         }
00105         */
00106            
00107     return sc;
00108 }
00109 
00110 
00111 StatusCode TkrBadStripsSvc::finalize()
00112 {
00113     return StatusCode::SUCCESS;
00114 }
00115 
00116 
00117 /*void TkrBadStripsSvc::makeCol(const int size)
00118 {
00119   //    m_stripsCol.assign(size);
00120   //  return;
00121 }
00122 */
00123 
00124 
00125 void TkrBadStripsSvc::readFromFile(std::ifstream* file)
00126 {    
00127     bool debug = false;
00128         bool read = true;
00129         bool makestrips = true;
00130 
00131     MsgStream log(msgSvc(), name());
00132     
00133     int nStrips = 0;
00134         std::string junk;
00135 
00136     while(read && !file->eof()) {
00137         int tower;
00138                 int sequence;
00139 
00140         *file >> tower ;
00141                 if(tower==-1) { // comment line, just skip 
00142                         std::getline(*file, junk);
00143                         continue;
00144                 }
00145         if (file->eof()) break;
00146         *file >> sequence;
00147         // kludge until the geometry supplies this info
00148                 int layer = sequence/2;
00149                 int element = (sequence+3)%4;
00150                 int view = element/2;
00151 
00152         v_strips* v;
00153         if (makestrips) v = getBadStrips(tower, layer, (TkrAxis::axis) view);
00154         int strip = -1;
00155         *file >>  strip;
00156         while (strip>=0) {
00157             if (makestrips) addStrip(v, strip);
00158             *file >> strip;
00159             nStrips++;
00160         }
00161 
00162         if (makestrips) std::sort(v->begin(), v->end());
00163         
00164     }
00165     log << MSG::INFO << nStrips << " bad strips read from file" << endreq;
00166    
00167     return;
00168 }
00169 
00170 
00171 int TkrBadStripsSvc::getIndex(const int tower, const int layer, const TkrAxis::axis axis) 
00172 {
00173     int view; 
00174     // this is to decouple the store from the current definition of axes
00175     // not that it will ever change
00176     if (axis==TkrAxis::X)  {view = 0;}
00177     else if (axis==TkrAxis::Y) {view = 1;}
00178     else {return 0;}
00179     return view + m_nviews*(layer + m_nlayers*tower);
00180 }
00181 
00182 
00183 void TkrBadStripsSvc::addStrip(v_strips* v, const int strip) {
00184     int tagged_strip = tagBad(strip);
00185     v->push_back(tagged_strip);
00186     int size = v->size();
00187     int capa = v->capacity();
00188     return;
00189 }
00190 
00191 
00192 v_strips* TkrBadStripsSvc::getBadStrips(const int tower, const int layer, const TkrAxis::axis axis)
00193 {
00194     int index = getIndex(tower, layer, axis);
00195 
00196     return getBadStrips(index);
00197 }
00198 
00199 
00200 v_strips* TkrBadStripsSvc::getBadStrips(const int index)
00201 {
00202     //int ind = (m_stripsCol.size()==0) ? m_stripsCol.size() : index;
00203     int ind = (index<0 || index>575) ? 0 : index;
00204     return &m_stripsCol[ind];
00205 }
00206 
00207 
00208 int TkrBadStripsSvc::tagBad(const int strip) 
00209 {
00210     return (strip << 1) | 1;
00211 }
00212 
00213 
00214 int TkrBadStripsSvc::tagGood(const int strip) 
00215 {
00216     return (strip << 1);
00217 }
00218 
00219 
00220 int TkrBadStripsSvc::untag(const int strip) 
00221 {
00222     return (strip >> 1);
00223 }
00224 
00225 
00226 bool TkrBadStripsSvc::isTaggedBad(const int taggedStrip) {
00227     return ((taggedStrip & 1) != 0);
00228 }
00229 
00230 
00231 bool TkrBadStripsSvc::isBadStrip(const int tower, const int layer, 
00232                                  const TkrAxis::axis axis, const int strip) 
00233 {
00234     v_strips* v = getBadStrips(tower, layer, axis);
00235     return isBadStrip(v, strip);
00236 }
00237 
00238 bool TkrBadStripsSvc::isBadStrip(const v_strips* v, const int strip)
00239 {
00240     v_strips_it it = std::find(v->begin(), v->end(), tagBad(strip));
00241     return (it!=v->end());
00242 }
00243 
00244 
00245 
00246 // queryInterface
00247 
00248 StatusCode  TkrBadStripsSvc::queryInterface (const IID& riid, void **ppvIF)
00249 {
00250     if (IID_ITkrBadStripsSvc == riid) {
00251         *ppvIF = dynamic_cast<ITkrBadStripsSvc*> (this);
00252     }
00253     else {
00254         return Service::queryInterface (riid, ppvIF);
00255     }
00256     //addRef(); 
00257     return StatusCode::SUCCESS;
00258 }
00259 
00260 // access the type of this service
00261 
00262 const IID&  TkrBadStripsSvc::type () const {
00263     return IID_ITkrBadStripsSvc;
00264 }

Generated at Wed Nov 21 12:21:21 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000