CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondFormats/RPCObjects/src/RPCReadOutMapping.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 
00003 
00004 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
00005 #include "CondFormats/RPCObjects/interface/TriggerBoardSpec.h"
00006 #include "CondFormats/RPCObjects/interface/LinkConnSpec.h"
00007 #include "CondFormats/RPCObjects/interface/LinkBoardSpec.h"
00008 #include "CondFormats/RPCObjects/interface/FebConnectorSpec.h"
00009 #include "CondFormats/RPCObjects/interface/ChamberStripSpec.h"
00010 
00011 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00012 
00013 #include<iostream>
00014 
00015 using namespace edm;
00016 
00017 
00018 RPCReadOutMapping::RPCReadOutMapping(const std::string & version) 
00019   : theVersion(version) { }
00020 
00021 const DccSpec * RPCReadOutMapping::dcc( int dccId) const
00022 {
00023   IMAP im = theFeds.find(dccId);
00024   const DccSpec & ddc = (*im).second;
00025   return (im != theFeds.end()) ?  &ddc : 0;
00026 }
00027 
00028 void RPCReadOutMapping::add(const DccSpec & dcc)
00029 {
00030   theFeds[dcc.id()] = dcc;
00031 }
00032 
00033 
00034 std::vector<const DccSpec*> RPCReadOutMapping::dccList() const
00035 {
00036   std::vector<const DccSpec*> result;
00037   result.reserve(theFeds.size());
00038   for (IMAP im = theFeds.begin(); im != theFeds.end(); im++) {
00039     result.push_back( &(im->second) );
00040   }
00041   return result;
00042 }
00043 
00044 std::pair<int,int> RPCReadOutMapping::dccNumberRange() const
00045 {
00046   
00047   if (theFeds.empty()) return std::make_pair(0,-1);
00048   else {
00049     IMAP first = theFeds.begin();
00050     IMAP last  = theFeds.end(); last--;
00051     return  std::make_pair(first->first, last->first);
00052   }
00053 }
00054 
00055 
00056 std::vector< std::pair< LinkBoardElectronicIndex, LinkBoardPackedStrip> > 
00057     RPCReadOutMapping::rawDataFrame( const StripInDetUnit & stripInDetUnit) const 
00058 {
00059   std::vector< std::pair< LinkBoardElectronicIndex, LinkBoardPackedStrip> > result;
00060   LinkBoardElectronicIndex eleIndex = { 0,0,0,0 };
00061 
00062   const uint32_t & rawDetId = stripInDetUnit.first;
00063   const int & stripInDU     = stripInDetUnit.second;
00064 
00065   for (IMAP im=theFeds.begin(); im != theFeds.end(); im++) {
00066     const DccSpec & dccSpec = (*im).second; 
00067     const std::vector<TriggerBoardSpec> & triggerBoards = dccSpec.triggerBoards();
00068     for ( std::vector<TriggerBoardSpec>::const_iterator 
00069         it = triggerBoards.begin(); it != triggerBoards.end(); it++) {
00070       const TriggerBoardSpec & triggerBoard = (*it);
00071       typedef std::vector<const LinkConnSpec* > LINKS;
00072       LINKS linkConns = triggerBoard.enabledLinkConns();
00073       for ( LINKS::const_iterator ic = linkConns.begin(); ic != linkConns.end(); ic++) {
00074               
00075         const LinkConnSpec & link = **ic; 
00076         const std::vector<LinkBoardSpec> & boards = link.linkBoards();
00077         for ( std::vector<LinkBoardSpec>::const_iterator
00078             ib = boards.begin(); ib != boards.end(); ib++) { 
00079 
00080           const LinkBoardSpec & board = (*ib);
00081           
00082           eleIndex.dccId = dccSpec.id();
00083           eleIndex.dccInputChannelNum = triggerBoard.dccInputChannelNum();
00084           eleIndex.tbLinkInputNum = link.triggerBoardInputNumber(); 
00085           eleIndex.lbNumInLink = board.linkBoardNumInLink();
00086 
00087           const std::vector<FebConnectorSpec> & febs = board.febs();
00088           int febCheck = 0;
00089           for ( std::vector<FebConnectorSpec>::const_iterator
00090               ifc = febs.begin(); ifc != febs.end(); ifc++) {
00091             const FebConnectorSpec & febConnector = (*ifc);
00092             febCheck++;
00093             if (febConnector.rawId() != rawDetId) continue;
00094             int febInLB = febConnector.linkBoardInputNum();
00095             /* if (febInLB != febCheck) {
00096               edm::LogError("rawDataFrame") << " problem with febInLB: " <<febInLB<<" "<<febCheck;
00097               } */
00098             for (int istrip=0; istrip<febConnector.nstrips(); istrip++) {
00099               int stripPinInFeb = febConnector.cablePinNum(istrip);
00100               if (febConnector.chamberStripNum(istrip) == stripInDU) {
00101                 result.push_back(
00102                     std::make_pair( eleIndex, LinkBoardPackedStrip( febInLB, stripPinInFeb) ) ); 
00103               }
00104             }
00105           } 
00106         }
00107       }
00108     }
00109   }
00110   return result;
00111 }
00112 
00113 const LinkBoardSpec*  
00114     RPCReadOutMapping::location(const LinkBoardElectronicIndex & ele) const
00115 {
00116   //FIXME after debugging change to dcc(ele.dccId)->triggerBoard(ele.dccInputChannelNum)->...
00117   const DccSpec *dcc = RPCReadOutMapping::dcc(ele.dccId);
00118   if (dcc) {
00119     const TriggerBoardSpec *tb = dcc->triggerBoard(ele.dccInputChannelNum);
00120      if (tb) {
00121       const LinkConnSpec *lc = tb->linkConn( ele.tbLinkInputNum);
00122       if (lc) {
00123         const LinkBoardSpec *lb = lc->linkBoard(ele.lbNumInLink);
00124         return lb;
00125       }
00126     }
00127   }
00128   return 0;
00129 }
00130 
00131 RPCReadOutMapping::StripInDetUnit 
00132     RPCReadOutMapping::detUnitFrame(const LinkBoardSpec& location, 
00133     const LinkBoardPackedStrip & lbstrip) const 
00134 {
00135   static bool debug = edm::MessageDrop::instance()->debugEnabled;
00136   uint32_t detUnit = 0;
00137   int stripInDU = 0;
00138   int febInLB = lbstrip.febInLB();
00139   int stripPinInFeb = lbstrip.stripPinInFeb();
00140 
00141   const FebConnectorSpec * feb = location.feb(febInLB);
00142   if (feb) {
00143     detUnit = feb->rawId();
00144     const ChamberStripSpec strip = feb->strip(stripPinInFeb);
00145     if (strip.chamberStripNumber > -1) {
00146       stripInDU = strip.chamberStripNumber;
00147     } else {
00148       // LogWarning("detUnitFrame")<<"problem with stip for febInLB: "<<febInLB
00149       //                             <<" strip pin: "<< stripPinInFeb
00150       //                             <<" strip pin: "<< stripPinInFeb;
00151       if (debug) {
00152         LogDebug("")<<"problem with stip for febInLB: "<<febInLB
00153                     <<" strip pin: "<< stripPinInFeb
00154                     <<" strip pin: "<< stripPinInFeb
00155                     <<" for linkBoard: "<<location.print(3);
00156       }
00157     }
00158   } else {
00159     // LogWarning("detUnitFrame")<<"problem with detUnit for febInLB: ";
00160     if (debug) {  
00161       LogDebug("") <<"problem with detUnit for febInLB: " <<febInLB
00162                    <<" for linkBoard: "<<location.print(1);
00163     }
00164   }
00165   return std::make_pair(detUnit,stripInDU);
00166 }
00167 
00168 
00169 //
00170 // ALL BELOW IS TEMPORARY, TO BE REMOVED !!!!
00171 //
00172 
00173 std::pair<LinkBoardElectronicIndex, int>  
00174 RPCReadOutMapping::getRAWSpecForCMSChamberSrip(uint32_t  detId, int strip, int dccInputChannel) const{
00175 
00176  LinkBoardElectronicIndex linkboard;
00177  linkboard.dccId = 790;
00178  linkboard.dccInputChannelNum = dccInputChannel;
00179 
00180  for(int k=0;k<18;k++){
00181    linkboard.tbLinkInputNum = k;
00182    for(int j=0;j<3;j++){
00183      linkboard.lbNumInLink = j;
00184      const LinkBoardSpec *location = this->location(linkboard);    
00185      if (location) {
00186        for(int i=1;i<7;i++){     
00187          const FebConnectorSpec * feb = location->feb(i);
00188          if(feb && feb->rawId()==detId){
00189            for(int l=1;l<17;l++){
00190              int pin = l;
00191              const ChamberStripSpec aStrip = feb->strip(pin);
00192              if(aStrip.cmsStripNumber==strip){
00193                int bitInLink = (i-1)*16+l-1;
00194                std::pair<LinkBoardElectronicIndex, int> stripInfo(linkboard,bitInLink);
00195                return stripInfo;
00196              }
00197            }
00198          }
00199        }
00200      }
00201    }
00202  }
00203  RPCDetId aDet(detId);
00204  std::cout<<"Strip: "<<strip<<" not found for detector: "<<aDet<<std::endl;
00205  std::pair<LinkBoardElectronicIndex, int> dummyStripInfo(linkboard,-99);
00206  return dummyStripInfo;
00207 }
00208 
00209 
00210 std::vector<const LinkBoardSpec*> RPCReadOutMapping::getLBforChamber(const std::string &name) const{
00211 
00212 
00213  std::vector<const LinkBoardSpec*> vLBforChamber;
00214 
00215  LinkBoardElectronicIndex linkboard;
00216  linkboard.dccId = 790;
00217  linkboard.dccInputChannelNum = 1;
00218  linkboard.tbLinkInputNum = 1;
00219  linkboard.lbNumInLink = 0;
00220  const LinkBoardSpec *location = this->location(linkboard);
00221  
00222  for(int k=0;k<18;k++){
00223    linkboard.dccInputChannelNum = 1;
00224    linkboard.tbLinkInputNum = k;
00225    for(int j=0;j<3;j++){
00226      linkboard.lbNumInLink = j;
00227      int febInputNum=1;
00228      location = this->location(linkboard);
00229      if (location) {
00230        //location->print();
00231        for(int j=0;j<6;j++){     
00232          const FebConnectorSpec * feb = location->feb(febInputNum+j);
00233          if(feb){
00234            //feb->print();        
00235            std::string chName = feb->chamber().chamberLocationName();
00236            if(chName==name){
00237              vLBforChamber.push_back(location);
00238              //feb->chamber().print();
00239              break;
00240            }
00241          }
00242        }
00243      }
00244    }
00245  }
00246  return vLBforChamber;
00247 }