| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TTNames.cpp

Go to the documentation of this file.
00001 
00002 #include "Kernel/STChannelID.h"
00003 #include "Kernel/TTNames.h"
00004 
00005 // BOOST
00006 #include "boost/lexical_cast.hpp"
00007 #include <boost/assign/std/vector.hpp>
00008 #include <boost/assign/list_of.hpp>
00009 
00010 #include <iostream>
00011 
00012 std::string LHCb::TTNames::UniqueSectorToString(const LHCb::STChannelID& chan) {
00013   std::string theString = UniqueRegionToString(chan) + "Sector" + boost::lexical_cast<std::string>(chan.sector());
00014   return theString;
00015 }
00016 
00017 std::vector<std::string> LHCb::TTNames::stations() {
00018 
00019   GaudiUtils::VectorMap<std::string,Station>::iterator iter = s_StationTypMap().begin();
00020   std::vector<std::string> stations; stations.reserve(s_StationTypMap().size());
00021   for ( ;iter != s_StationTypMap().end(); ++iter ){
00022     if (iter->first != "Unknownstation") stations.push_back(iter->first);
00023   } // iter
00024 
00025   return stations;
00026 }
00027 
00028 std::vector<std::string> LHCb::TTNames::detRegions() {
00029 
00030   GaudiUtils::VectorMap<std::string,detRegion>::iterator iter = s_detRegionTypMap().begin();
00031   std::vector<std::string> regions; regions.reserve(s_detRegionTypMap().size());
00032   for ( ;iter != s_detRegionTypMap().end(); ++iter ){
00033     if (iter->first != "UnknownRegion") regions.push_back(iter->first);
00034   } // iter
00035 
00036   return regions;
00037 }
00038 
00039 std::vector<std::string> LHCb::TTNames::layers() {
00040   //messy
00041   std::vector<std::string> layers = boost::assign::list_of("X")("U")("V");
00042   return layers;
00043 }
00044 
00045 std::vector<std::string> LHCb::TTNames::allStations() {
00046 
00047   return stations();
00048 }
00049 
00050 std::vector<std::string> LHCb::TTNames::allDetRegions() {
00051 
00052   typedef std::vector<std::string> Strings;
00053   Strings layers = allLayers();
00054   Strings regions = detRegions(); 
00055   Strings tVector; tVector.reserve(regions.size()*layers.size());
00056   for (Strings::iterator iterL = layers.begin(); iterL != layers.end(); ++iterL){
00057      for (Strings::iterator iterR = regions.begin(); iterR != regions.end(); ++iterR){
00058        std::string temp = (*iterL) + (*iterR) ;
00059        tVector.push_back(temp); 
00060      } // iterB
00061   } // iterS
00062 
00063   return tVector;
00064 }
00065 
00066 std::vector<std::string> LHCb::TTNames::allLayers() {
00067 
00068   typedef std::vector<std::string> Strings;
00069   Strings stationVec = stations(); 
00070    std::vector<std::string> layers = boost::assign::list_of(stationVec[0]+"X")(stationVec[0]+"U")
00071                                     (stationVec[1]+"V")(stationVec[1]+"X");
00072   return layers;
00073 }
00074 
00075 
00076 std::string LHCb::TTNames::UniqueLayerToString(const LHCb::STChannelID& chan) {
00077 
00078   std::string layer = "UnknownLayer";
00079   if (chan.station() == 1){
00080     if ( chan.layer()  == 1){
00081       layer = "X" ;     
00082     } 
00083     else if (chan.layer() == 2) {
00084       layer = "U";
00085     }
00086   } 
00087   else if (chan.station() ==2 ) {
00088     if ( chan.layer()  == 1){
00089       layer = "V" ;     
00090     } 
00091     else if (chan.layer() == 2) {
00092       layer = "X";
00093     }
00094   } 
00095   else {
00096     // nothing
00097   }
00098 
00099   std::string theString = StationToString(chan) + layer;
00100   
00101   return theString;
00102 }
00103 
00104 
00105 std::string LHCb::TTNames::channelToString(const LHCb::STChannelID& chan) {
00106   std::string theStrip = UniqueSectorToString(chan) + "Strip" + boost::lexical_cast<std::string>(chan.strip());
00107   return theStrip;
00108 }  
00109 
00110 LHCb::STChannelID LHCb::TTNames::stringToChannel(const std::string& name)  {
00111 
00112   // convert string to channel
00113 
00114   // get the station, layer and box
00115   const std::vector<std::string> thestations = stations(); 
00116   const unsigned int station = findStationType(name, thestations);
00117  
00118   const std::vector<std::string> thelayers = layers(); 
00119   unsigned int layer = 0;
00120   // station 1, layers U and X
00121   if (station == 1){
00122     if (name.find("X") != std::string::npos){
00123       layer = 1;
00124     }
00125     else if (name.find("U") != std::string::npos){
00126       layer = 2;
00127     }
00128     else {
00129       return STChannelID();
00130     }
00131   }
00132 
00133   if (station == 2){
00134     if (name.find("X") != std::string::npos){
00135       layer = 2;
00136     }
00137     else if (name.find("V") != std::string::npos){
00138       layer = 1;
00139     }
00140     else {
00141       return STChannelID();
00142     }
00143   }
00144 
00145   const std::vector<std::string> theregions = detRegions(); 
00146   const unsigned int region = findRegionType(name, theregions);
00147  
00148   // sector and strip is different
00149   unsigned int strip; unsigned int sector;
00150   std::string::size_type startSector = name.find("Sector");
00151   std::string::size_type startStrip = name.find("Strip");
00152 
00153   if (startSector == std::string::npos){
00154     sector = 0;
00155     strip = 0;
00156   }
00157   else if (startStrip == std::string::npos){
00158     strip = 0;
00159     std::string sectorName = name.substr(startSector+6);
00160     sector = toInt(sectorName);
00161     if (sector == 0) {
00162       return STChannelID(); // invalid sector
00163     }
00164   }
00165   else {
00166     std::string stripName = name.substr(startStrip+5); 
00167     strip = toInt(stripName);
00168     std::string sectorName = name.substr(startSector+6,startStrip - startSector - 6);
00169     sector = toInt(sectorName); 
00170   }
00171 
00172   return LHCb::STChannelID(LHCb::STChannelID::typeIT, station, layer,
00173                            region, sector, strip);
00174 }
00175 
00176 unsigned int LHCb::TTNames::findStationType(const std::string& testname, 
00177                                           const std::vector<std::string>& names) {
00178 
00179   std::vector<std::string>::const_iterator theName = names.begin();
00180   for ( ; theName != names.end(); ++theName ){
00181     if ( testname.find(*theName) != std::string::npos) {
00182       break;
00183     }
00184   } // iterS
00185   return theName == names.end()  ? 0 : (unsigned int)StationToType(*theName);
00186 }
00187 
00188 unsigned int LHCb::TTNames::findRegionType(const std::string& testname, 
00189                                           const std::vector<std::string>& names) {
00190 
00191   std::vector<std::string>::const_iterator theName = names.begin();
00192   for ( ; theName != names.end(); ++theName ){
00193     if ( testname.find(*theName) != std::string::npos) {
00194       break;
00195     }
00196   } // iterS
00197   return theName == names.end()  ? 0 : (unsigned int)detRegionToType(*theName);
00198 }
00199 
00200 
00201 unsigned int LHCb::TTNames::toInt(const std::string& str) {
00202   unsigned int outValue = 0;
00203   try {
00204     outValue = boost::lexical_cast<unsigned int>(str);
00205   }
00206   catch(boost::bad_lexical_cast& e){
00207     outValue = 0;
00208     std::cerr << "ERROR " << e.what() << "** " << str << " **" << std::endl; 
00209   }
00210   return outValue;
00211 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:03:13 2011 for LHCbKernel by doxygen 1.4.7