| 1 | /* |
| 2 | * Legal Notice |
| 3 | * |
| 4 | * This document and associated source code (the "Work") is a part of a |
| 5 | * benchmark specification maintained by the TPC. |
| 6 | * |
| 7 | * The TPC reserves all right, title, and interest to the Work as provided |
| 8 | * under U.S. and international laws, including without limitation all patent |
| 9 | * and trademark rights therein. |
| 10 | * |
| 11 | * No Warranty |
| 12 | * |
| 13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
| 14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
| 15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
| 16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
| 17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
| 18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
| 20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
| 21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
| 22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
| 23 | * WITH REGARD TO THE WORK. |
| 24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
| 25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
| 26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
| 27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
| 28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
| 29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
| 30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
| 31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
| 32 | * |
| 33 | * Contributors |
| 34 | * - Sergey Vasilevskiy |
| 35 | * - Doug Johnson |
| 36 | */ |
| 37 | |
| 38 | #include "input/CompanyCompetitorFile.h" |
| 39 | #include "utilities/MiscConsts.h" |
| 40 | |
| 41 | using namespace TPCE; |
| 42 | |
| 43 | /* |
| 44 | * Constructor. |
| 45 | * |
| 46 | * PARAMETERS: |
| 47 | * IN dataFile - CompanyCompetitorDataFile |
| 48 | * IN iConfiguredCustomerCount - total configured number of customers |
| 49 | * in the database IN iActiveCustomerCount - active number of customers |
| 50 | * in the database (provided for engineering purposes) |
| 51 | * |
| 52 | * RETURNS: |
| 53 | * not applicable. |
| 54 | */ |
| 55 | CCompanyCompetitorFile::CCompanyCompetitorFile(const CompanyCompetitorDataFile_t &dataFile, |
| 56 | TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount, |
| 57 | UINT baseCompanyCount) |
| 58 | : m_dataFile(&dataFile), |
| 59 | m_iConfiguredCompanyCompetitorCount(CalculateCompanyCompetitorCount(iConfiguredCustomerCount)), |
| 60 | m_iActiveCompanyCompetitorCount(CalculateCompanyCompetitorCount(iActiveCustomerCount)), |
| 61 | m_iBaseCompanyCount(baseCompanyCount) { |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Calculate company competitor count for the specified number of customers. |
| 66 | * Sort of a static method. Used in parallel generation of company related |
| 67 | * tables. |
| 68 | * |
| 69 | * PARAMETERS: |
| 70 | * IN iCustomerCount - number of customers |
| 71 | * |
| 72 | * RETURNS: |
| 73 | * number of company competitors. |
| 74 | */ |
| 75 | TIdent CCompanyCompetitorFile::CalculateCompanyCompetitorCount(TIdent iCustomerCount) const { |
| 76 | return iCustomerCount / iDefaultLoadUnitSize * iOneLoadUnitCompanyCompetitorCount; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Calculate the first company competitor id (0-based) for the specified |
| 81 | * customer id. |
| 82 | * |
| 83 | * PARAMETERS: |
| 84 | * IN iStartFromCustomer - customer id |
| 85 | * |
| 86 | * RETURNS: |
| 87 | * company competitor id. |
| 88 | */ |
| 89 | TIdent CCompanyCompetitorFile::CalculateStartFromCompanyCompetitor(TIdent iStartFromCustomer) const { |
| 90 | return iStartFromCustomer / iDefaultLoadUnitSize * iOneLoadUnitCompanyCompetitorCount; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Return company id for the specified row. |
| 95 | * Index can exceed the size of the Company Competitor input file. |
| 96 | * |
| 97 | * PARAMETERS: |
| 98 | * IN iIndex - row number in the Company Competitor file (0-based) |
| 99 | * |
| 100 | * RETURNS: |
| 101 | * company id. |
| 102 | */ |
| 103 | TIdent CCompanyCompetitorFile::GetCompanyId(TIdent iIndex) const { |
| 104 | // Index wraps around every 15000 companies. |
| 105 | // |
| 106 | return (*m_dataFile)[(int)(iIndex % m_dataFile->size())].CP_CO_ID() + iTIdentShift + |
| 107 | iIndex / m_dataFile->size() * m_iBaseCompanyCount; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Return company competitor id for the specified row. |
| 112 | * Index can exceed the size of the Company Competitor input file. |
| 113 | * |
| 114 | * PARAMETERS: |
| 115 | * IN iIndex - row number in the Company Competitor file (0-based) |
| 116 | * |
| 117 | * RETURNS: |
| 118 | * company competitor id. |
| 119 | */ |
| 120 | TIdent CCompanyCompetitorFile::GetCompanyCompetitorId(TIdent iIndex) const { |
| 121 | // Index wraps around every 5000 companies. |
| 122 | // |
| 123 | return (*m_dataFile)[(int)(iIndex % m_dataFile->size())].CP_COMP_CO_ID() + iTIdentShift + |
| 124 | iIndex / m_dataFile->size() * m_iBaseCompanyCount; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Return industry id for the specified row. |
| 129 | * Index can exceed the size of the Company Competitor input file. |
| 130 | * |
| 131 | * PARAMETERS: |
| 132 | * IN iIndex - row number in the Company Competitor file (0-based) |
| 133 | * |
| 134 | * RETURNS: |
| 135 | * industry id. |
| 136 | */ |
| 137 | const std::string &CCompanyCompetitorFile::GetIndustryId(TIdent iIndex) const { |
| 138 | // Index wraps around every 5000 companies. |
| 139 | // |
| 140 | return (*m_dataFile)[(int)(iIndex % m_dataFile->size())].CP_IN_ID(); |
| 141 | } |
| 142 | |
| 143 | const char *CCompanyCompetitorFile::GetIndustryIdCSTR(TIdent iIndex) const { |
| 144 | // Index wraps around every 5000 companies. |
| 145 | // |
| 146 | return (*m_dataFile)[(int)(iIndex % m_dataFile->size())].CP_IN_ID_CSTR(); |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Return the number of company competitors in the database for |
| 151 | * the configured number of customers. |
| 152 | * |
| 153 | * PARAMETERS: |
| 154 | * none. |
| 155 | * |
| 156 | * RETURNS: |
| 157 | * configured company competitor count. |
| 158 | */ |
| 159 | TIdent CCompanyCompetitorFile::GetConfiguredCompanyCompetitorCount() const { |
| 160 | return m_iConfiguredCompanyCompetitorCount; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Return the number of company competitors in the database for |
| 165 | * the active number of customers. |
| 166 | * |
| 167 | * PARAMETERS: |
| 168 | * none. |
| 169 | * |
| 170 | * RETURNS: |
| 171 | * active company competitor count. |
| 172 | */ |
| 173 | TIdent CCompanyCompetitorFile::GetActiveCompanyCompetitorCount() const { |
| 174 | return m_iActiveCompanyCompetitorCount; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Overload GetRecord to wrap around indices that |
| 179 | * are larger than the flat file |
| 180 | * |
| 181 | * PARAMETERS: |
| 182 | * IN iIndex - row number in the Company Competitor file (0-based) |
| 183 | * |
| 184 | * RETURNS: |
| 185 | * reference to the row structure in the Company Competitor file. |
| 186 | */ |
| 187 | const CompanyCompetitorDataFileRecord &CCompanyCompetitorFile::GetRecord(TIdent index) const { |
| 188 | return (*m_dataFile)[(int)(index % m_dataFile->size())]; |
| 189 | } |
| 190 | |