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/*
39 * CPerson class for the Customer table.
40 */
41#ifndef PERSON_H
42#define PERSON_H
43
44#include <string>
45
46#include "utilities/EGenStandardTypes.h"
47#include "utilities/Random.h"
48
49#include "input/DataFileManager.h"
50
51namespace TPCE {
52
53// Used for generating tax ID strings.
54const int TaxIDFmt_len = 14;
55const char TaxIDFmt[TaxIDFmt_len + 1] = "nnnaannnnaannn";
56
57class CPerson {
58private:
59 const LastNameDataFile_t &m_LastNames;
60 const MaleFirstNameDataFile_t &m_MaleFirstNames;
61 const FemaleFirstNameDataFile_t &m_FemaleFirstNames;
62
63 CRandom m_rnd;
64 bool m_bCacheEnabled;
65 int m_iCacheSize;
66 TIdent m_iCacheOffset;
67 int *m_FirstNameCache;
68 int *m_LastNameCache;
69 char *m_GenderCache;
70 const int INVALID_NAME_CACHE_ENTRY;
71 const char INVALID_GENDER_CACHE_ENTRY;
72
73 template <class DataFileT> const string &getName(TIdent CID, const DataFileT &df, int *cache, RNGSEED seedBase) {
74 // It is possible (and expected) to get CID values that are oustide the
75 // current load unit. For example, AccountPermission CIDs and Broker IDs
76 // can be outside the current load unit. These "out of bounds" CIDs are
77 // not cached so we need to account for this.
78 TIdent index = CID - m_iCacheOffset;
79 bool bCheckCache = (index >= 0 && index < m_iCacheSize);
80
81 // Use the cache if we can.
82 if (m_bCacheEnabled && bCheckCache && (INVALID_NAME_CACHE_ENTRY != cache[index])) {
83 return df[cache[index]].NAME();
84 }
85
86 // We couldn't use the cache.
87 RNGSEED OldSeed;
88 int iThreshold;
89
90 OldSeed = m_rnd.GetSeed();
91
92 m_rnd.SetSeed(m_rnd.RndNthElement(seedBase, (RNGSEED)CID));
93
94 // First, generate the threshold.
95 iThreshold = m_rnd.RndIntRange(0, df.size() - 1);
96
97 // Cache the result if appropriate.
98 if (m_bCacheEnabled && bCheckCache) {
99 cache[index] = iThreshold;
100 }
101
102 // Restore the RNG
103 m_rnd.SetSeed(OldSeed);
104
105 return df[iThreshold].NAME();
106 };
107
108public:
109 CPerson(const DataFileManager &dfm, TIdent iStartFromCustomer, bool bCacheEnabled = false);
110
111 ~CPerson();
112 void InitNextLoadUnit(TIdent iCacheOffsetIncrement = iDefaultLoadUnitSize);
113
114 const string &GetLastName(TIdent CID);
115 const string &GetFirstName(TIdent CID);
116 char GetMiddleName(TIdent CID);
117 char GetGender(TIdent CID); //'M' or 'F'
118 bool IsMaleGender(TIdent CID); // TRUE if male, FALSE if female
119 void GetTaxID(TIdent CID, char *buf);
120
121 // get first name, last name, and tax id
122 void GetFirstLastAndTaxID(TIdent C_ID, char *szFirstName, char *szLastName, char *szTaxID);
123};
124
125} // namespace TPCE
126
127#endif // PERSON_H
128