00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "CalibFormats/SiPixelObjects/interface/PixelPortcardMap.h"
00010
00011 #include <cassert>
00012
00013 using namespace pos;
00014 using namespace std;
00015
00016 PixelPortcardMap::PixelPortcardMap(std::vector< std::vector < std::string> > &tableMat):PixelConfigBase(" "," "," "){
00017
00018 std::vector< std::string > ins = tableMat[0];
00019 std::map<std::string , int > colM;
00020 std::vector<std::string > colNames;
00021 colNames.push_back("CONFIG_KEY_ID" );
00022 colNames.push_back("CONFG_KEY" );
00023 colNames.push_back("VERSION" );
00024 colNames.push_back("KIND_OF_COND" );
00025 colNames.push_back("SERIAL_NUMBER" );
00026 colNames.push_back("PORT_CARD" );
00027 colNames.push_back("PANEL_NAME" );
00028 colNames.push_back("TBM_MODE" );
00029 colNames.push_back("AOH_CHAN" );
00030
00031 for(unsigned int c = 0 ; c < ins.size() ; c++)
00032 {
00033 for(unsigned int n=0; n<colNames.size(); n++)
00034 {
00035 if(tableMat[0][c] == colNames[n])
00036 {
00037 colM[colNames[n]] = c;
00038 break;
00039 }
00040 }
00041 }
00042 for(unsigned int n=0; n<colNames.size(); n++)
00043 {
00044 if(colM.find(colNames[n]) == colM.end())
00045 {
00046 std::cerr << "[PixelPortcardMap::PixelPortcardMap()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00047 assert(0);
00048 }
00049 }
00050
00051
00052
00053 std::string portcardname;
00054 std::string modulename;
00055 unsigned int aoh;
00056 std::string aohstring;
00057 std::string tbmChannel;
00058
00059 for(unsigned int r = 1 ; r < tableMat.size() ; r++){
00060
00061 portcardname = tableMat[r][colM["PORT_CARD"]];
00062 modulename = tableMat[r][colM["PANEL_NAME"]];
00063 aohstring = tableMat[r][colM["AOH_CHAN"]];
00064 tbmChannel = tableMat[r][colM["TBM_MODE"]] ;
00065 cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t "
00066 << "Portcardname: " << portcardname
00067 << "\tmodulename: " << modulename
00068 << "\taohstring: " << aohstring
00069 << "\ttbmChannel:" << tbmChannel
00070 << endl ;
00071
00072 aoh = (((unsigned int)atoi(aohstring.c_str()))+1);
00073
00074 PixelModuleName module(modulename);
00075 if (module.modulename()!=modulename)
00076 {
00077 std::cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t Modulename:"<<modulename<<std::endl;
00078 std::cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t Parsed to:"<<module.modulename()<<std::endl;
00079 assert(0);
00080 }
00081 if(tbmChannel == "")
00082 {
00083 tbmChannel = "A";
00084 }
00085 PixelChannel channel(module, tbmChannel);
00086 std::pair<std::string, int> portcardAndAOH(portcardname, aoh);
00087 map_[channel] = portcardAndAOH;
00088 }
00089
00090
00091 }
00092
00093
00094 PixelPortcardMap::PixelPortcardMap(std::string filename):
00095 PixelConfigBase(" "," "," "){
00096
00097 std::ifstream in(filename.c_str());
00098
00099 if (!in.good()){
00100 std::cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t Could not open: " << filename <<std::endl;
00101 assert(0);
00102 }
00103 else {
00104 std::cout << "[PixelPortcardMap::PixelPortcardMap()]\t\t\t Reading from: " << filename <<std::endl;
00105 }
00106
00107 std::string dummy;
00108
00109 in >> dummy;
00110 in >> dummy;
00111 in >> dummy;
00112 in >> dummy;
00113 in >> dummy;
00114
00115 do {
00116
00117 std::string portcardname;
00118 std::string modulename;
00119 std::string TBMChannel = "A";
00120 std::string aoh_string;
00121 unsigned int aoh;
00122
00123 in >> portcardname >> modulename >> aoh_string ;
00124 if (aoh_string == "A" || aoh_string == "B")
00125 {
00126 TBMChannel = aoh_string;
00127 in >> aoh_string;
00128 }
00129 aoh = atoi(aoh_string.c_str());
00130
00131 if (!in.eof() ){
00132 PixelModuleName module(modulename);
00133 if (module.modulename()!=modulename){
00134 std::cout << "Modulename:"<<modulename<<std::endl;
00135 std::cout << "Parsed to:"<<module.modulename()<<std::endl;
00136 assert(0);
00137 }
00138
00139 PixelChannel channel(module, TBMChannel);
00140 std::pair<std::string, int> portcardAndAOH(portcardname, aoh);
00141 map_[channel] = portcardAndAOH;
00142 }
00143
00144
00145 }while (!in.eof());
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 PixelPortcardMap::~PixelPortcardMap(){}
00161
00162
00163 void PixelPortcardMap::writeASCII(std::string dir) const {
00164
00165
00166 if (dir!="") dir+="/";
00167 string filename=dir+"portcardmap.dat";
00168
00169 ofstream out(filename.c_str());
00170 if(!out.good()){
00171 cout << "Could not open file:"<<filename<<endl;
00172 assert(0);
00173 }
00174
00175 out <<"# Portcard Module AOH channel" <<endl;
00176 std::map< PixelChannel, std::pair<std::string, int> >::const_iterator i=map_.begin();
00177 for(;i!=map_.end();++i){
00178 out << i->second.first<<" "
00179 << i->first.module()<<" "
00180 << i->first.TBMChannel()<<" "
00181 << i->second.second<<endl;
00182 }
00183 out.close();
00184
00185
00186 }
00187
00188
00189
00190 const std::set< std::pair< std::string, int > > PixelPortcardMap::PortCardAndAOHs(const PixelModuleName& aModule) const
00191 {
00192 std::set< std::pair< std::string, int > > returnThis;
00193
00194
00195 for( std::map< PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin(); map_itr != map_.end(); ++map_itr )
00196 {
00197 if ( map_itr->first.modulename() == aModule.modulename() )
00198 {
00199 returnThis.insert(map_itr->second);
00200 }
00201 }
00202
00203 return returnThis;
00204 }
00205
00206 const std::set< std::string > PixelPortcardMap::portcards(const PixelModuleName& aModule) const
00207 {
00208 std::set< std::string > returnThis;
00209 const std::set< std::pair< std::string, int > > portCardAndAOHs = PortCardAndAOHs(aModule);
00210 for ( std::set< std::pair< std::string, int > >::const_iterator portCardAndAOHs_itr = portCardAndAOHs.begin(); portCardAndAOHs_itr != portCardAndAOHs.end(); ++portCardAndAOHs_itr)
00211 {
00212 returnThis.insert( (*portCardAndAOHs_itr).first );
00213 }
00214 return returnThis;
00215 }
00216
00217 const std::pair< std::string, int > PixelPortcardMap::PortCardAndAOH(const PixelModuleName& aModule, const PixelTBMChannel& TBMChannel) const
00218 {
00219 return PortCardAndAOH(PixelChannel(aModule, TBMChannel));
00220 }
00221
00222 const std::pair< std::string, int > PixelPortcardMap::PortCardAndAOH(const PixelModuleName& aModule, const std::string& TBMChannel) const
00223 {
00224 return PortCardAndAOH(PixelChannel(aModule, TBMChannel));
00225 }
00226
00227 const std::pair< std::string, int > PixelPortcardMap::PortCardAndAOH(const PixelChannel& aChannel) const
00228 {
00229 std::map< PixelChannel, std::pair<std::string, int> >::const_iterator found = map_.find(aChannel);
00230 if ( found == map_.end() )
00231 {
00232 std::pair< std::string, int > returnThis("none", 0);
00233 return returnThis;
00234 }
00235 else
00236 {
00237 return found->second;
00238 }
00239 }
00240
00241 std::set< PixelModuleName > PixelPortcardMap::modules(std::string portCardName) const
00242 {
00243 std::set< PixelModuleName > returnThis;
00244
00245
00246 for( std::map< PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin(); map_itr != map_.end(); ++map_itr )
00247 {
00248 if ( map_itr->second.first == portCardName )
00249 {
00250 returnThis.insert(map_itr->first.module());
00251 }
00252 }
00253
00254 return returnThis;
00255 }
00256
00257 std::set< std::string > PixelPortcardMap::portcards()
00258 {
00259 std::set< std::string > returnThis;
00260
00261
00262 for( std::map< PixelChannel, std::pair<std::string, int> >::const_iterator map_itr = map_.begin(); map_itr != map_.end(); ++map_itr )
00263 {
00264 returnThis.insert(map_itr->second.first);
00265 }
00266
00267 return returnThis;
00268 }