00001 #include "Kernel/STChannelID.h"
00002 #include "Kernel/ITNames.h"
00003 #include "boost/lexical_cast.hpp"
00004 #include <iostream>
00005
00006 std::string LHCb::ITNames::UniqueSectorToString(const LHCb::STChannelID& chan) {
00007 std::string theString = UniqueLayerToString(chan) + "Sector" + boost::lexical_cast<std::string>(chan.sector());
00008 return theString;
00009 }
00010
00011 std::string LHCb::ITNames::channelToString(const LHCb::STChannelID& chan) {
00012 std::string theStrip = UniqueSectorToString(chan) + "Strip" + boost::lexical_cast<std::string>(chan.strip());
00013 return theStrip;
00014 }
00015
00016 std::vector<std::string> LHCb::ITNames::stations() {
00017
00018 GaudiUtils::VectorMap<std::string,Station>::iterator iter = s_StationTypMap().begin();
00019 std::vector<std::string> stations; stations.reserve(s_StationTypMap().size());
00020 for ( ;iter != s_StationTypMap().end(); ++iter ){
00021 if (iter->first != "UnknownStation" ) stations.push_back(iter->first);
00022 }
00023
00024 return stations;
00025 }
00026
00027
00028 std::vector<std::string> LHCb::ITNames::allStations() {
00029
00030 return stations();
00031 }
00032
00033
00034 std::vector<std::string> LHCb::ITNames::allBoxes() {
00035
00036 typedef std::vector<std::string> Strings;
00037 Strings stationVec = stations();
00038 Strings boxVec = boxes();
00039 Strings tVector; tVector.reserve(boxVec.size()*stationVec.size());
00040 for (Strings::iterator iterS = stationVec.begin(); iterS != stationVec.end(); ++iterS){
00041 for (Strings::iterator iterB = boxVec.begin(); iterB != boxVec.end(); ++iterB){
00042 std::string temp = (*iterS) + (*iterB) ;
00043 tVector.push_back(temp);
00044 }
00045 }
00046
00047 return tVector;
00048 }
00049
00050 std::vector<std::string> LHCb::ITNames::allLayers() {
00051
00052 typedef std::vector<std::string> Strings;
00053 Strings layerVec = layers();
00054 Strings boxVec = allBoxes();
00055 Strings tVector; tVector.reserve(boxVec.size()*layerVec.size());
00056 for (Strings::iterator iterB = boxVec.begin(); iterB != boxVec.end(); ++iterB){
00057 for (Strings::iterator iterL = layerVec.begin(); iterL != layerVec.end(); ++iterL){
00058 std::string temp = (*iterB) + (*iterL) ;
00059 tVector.push_back(temp);
00060 }
00061 }
00062
00063 return tVector;
00064 }
00065
00066
00067 std::vector<std::string> LHCb::ITNames::boxes() {
00068
00069 GaudiUtils::VectorMap<std::string,Box>::iterator iter = s_BoxTypMap().begin();
00070 std::vector<std::string> boxes; boxes.reserve(s_BoxTypMap().size());
00071 for ( ;iter != s_BoxTypMap().end(); ++iter ){
00072 if (iter->first != "UnknownBox") boxes.push_back(iter->first);
00073 }
00074
00075 return boxes;
00076 }
00077
00078 std::vector<std::string> LHCb::ITNames::layers() {
00079
00080 GaudiUtils::VectorMap<std::string,Layer>::iterator iter = s_LayerTypMap().begin();
00081 std::vector<std::string> layers; layers.reserve(s_LayerTypMap().size());
00082 for ( ;iter != s_LayerTypMap().end(); ++iter ){
00083 if (iter->first != "UnknownLayer") layers.push_back(iter->first);
00084 }
00085
00086 return layers;
00087 }
00088
00089 LHCb::STChannelID LHCb::ITNames::stringToChannel(const std::string& name) {
00090
00091
00092
00093
00094 const std::vector<std::string> thestations = stations();
00095 const unsigned int station = findStationType(name, thestations);
00096
00097 const std::vector<std::string> thelayers = layers();
00098 const unsigned int layer = findLayerType(name, thelayers );
00099
00100 const std::vector<std::string> theboxes = boxes();
00101 const unsigned int box = findBoxType(name, theboxes);
00102
00103
00104 unsigned int strip; unsigned int sector;
00105 std::string::size_type startSector = name.find("Sector");
00106 std::string::size_type startStrip = name.find("Strip");
00107
00108 if (startSector == std::string::npos){
00109 sector = 0;
00110 strip = 0;
00111 }
00112 else if (startStrip == std::string::npos){
00113 strip = 0;
00114 std::string sectorName = name.substr(startSector+6);
00115 sector = toInt(sectorName);
00116 if (sector == 0) {
00117 return STChannelID();
00118 }
00119 }
00120 else {
00121 std::string stripName = name.substr(startStrip+5);
00122 strip = toInt(stripName);
00123 std::string sectorName = name.substr(startSector+6,startStrip - startSector - 6);
00124 sector = toInt(sectorName);
00125 }
00126
00127 return LHCb::STChannelID(LHCb::STChannelID::typeIT, station, layer,
00128 box, sector, strip);
00129 }
00130
00131 unsigned int LHCb::ITNames::findStationType(const std::string& testname,
00132 const std::vector<std::string>& names) {
00133
00134 std::vector<std::string>::const_iterator theName = names.begin();
00135 for ( ; theName != names.end(); ++theName ){
00136 if ( testname.find(*theName) != std::string::npos) {
00137 break;
00138 }
00139 }
00140 return theName == names.end() ? 0 : (unsigned int)StationToType(*theName);
00141 }
00142
00143 unsigned int LHCb::ITNames::findLayerType(const std::string& testname,
00144 const std::vector<std::string>& names) {
00145
00146 std::vector<std::string>::const_iterator theName = names.begin();
00147 for ( ; theName != names.end(); ++theName ){
00148 if ( testname.find(*theName) != std::string::npos) {
00149 break;
00150 }
00151 }
00152 return theName == names.end() ? 0 : (unsigned int)LayerToType(*theName);
00153 }
00154
00155 unsigned int LHCb::ITNames::findBoxType(const std::string& testname,
00156 const std::vector<std::string>& names) {
00157
00158 std::vector<std::string>::const_iterator theName = names.begin();
00159 for ( ; theName != names.end(); ++theName ){
00160 if ( testname.find(*theName) != std::string::npos) {
00161 break;
00162 }
00163 }
00164 return theName == names.end() ? 0 : (unsigned int)BoxToType(*theName);
00165 }
00166
00167
00168 unsigned int LHCb::ITNames::toInt(const std::string& str) {
00169 unsigned int outValue = 0;
00170 try {
00171 outValue = boost::lexical_cast<unsigned int>(str);
00172 }
00173 catch(boost::bad_lexical_cast& e){
00174 outValue = 0;
00175 std::cerr << "ERROR " << e.what() << "** " << str << " **" << std::endl;
00176 }
00177 return outValue;
00178 }