CMS 3D CMS Logo

PixelNameTranslation.cc

Go to the documentation of this file.
00001 //
00002 // This class stores the name and related
00003 // hardware mapings for a ROC 
00004 //
00005 //
00006 
00007 #include "CalibFormats/SiPixelObjects/interface/PixelNameTranslation.h"
00008 #include "CalibFormats/SiPixelObjects/interface/PixelDetectorConfig.h"
00009 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00010 #include <fstream>
00011 #include <sstream>
00012 #include <map>
00013 #include <string>
00014 #include <vector>
00015 #include <assert.h>
00016 
00017 using namespace pos;
00018 using namespace std;
00019 
00020 
00021 PixelNameTranslation::PixelNameTranslation(std::vector< std::vector<std::string> > &tableMat):PixelConfigBase(" "," "," "){
00022   std::map<std::string , int > colM;
00023   std::vector<std::string > colNames;
00024   colNames.push_back("CONFIG_KEY_ID" );//0
00025   colNames.push_back("CONFIG_KEY"    );//1
00026   colNames.push_back("VERSION"       );//2
00027   colNames.push_back("KIND_OF_COND"  );//3
00028   colNames.push_back("SERIAL_NUMBER" );//4
00029   colNames.push_back("ROC_NAME"      );//5
00030   colNames.push_back("TBM_MODE"      );//6  
00031   colNames.push_back("PXLFEC_NAME"   );//7  
00032   colNames.push_back("MFEC_POSN"     );//8  
00033   colNames.push_back("MFEC_CHAN"     );//9  
00034   colNames.push_back("HUB_ADDRS"     );//10 
00035   colNames.push_back("PORT_NUM"      );//11 
00036   colNames.push_back("ROC_I2C_ADDR"  );//12 
00037   colNames.push_back("PXLFED_NAME"   );//13 
00038   colNames.push_back("FED_CHAN"      );//14 
00039   colNames.push_back("FED_ROC_NUM"   );//15
00040 
00041 
00042   for(unsigned int c = 0 ; c < tableMat[0].size() ; c++){
00043     for(unsigned int n=0; n<colNames.size(); n++){
00044       if(tableMat[0][c] == colNames[n]){
00045         colM[colNames[n]] = c;
00046         break;
00047       }
00048     }
00049   }//end for
00050   for(unsigned int n=0; n<colNames.size(); n++){
00051     if(colM.find(colNames[n]) == colM.end()){
00052       std::cerr << "[PixelNameTranslation::PixelNameTranslation()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00053       assert(0);
00054     }
00055   }
00056  
00057 
00058  for(unsigned int r = 1 ; r < tableMat.size() ; r++){    //Goes to every row of the Matrix
00059    std::string rocname       = tableMat[r][colM["ROC_NAME"]] ;
00060    std::string TBMChannel    = tableMat[r][colM["TBM_MODE"]] ; // assert(0); // need to add this to the input table
00061    if(TBMChannel == "")
00062      {
00063        TBMChannel = "A" ;
00064      }
00065    /* // modified by MR on 13-07-2008 11:32:50
00066       Umesh changed the content of the column and 
00067       stripped out the FPix_Pxl_FEC_ part of the "number"
00068    tableMat[r][colM["PXLFEC_NAME"]].erase(0 , 13);//PIXFEC
00069    unsigned int fecnumber    = (unsigned int)atoi(tableMat[r][colM["PXLFEC_NAME"]].c_str());
00070    */
00071    unsigned int fecnumber    = (unsigned int)atoi(tableMat[r][colM["PXLFEC_NAME"]].c_str());
00072    unsigned int mfec         = (unsigned int)atoi(tableMat[r][colM["MFEC_POSN"]].c_str());
00073    unsigned int mfecchannel  = (unsigned int)atoi(tableMat[r][colM["MFEC_CHAN"]].c_str());
00074    unsigned int hubaddress   = (unsigned int)atoi(tableMat[r][colM["HUB_ADDRS"]].c_str());
00075    unsigned int portaddress  = (unsigned int)atoi(tableMat[r][colM["PORT_NUM"]].c_str());
00076    unsigned int rocid        = (unsigned int)atoi(tableMat[r][colM["ROC_I2C_ADDR"]].c_str());
00077    // modified by MR on 13-07-2008 11:47:32
00078    /* Umesh changed the content of the column and 
00079       stripped out the PxlFED_ part of the "number"
00080      
00081    tableMat[r][colM["PXLFED_NAME"]].erase(0,7);//FED
00082    */
00083    unsigned int fednumber    = (unsigned int)atoi(tableMat[r][colM["PXLFED_NAME"]].c_str());
00084    unsigned int fedchannel   = (unsigned int)atoi(tableMat[r][colM["FED_CHAN"]].c_str());
00085    unsigned int fedrocnumber = (unsigned int)(atoi(tableMat[r][colM["FED_ROC_NUM"]].c_str())-1);
00086         
00087         
00088    PixelROCName aROC(rocname);
00089    if (aROC.rocname()!=rocname){
00090      std::cout << "[PixelNameTranslation::PixelNameTranslation()]\tRocname:"<<rocname<<std::endl;
00091      std::cout << "[PixelNameTranslation::PixelNameTranslation()]\tParsed to:"<<aROC.rocname()<<std::endl;
00092      assert(0);
00093    }
00094    PixelHdwAddress hdwAdd(fecnumber,mfec,mfecchannel,
00095                           hubaddress,portaddress,
00096                           rocid,
00097                           fednumber,fedchannel,fedrocnumber);
00098 //    std::cout << "[PixelNameTranslation::PixelNameTranslation()] aROC: " << aROC << std::endl;
00099    translationtable_[aROC]=hdwAdd;
00100    
00101    PixelModuleName aModule(rocname);
00102    
00103             PixelChannel aChannel(aModule, TBMChannel);
00104             // Look for this channel in channelTransaltionTable.  If it is found, check that the hardware address agrees.  If not, add it to the table.  Also, if another channel on that module is found, check that the FEC part agrees, and the FED part doesn't.
00105             bool foundChannel = false;
00106             for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00107             {
00108                 if ( channelTranslationTable_itr->first == aChannel )
00109                 {
00110                    assert( channelTranslationTable_itr->second |= hdwAdd );
00111                    foundChannel = true;
00112                 }
00113                 else if ( channelTranslationTable_itr->first.module() == aModule )
00114                 {
00115                    assert( channelTranslationTable_itr->second.fecnumber() == hdwAdd.fecnumber() );
00116                    assert( channelTranslationTable_itr->second.mfec() == hdwAdd.mfec() );
00117                    assert( channelTranslationTable_itr->second.mfecchannel() == hdwAdd.mfecchannel() );
00118                    //assert( channelTranslationTable_itr->second.portaddress() == hdwAdd.portaddress() );
00119                    assert( channelTranslationTable_itr->second.hubaddress() == hdwAdd.hubaddress() );
00120                    assert( channelTranslationTable_itr->second.fednumber() != hdwAdd.fednumber() || channelTranslationTable_itr->second.fedchannel() != hdwAdd.fedchannel() );
00121                 }
00122             }
00123             if ( foundChannel == false ) channelTranslationTable_[aChannel] = hdwAdd;
00124             
00125   }//end for r
00126 }//end contructor
00127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00128 
00129 PixelNameTranslation::PixelNameTranslation(std::string filename):
00130   PixelConfigBase(" "," "," "){
00131 
00132   std::ifstream in(filename.c_str());
00133   
00134   if (!in.good()){
00135     std::cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t    Could not open: " << filename <<std::endl;
00136     assert(0);
00137   }
00138   else {
00139     std::cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t    Reading from: "   << filename <<std::endl;
00140   }
00141   
00142   std::string dummy;
00143   
00144   getline(in, dummy); // skip the column headings
00145   
00146   do {
00147         
00148     std::string rocname;
00149     std::string TBMChannel;
00150     unsigned int fecnumber;
00151     unsigned int mfec;
00152     unsigned int mfecchannel;
00153     unsigned int hubaddress;
00154     unsigned int portaddress;
00155     unsigned int rocid;
00156     unsigned int fednumber;
00157     unsigned int fedchannel;
00158     unsigned int fedrocnumber;
00159 
00160     in >> rocname;
00161     in >> TBMChannel;
00162     if ( TBMChannel != "A" && TBMChannel != "B" ) // no TBM channel was specified, so default to A and set fecnumber to the value of this string
00163       {
00164         fecnumber = atoi(TBMChannel.c_str());
00165         TBMChannel = "A";
00166       }
00167     else // TBM channel was specified, now read fecnumber
00168       {
00169         in >> fecnumber;
00170       }
00171     in >> mfec >> mfecchannel 
00172        >> hubaddress >> portaddress >> rocid >> fednumber 
00173        >> fedchannel >> fedrocnumber;
00174 
00175     if (!in.eof() ){
00176       PixelROCName aROC(rocname);
00177       if (aROC.rocname()!=rocname){
00178         std::cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t    Rocname  : "<<rocname<<std::endl;
00179         std::cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t    Parsed to: "<<aROC.rocname()<<std::endl;
00180         assert(0);
00181       }
00182 
00183       
00184       if (ROCNameFromFEDChannelROCExists(fednumber,fedchannel,
00185                                          fedrocnumber)){
00186         std::cout << "ROC with fednumber="<<fednumber
00187                   << " fedchannel="<<fedchannel
00188                   << " roc number="<<fedrocnumber
00189                   << " already exists"<<std::endl;
00190         std::cout << "Fix this inconsistency in the name translation"
00191                   << std::endl;
00192         assert(0);
00193         
00194       }
00195 
00196       
00197 
00198       PixelHdwAddress hdwAdd(fecnumber,mfec,mfecchannel,
00199                              hubaddress,portaddress,
00200                              rocid,
00201                              fednumber,fedchannel,fedrocnumber);
00202       //std::cout << aROC << std::endl;
00203       // modified by MR on 18-01-2008 11:18:53
00204       //       std::cout << hdwAdd << std::endl ;
00205 //cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t-----------------------------"  << endl ;
00206 // A fecnumber    
00207 // B mfec         
00208 // C mfecchannel  
00209 // D hubaddress   
00210 // E portaddress  
00211 // F rocid        
00212 // G fednumber    
00213 // H fedchannel   
00214 // I fedrocnumber 
00215 //cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t"
00216 //     << " A " << fecnumber   
00217 //     << " B " << mfec       
00218 //     << " C " << mfecchannel  
00219 //     << " D " << hubaddress   
00220 //     << " E " << portaddress  
00221 //     << " F " << rocid        
00222 //     << " G " << fednumber    
00223 //     << " H " << fedchannel   
00224 //     << " I " << fedrocnumber << endl ;    
00225       translationtable_[aROC]=hdwAdd;
00226       fedlookup_[hdwAdd]=aROC;
00227             
00228       PixelModuleName aModule(rocname);
00229       PixelChannel aChannel(aModule, TBMChannel);
00230       // Look for this channel in channelTransaltionTable.  If it is found, 
00231       // check that the hardware address agrees.  If not, add it to the table.
00232       // Also, if another channel on that module is found, check that the FEC 
00233       // part agrees, and the FED part doesn't.
00234       bool foundChannel = false;
00235 
00236       for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ ) {
00237 
00238         if ( channelTranslationTable_itr->first == aChannel ) {
00239           if (!(channelTranslationTable_itr->second |= hdwAdd)){
00240                 
00241             cout << "Found two ROCs on the same channe, but not same hdw"<<endl;
00242             cout << "Hdw1:"<<endl<<channelTranslationTable_itr->second<<endl;
00243             cout << "Hdw2:"<<endl<<hdwAdd<<endl;
00244           }
00245           assert( channelTranslationTable_itr->second |= hdwAdd );
00246           foundChannel = true;
00247         }
00248         else if ( channelTranslationTable_itr->first.module() == aModule ) {
00249           assert( channelTranslationTable_itr->second.fecnumber() == hdwAdd.fecnumber() );
00250           assert( channelTranslationTable_itr->second.mfec() == hdwAdd.mfec() );
00251           assert( channelTranslationTable_itr->second.mfecchannel() == hdwAdd.mfecchannel() );
00252           //assert( channelTranslationTable_itr->second.portaddress() == hdwAdd.portaddress() );
00253           assert( channelTranslationTable_itr->second.hubaddress() == hdwAdd.hubaddress() );
00254           assert( channelTranslationTable_itr->second.fednumber() != hdwAdd.fednumber() || channelTranslationTable_itr->second.fedchannel() != hdwAdd.fedchannel() );
00255         }
00256       }
00257       if ( foundChannel == false )      channelTranslationTable_[aChannel] = hdwAdd;
00258     }
00259   }
00260   while (!in.eof());
00261   in.close();
00262 
00263 }
00264 
00265 std::ostream& operator<<(std::ostream& s, const PixelNameTranslation& table){
00266 
00267   //for (unsigned int i=0;i<table.translationtable_.size();i++){
00268   //    s << table.translationtable_[i]<<std::endl;
00269   //   }
00270   return s;
00271 
00272 }
00273 
00274 std::list<const PixelROCName*> PixelNameTranslation::getROCs() const
00275 {
00276   std::list<const PixelROCName*> listOfROCs;
00277   for ( std::map<PixelROCName, PixelHdwAddress>::const_iterator translationTableEntry = translationtable_.begin();
00278         translationTableEntry != translationtable_.end(); ++translationTableEntry ) {
00279     listOfROCs.push_back(&(translationTableEntry->first));
00280   }
00281 
00282   return listOfROCs;
00283 }
00284 
00285 std::list<const PixelModuleName*> PixelNameTranslation::getModules() const
00286 {
00287   std::list<const PixelModuleName*> listOfModules;
00288   for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00289     {
00290       bool foundOne = false;
00291       for ( std::list<const PixelModuleName*>::const_iterator listOfModules_itr = listOfModules.begin(); listOfModules_itr != listOfModules.end(); listOfModules_itr++ )
00292         {
00293           if ( *(*listOfModules_itr) == channelTranslationTable_itr->first.module() )
00294             {
00295               foundOne = true;
00296               break;
00297             }
00298         }
00299       if (!foundOne) listOfModules.push_back( &(channelTranslationTable_itr->first.module()) );
00300     }
00301 
00302   return listOfModules;
00303 }
00304 
00305 std::set<PixelChannel> PixelNameTranslation::getChannels() const
00306 {
00307   std::set<PixelChannel> channelSet;
00308   for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00309     {
00310       channelSet.insert(channelTranslationTable_itr->first);
00311     }
00312   return channelSet;
00313 }
00314 
00315 std::set<PixelChannel> PixelNameTranslation::getChannels(const PixelDetectorConfig& aDetectorConfig) const
00316 {
00317   std::set<PixelChannel> channelSet;
00318   for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00319     {
00320       if ( aDetectorConfig.containsModule(channelTranslationTable_itr->first.module()) ) channelSet.insert(channelTranslationTable_itr->first);
00321     }
00322   return channelSet;
00323 }
00324 
00325 const PixelHdwAddress* PixelNameTranslation::getHdwAddress(const PixelROCName& aROC) const{
00326 
00327   if (translationtable_.find(aROC)==translationtable_.end()){
00328     std::cout<<"Could not look up ROC:"<<aROC<<std::endl;
00329     assert(0);
00330   }
00331     
00332   return &(translationtable_.find(aROC))->second;
00333 
00334 }
00335 
00336 const PixelHdwAddress& PixelNameTranslation::getHdwAddress(const PixelChannel& aChannel) const
00337 {
00338   std::map<PixelChannel, PixelHdwAddress >::const_iterator channelHdwAddress_itr = channelTranslationTable_.find(aChannel);
00339   assert( channelHdwAddress_itr != channelTranslationTable_.end() );
00340   return channelHdwAddress_itr->second;
00341 }
00342 
00343 const PixelHdwAddress& PixelNameTranslation::firstHdwAddress(const PixelModuleName& aModule) const
00344 {
00345         std::set<PixelChannel> channelsOnModule = getChannelsOnModule(aModule);
00346         if (channelsOnModule.size() == 0 ){
00347           cout << "[PixelNameTranslation::firstHdwAddress] module="<<aModule<<" has zero channels!"<<endl;
00348           cout << "Will terminate" <<endl;
00349           ::abort();
00350         }
00351         std::set<PixelChannel>::const_iterator firstChannel = channelsOnModule.begin();
00352         assert( firstChannel != channelsOnModule.end() );
00353         return getHdwAddress( *firstChannel );
00354 }
00355 
00356 const PixelChannel& PixelNameTranslation::getChannelForROC(const PixelROCName& aROC) const
00357 {
00358   std::map<PixelROCName,PixelHdwAddress>::const_iterator foundEntry = translationtable_.find(aROC);
00359   assert( foundEntry != translationtable_.end() );
00360   return getChannelFromHdwAddress( foundEntry->second );
00361 }
00362 
00363 std::set< PixelChannel > PixelNameTranslation::getChannelsOnModule(const PixelModuleName& aModule) const
00364 {
00365   std::set< PixelChannel > returnThis;
00366   for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00367     {
00368       if ( channelTranslationTable_itr->first.module() == aModule ) returnThis.insert(channelTranslationTable_itr->first);
00369     }
00370   assert( returnThis.size() <= 2 );
00371   return returnThis;
00372 }
00373 
00374 
00375 //Will return ROC names sorted by FED readout order.
00376 std::vector<PixelROCName> PixelNameTranslation::getROCsFromFEDChannel(unsigned int fednumber, 
00377                                                                       unsigned int fedchannel) const{
00378 
00379   //FIXME this should have a proper map to directly look up things in!
00380 
00381   std::vector<PixelROCName> tmp(24);
00382 
00383   int counter=0;        
00384 
00385   int maxindex=0;
00386 
00387   std::map<PixelROCName,PixelHdwAddress>::const_iterator it=translationtable_.begin();
00388     
00389   for(;it!=translationtable_.end();it++){
00390 
00391     if (it->second.fednumber()==fednumber&&
00392         it->second.fedchannel()==fedchannel){
00393       int index=it->second.fedrocnumber();
00394       if (index>maxindex) maxindex=index;
00395       //std::cout << "Found one:"<<index<<" "<<it->first<<std::endl;
00396       tmp[index]=it->first;
00397       counter++;
00398     }
00399 
00400   }
00401 
00402   assert(counter==maxindex+1);
00403 
00404   tmp.resize(counter);
00405 
00406   return tmp;
00407 
00408 }
00409 
00410 
00411 bool PixelNameTranslation::ROCNameFromFEDChannelROCExists(unsigned int fednumber, 
00412                                                           unsigned int channel, 
00413                                                           unsigned int roc) const {
00414 
00415 
00416   PixelHdwAddress tmp(0,0,0,0,0,0,fednumber,channel,roc);
00417 
00418   std::map<PixelHdwAddress,PixelROCName,PixelHdwAddress>::const_iterator it1=fedlookup_.find(tmp);
00419 
00420   return (it1!=fedlookup_.end());
00421 
00422 }
00423 
00424 
00425 PixelROCName PixelNameTranslation::ROCNameFromFEDChannelROC(unsigned int fednumber, 
00426                                                             unsigned int channel, 
00427                                                             unsigned int roc) const {
00428 
00429 
00430   PixelHdwAddress tmp(0,0,0,0,0,0,fednumber,channel,roc);
00431 
00432   std::map<PixelHdwAddress,PixelROCName,PixelHdwAddress>::const_iterator it1=fedlookup_.find(tmp);
00433 
00434   if (it1!=fedlookup_.end()){
00435     return it1->second;
00436   }
00437 
00438   std::cout << "PixelNameTranslation::ROCNameFromFEDChannelROC: could not find ROCName "
00439             << " for FED#" << fednumber <<" chan=" << channel << " roc#=" << roc << std::endl;
00440 
00441   assert(0);
00442 
00443   PixelROCName tmp1;
00444 
00445   return tmp1;
00446 
00447 }
00448 
00449 PixelChannel PixelNameTranslation::ChannelFromFEDChannel(unsigned int fednumber, unsigned int fedchannel) const
00450 {
00451         std::map<PixelChannel,PixelHdwAddress>::const_iterator toReturn;
00452         bool foundOne = false;
00453         for(std::map<PixelChannel,PixelHdwAddress>::const_iterator it=channelTranslationTable_.begin(); it!=channelTranslationTable_.end();it++)
00454         {
00455                 if (it->second.fednumber()==fednumber && it->second.fedchannel()==fedchannel)
00456                 {
00457                         if ( foundOne )
00458                         {
00459                                 std::cout << "ERROR: multiple channels on FED#" << fednumber <<", chan=" << fedchannel << std::endl;
00460                                 assert(0);
00461                         }
00462                         else
00463                         {
00464                                 toReturn = it;
00465                                 foundOne = true;
00466                         }
00467                 }
00468         }
00469         
00470         if ( !foundOne )
00471         {
00472                 std::cout << "ERROR: no channel found for FED#" << fednumber <<", chan=" << fedchannel << std::endl;
00473                 assert(0);
00474         }
00475         
00476         return toReturn->first;
00477 }
00478 
00479 bool PixelNameTranslation::FEDChannelExist(unsigned int fednumber, unsigned int fedchannel) const
00480 {
00481         std::map<PixelChannel,PixelHdwAddress>::const_iterator toReturn;
00482         bool foundOne = false;
00483         for(std::map<PixelChannel,PixelHdwAddress>::const_iterator it=channelTranslationTable_.begin(); it!=channelTranslationTable_.end();it++)
00484         {
00485                 if (it->second.fednumber()==fednumber && it->second.fedchannel()==fedchannel)
00486                 {
00487                         if ( foundOne )
00488                         {
00489                                 std::cout << "ERROR: multiple channels on FED#" << fednumber <<", chan=" << fedchannel << std::endl;
00490                                 assert(0);
00491                         }
00492                         else
00493                         {
00494                                 toReturn = it;
00495                                 foundOne = true;
00496                         }
00497                 }
00498         }
00499         return foundOne;
00500 }
00501 
00502 const PixelChannel& PixelNameTranslation::getChannelFromHdwAddress(const PixelHdwAddress& aHdwAddress) const
00503 {
00504 // modified by MR on 30-01-2008 10:38:22
00505   for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin(); 
00506         channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
00507     {
00508       if ( aHdwAddress |= channelTranslationTable_itr->second )
00509         {
00510           return channelTranslationTable_itr->first;
00511         }
00512     }
00513 // modified by MR on 30-01-2008 13:56:34
00514 // if you get here then there was NO match on the previous loop!!
00515   std::cout << "[PixelNameTranslation::getChannelFromHdwAddress()]\tERROR: no channel found for hardware address " << aHdwAddress << std::endl;
00516   assert(0);
00517 }
00518 
00519 void PixelNameTranslation::writeASCII(std::string dir) const {
00520 
00521   if (dir!="") dir+="/";
00522   std::string filename=dir+"translation.dat";
00523 
00524   std::ofstream out(filename.c_str());
00525   
00526   //std::cout << "[PixelNameTranslation::writeASCII()]\t\tfilename: " 
00527   //        << filename 
00528   //        << " status: " 
00529   //        << out 
00530   //        << "   " 
00531   //        << out.is_open() 
00532   //        <<endl ;
00533 
00534   out << "# name                          TBMchannel  FEC      mfec  mfecchannel hubaddress portadd rocid     FED     channel     roc#"<<endl;
00535 
00536   std::map<PixelROCName,PixelHdwAddress>::const_iterator iroc=translationtable_.begin();
00537 
00538   for (;iroc!=translationtable_.end();++iroc) {
00539   
00540     // Find the PixelChannel for this ROC, in order to get the TBM channel.
00541     std::string TBMChannel = getChannelFromHdwAddress(iroc->second).TBMChannelString();
00542   
00543     out << iroc->first.rocname()<<"       "
00544         << TBMChannel<<"       "
00545         << iroc->second.fecnumber()<<"       "
00546         << iroc->second.mfec()<<"       "
00547         << iroc->second.mfecchannel()<<"       "
00548         << iroc->second.hubaddress()<<"       "
00549         << iroc->second.portaddress()<<"       "
00550         << iroc->second.rocid()<<"         "
00551         << iroc->second.fednumber()<<"       "
00552         << iroc->second.fedchannel()<<"       "
00553         << iroc->second.fedrocnumber()
00554         << endl;
00555   }
00556 
00557 
00558 
00559   out.close();
00560 
00561 }
00562 
00563 //=============================================================================================
00564 void PixelNameTranslation::writeXML(pos::PixelConfigKey key, int version, std::string path) const {
00565   std::string mthn = "[PixelNameTranslation::writeXML]\t\t\t    " ;
00566   std::stringstream fullPath ;
00567 
00568   fullPath << path << "/nametranslation.xml" ;
00569   cout << mthn << "Writing to: |" << fullPath.str()  << "|" << endl ;
00570   
00571   std::ofstream out(fullPath.str().c_str()) ;
00572 
00573   out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                    << endl ;
00574   out << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>"                               << endl ;
00575   out << ""                                                                                           << endl ;
00576   out << " <HEADER>"                                                                                  << endl ;
00577   out << "  <TYPE>"                                                                                   << endl ;
00578   out << "   <EXTENSION_TABLE_NAME>FPIX_NAME_TRANSLATION</EXTENSION_TABLE_NAME>"                      << endl ;
00579   out << "   <NAME>FPix Name Translation</NAME>"                                                      << endl ;
00580   out << "  </TYPE>"                                                                                  << endl ;
00581   out << "  <RUN>"                                                                                    << endl ;
00582   out << "   <RUN_TYPE>test</RUN_TYPE>"                                                               << endl ;
00583   out << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                              << endl ;
00584   out << "   <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl ;
00585   out << "   <COMMENT_DESCRIPTION>Test of Name Translation xml</COMMENT_DESCRIPTION>"                 << endl ;
00586   out << "   <LOCATION>CERN TAC</LOCATION>"                                                           << endl ;
00587   out << "   <INITIATED_BY_USER>Dario Menasce</INITIATED_BY_USER>"                                    << endl ;
00588   out << "  </RUN>"                                                                                   << endl ;
00589   out << " </HEADER>"                                                                                 << endl ;
00590   out << ""                                                                                           << endl ;
00591   out << " <DATA_SET>"                                                                                << endl ;
00592   out << "  <VERSION>" << version << "</VERSION>"                                                     << endl ;
00593   out << "  <PART>"                                                                                   << endl ;
00594   out << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                                 << endl ;
00595   out << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                              << endl ;
00596   out << "  </PART>"                                                                                  << endl ;
00597   out << ""                                                                                           << endl ;
00598 
00599   std::map<PixelROCName,PixelHdwAddress>::const_iterator iroc=translationtable_.begin();
00600 
00601   for (;iroc!=translationtable_.end();++iroc) 
00602     {
00603       // Find the PixelChannel for this ROC, in order to get the TBM channel.
00604       std::string TBMChannel = getChannelFromHdwAddress(iroc->second).TBMChannelString();
00605 
00606       out << "  <DATA>"                                                                               << endl ;
00607       out << "   <PXLFEC_NAME>"  << iroc->second.fecnumber()    << "</PXLFEC_NAME>"                   << endl ;
00608       out << "   <MFEC_POSN>"    << iroc->second.mfec()         << "</MFEC_POSN>"                     << endl ;
00609       out << "   <MFEC_CHAN>"    << iroc->second.mfecchannel()  << "</MFEC_CHAN>"                     << endl ;
00610       out << "   <HUB_ADDRS>"    << iroc->second.hubaddress()   << "</HUB_ADDRS>"                     << endl ;
00611       out << "   <PORT_NUM>"     << iroc->second.portaddress()  << "</PORT_NUM>"                      << endl ;
00612       out << "   <ROC_I2C_ADDR>" << iroc->second.rocid()        << "</ROC_I2C_ADDR>"                  << endl ;
00613       out << "   <PXLFED_NAME>"  << iroc->second.fednumber()    << "</PXLFED_NAME>"                   << endl ;
00614       out << "   <FED_CHAN>"     << iroc->second.fedchannel()   << "</FED_CHAN>"                      << endl ;
00615       out << "   <FED_ROC_NUM>"  << iroc->second.fedrocnumber() << "</FED_ROC_NUM>"                   << endl ;
00616       out << "  </DATA>"                                                                              << endl ;
00617       out << ""                                                                                       << endl ;
00618     }
00619   out << " </DATA_SET> "                                                                              << endl ;
00620   out << "</ROOT> "                                                                                   << endl ;
00621   out.close() ;
00622   assert(0) ;
00623 }
00624 
00625 std::vector<PixelROCName> PixelNameTranslation::getROCsFromChannel(const PixelChannel& aChannel) const
00626 {
00627   const PixelHdwAddress& channelHdwAddress = getHdwAddress(aChannel);
00628   return getROCsFromFEDChannel( channelHdwAddress.fednumber(), channelHdwAddress.fedchannel() );
00629 }
00630 
00631 std::vector<PixelROCName> PixelNameTranslation::getROCsFromModule(const PixelModuleName& aModule) const
00632 {
00633   std::vector<PixelROCName> returnThis;
00634         
00635   std::set<PixelChannel> channelsOnThisModule = getChannelsOnModule(aModule);
00636   for ( std::set<PixelChannel>::const_iterator channelsOnThisModule_itr = channelsOnThisModule.begin(); channelsOnThisModule_itr != channelsOnThisModule.end(); channelsOnThisModule_itr++ )
00637     {
00638       std::vector<PixelROCName> ROCsOnThisChannel = getROCsFromChannel( *channelsOnThisModule_itr );
00639       for ( std::vector<PixelROCName>::const_iterator ROCsOnThisChannel_itr = ROCsOnThisChannel.begin(); ROCsOnThisChannel_itr != ROCsOnThisChannel.end(); ROCsOnThisChannel_itr++ )
00640         {
00641           returnThis.push_back(*ROCsOnThisChannel_itr);
00642         }
00643     }
00644 
00645   return returnThis;
00646 }
00647 
00648 //====================================================================================
00649 // Added by Dario
00650 bool PixelNameTranslation::ROCexists(PixelROCName theROC)
00651 {
00652   if (translationtable_.find(theROC)==translationtable_.end()) {return false ;}
00653   return true ;
00654 }
00655 
00656 
00657 std::map <unsigned int, std::set<unsigned int> > PixelNameTranslation::getFEDsAndChannels() const {
00658 
00659   std::map <unsigned int, std::set<unsigned int> > tmp;
00660 
00661 std::map<PixelChannel, PixelHdwAddress >::const_iterator 
00662   channelTranslationTable_itr = channelTranslationTable_.begin();
00663 
00664   for ( ; channelTranslationTable_itr != channelTranslationTable_.end(); 
00665           channelTranslationTable_itr++ ) {
00666 
00667     unsigned int fednumber=channelTranslationTable_itr->second.fednumber();
00668     unsigned int fedchannel=channelTranslationTable_itr->second.fedchannel();
00669 
00670     tmp[fednumber].insert(fedchannel);
00671 
00672   }
00673 
00674   return tmp;
00675   
00676 }

Generated on Tue Jun 9 17:25:25 2009 for CMSSW by  doxygen 1.5.4