76 std::map<std::string, int> schemaEntriesMap;
77 std::vector<schemaEntry_t> schemaEntries;
82 std::string schemaName;
85 int getTypeSize(
int id);
86 int getTypeByString(std::string &typeName);
92 schema(){ groupid = 0; itemid = 0; rowLength = 0;}
99 schema(
const char *name,
int __group,
int __item){
100 schemaName = name; groupid = __group; itemid = __item;
105 schemaName = s.schemaName;
106 schemaEntries = s.schemaEntries;
107 schemaEntriesMap = s.schemaEntriesMap;
122 void parse(
const std::string& schString);
125 std::string
getName()
const {
return schemaName;}
142 const auto nentries = schemaEntries.size()-1;
143 const auto &sch=schemaEntries[nentries];
144 return sch.offset + sch.typeSize;
160 if(schemaEntriesMap.count(name))
return true;
172 const auto &sch=schemaEntries[item];
173 return rows*sch.offset + order*sch.typeSize;
183 int getOffset(
const char *name,
int order,
int rows)
const {
184 int item = schemaEntriesMap.at(name);
194 return schemaEntries[item].typeId;
204 return schemaEntries[item].typeId;
214 std::string
getEntryName(
int item)
const noexcept {
return schemaEntries[item].name;}
217 int getEntries() const noexcept {
return schemaEntries.size();}
231 schemaName = D.schemaName;
234 schemaEntries = D.schemaEntries;
235 schemaEntriesMap = D.schemaEntriesMap;
241 return schemaEntriesMap.at(name);
250 std::map<std::string,schema> factory;
264 bool hasSchema(
const char *name) {
return (factory.count(name)!=0);}
272 if(factory.count(name)==0){
273 throw hipo::schema_error(std::string(
"hipo::dictionary: schema '") + name +
"' does not exist");
275 return factory[name];
282 bool parse(
const char *schemaString);
Collection of schema definitions, typically read from a HIPO file header.
bool parse(const char *schemaString)
Parse a full schema string and add it to the dictionary.
void addSchema(schema sc)
Add a schema to the dictionary.
std::vector< std::string > getSchemaList()
Get a list of all schema names in the dictionary.
virtual ~dictionary()=default
bool hasSchema(const char *name)
Check whether a schema with the given name exists.
void show()
Print all schemas in the dictionary to standard output.
schema & getSchema(const char *name)
Retrieve a schema by name.
Exception thrown for schema-related errors (e.g., missing schema, parse failure).
Schema definition for a HIPO bank.
void parse(const std::string &schString)
Parse a schema definition string and populate entries.
void operator=(const schema &D)
Copy-assignment operator.
schema()
Default constructor. Initializes an empty schema with zero group/item IDs.
std::string getName() const
Get the schema name.
std::string getSchemaString()
Serialize the schema to a definition string (e.g. "pid/I,px/F").
virtual ~schema()=default
Virtual destructor (defaulted).
bool exists(const char *name) const
Check whether a column with the given name exists.
int getEntryOrder(const char *name) const
Get the column index for a given column name.
std::string getEntryName(int item) const noexcept
Get the name of a column by index.
schema(const char *name, int __group, int __item)
Construct a schema with a name, group ID, and item ID.
int getSizeForRows(int rows)
Compute the total buffer size needed for a given number of rows.
int getOffset(int item, int order, int rows) const
Compute the byte offset for a column value by column index.
void show()
Print the schema to standard output.
int getEntryType(const char *name) const noexcept
Get the type identifier of a column by name.
int getRowLength() const noexcept
Get the size of a single row in bytes.
int getItem()
Get the item identifier.
int getEntries() const noexcept
Get the number of columns in the schema.
int getGroup()
Get the group identifier.
std::string getSchemaStringJson()
Serialize the schema to a JSON-formatted string.
int getOffset(const char *name, int order, int rows) const
Compute the byte offset for a column value by column name.
int getEntryType(int item) const noexcept
Get the type identifier of a column by index.
schema(const schema &s)
Copy constructor.
struct hipo::schemaEntry_t schemaEntry_t
Describes a single column (entry) within a schema.
Exception classes for HIPO library error handling.
Type
Supported column data types for HIPO banks.
@ kLong
64-bit signed integer.
@ kInt
32-bit signed integer.
@ kFloat
32-bit IEEE 754 floating point.
@ kShort
16-bit signed integer.
@ kByte
8-bit signed integer.
@ kDouble
64-bit IEEE 754 floating point.
Describes a single column (entry) within a schema.
int typeId
Numeric type identifier (see Type).
int offset
Byte offset of this column within a row.
std::string type
Type string (e.g. "B", "S", "I", "F", "D", "L").
std::string name
Column name.
int typeSize
Size of the type in bytes.