CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2015
    Posts
    500

    Help in understanding the legacy code

    Hello,

    Im trying to understand the following legacy code:

    Not sure why the following array indexing is made so complicated.
    Could some experts explain help me understand the logic behind

    Code:
    COverlapTableRSSI& GetTableRSSI(bool b15kHzA, bool b15kHzB, bool bNormalA, bool bNormalB, int nNonMbsfnA, int nNonMbsfnB, int numTxA, int numTxB) const
    {
    	ASSERT_ONCE(m_pTablesRSSI);
    	const size_t iSA = GetSubCarrierTypeIndex(b15kHzA);
    	const size_t iSB = GetSubCarrierTypeIndex(b15kHzB);
    	const size_t iCA = GetCyclicPrefixTypeIndex(bNormalA);
    	const size_t iCB = GetCyclicPrefixTypeIndex(bNormalB);
    	const size_t iNA = GetNonMbsfnIndex(nNonMbsfnA);
    	const size_t iNB = GetNonMbsfnIndex(nNonMbsfnB);
    	const size_t iTA = GetTxTypeIndex(numTxA);
    	const size_t iTB = GetTxTypeIndex(numTxB);
    
    	const size_t index = iSA + GetNumSubCarrierTypes()
    		* (iSB + GetNumSubCarrierTypes()
    		* (iCA + GetNumCyclicPrefixTypes()
    		* (iCB + GetNumCyclicPrefixTypes()
    		* (iNA + GetNumNonMbsfnTypes()
    		* (iNB + GetNumNonMbsfnTypes()
    		* (iTA + GetNumTxTypes()
    		* (iTB)))))));
    
    	ASSERT_ONCE(index >= 0 && index < GetSizeRSSI());
    	return m_pTablesRSSI[index];

    And this table is being filled in the folowing function:
    Code:
    void Populate()
    {
       if (m_pTables || m_pTablesRSSI) return;   // Already populated !!!
    
    #ifdef DUMP_TABLES_TO_FILE
       std::ofstream os;
       os.open("C:\\SubFramePatterns.txt", std::ios::out);
    #endif
    
       const size_t iSize = GetSize();
       m_pTables = new COverlapTable[iSize];
    
       const size_t iSizeRSSI = GetSizeRSSI();
       m_pTablesRSSI = new COverlapTableRSSI[iSizeRSSI];
    
       CSubFrame A, B;   // Working objects for calculating overlaps in the loop   (Think of A as victim and B as aggressor)
    
       // We should only ever be comparing subframes on the same carrier with the same SYNC Id and the same subframe number
       for (size_t iSA = 0; iSA < GetNumSubCarrierTypes(); iSA++)
       {
          const bool b15kHzA = Get15kHz(iSA);
          for (size_t iSB = 0; iSB < GetNumSubCarrierTypes(); iSB++)
          {
             const bool b15kHzB = Get15kHz(iSB);
             for (size_t iCA = 0; iCA < GetNumCyclicPrefixTypes(); iCA++)
             {
                const bool bNormalA = GetNormalCP(iCA);
                for (size_t iCB = 0; iCB < GetNumCyclicPrefixTypes(); iCB++)
                {
                   const bool bNormalB = GetNormalCP(iCB);
                   for (size_t iNonA = 0; iNonA < GetNumNonMbsfnTypes(); iNonA++)
                   {
                      const int nNonMbsfnA = GetNonMbsfn(iNonA);
                      for (size_t iNonB = 0; iNonB < GetNumNonMbsfnTypes(); iNonB++)
                      {
                         const int nNonMbsfnB = GetNonMbsfn(iNonB);
                         for (size_t iTA = 0; iTA < GetNumTxTypes(); iTA++)
                         {
                            const int numTxA = GetNumTx(iTA);
                            for (size_t iTB = 0; iTB < GetNumTxTypes(); iTB++)
                            {
                               const int numTxB = GetNumTx(iTB);
    
                               // Keep the PCI loops innermost so we can do the averaging easily
                               for (int iPciA = 0; iPciA < 6; iPciA++)   // Omit "Unknown" PCI index of 6
                               {
                                  A.Make(b15kHzA, bNormalA, iPciA, numTxA, nNonMbsfnA);
    #ifdef DUMP_TABLES_TO_FILE
                                  if (iPciA == 0 && iSB == 0 && iCB == 0 && iNonB == 0 && iTB == 0) A.Dump(os);   // Only dump for PCI0 and skip loops through B
    #endif
                                  for (int iPciB = 0; iPciB < 6; iPciB++)
                                  {
                                     B.Make(b15kHzB, bNormalB, iPciB, numTxB, nNonMbsfnB);
    
                                     COverlapTable& s = GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, iPciA, iPciB);
                                     COverlapTable& avgA = GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, PCI_UNKNOWN, iPciB);      // B has known PCI.  A is unknown, so sum over all 6 possibilities
                                     COverlapTable& avgB = GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, iPciA, PCI_UNKNOWN);      // A has known PCI.  B is unknown, so sum over all 6 possibilities
                                     COverlapTable& avgAB = GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, PCI_UNKNOWN, PCI_UNKNOWN);   // A and B have unknown PCI so sum over all 36 possibilities
    
                                     if (iPciA == iPciB == 0)   // We can calculate RSSI overlap tables just for this case w.l.o.g.
                                     {
                                        COverlapTableRSSI& t = GetTableRSSI(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB);
                                        t.Populate(A, B);
                                     }
    
                                     s.Populate(A, B);
                                     avgA += s;
                                     avgB += s;
                                     avgAB += s;
                                  }
                               }
    
                               // Now do the final scaling to get averages over PCIs for the special case when a PCI is unknown
                               const double dSixth = 1.0 / 6.0;
                               for (int iPci = 0; iPci < GetNumPciTypes(); iPci++)   // Includes "Unknown" PCI index of PCI_UNKNOWN
                               {
                                  GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, iPci, PCI_UNKNOWN) *= dSixth;
                                  GetTable(b15kHzA, b15kHzB, bNormalA, bNormalB, nNonMbsfnA, nNonMbsfnB, numTxA, numTxB, PCI_UNKNOWN, iPci) *= dSixth;
                               }
                            }
                         }
                      }
                   }
                }
             }
          }
       }
    }
    thanks a lot
    pdk
    Last edited by VictorN; June 11th, 2021 at 03:04 AM. Reason: decrease the length of TAB stops in code snippet

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Help in understanding the legacy code

    What for was used this "legacy code"?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    500

    Re: Help in understanding the legacy code

    I dont have any documents regarding this, so need to go through this and find out whats happening.
    and i was thinking, if they had used vectors it would have been implemented.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Help in understanding the legacy code

    Well, the millions of programmers use vectors! So it is not a reason that a lot of them could understand what for was this code written.
    Also Goggle knows only one link that mentions this GetNumSubCarrierTypes() function. And it is your post in CG!
    Victor Nijegorodov

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Help in understanding the legacy code

    Limit the populate method to populate only one small representitive data set and then step through the code to inspect what you have. It might be that the folks that wrote this code expected a lot of data variation, so wrote it to be flexible. However, there may be very few actual variations, so the the code ends up being overly flexible and unnecessarily complicated.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured