File IO / Database
Block Name: Database
Code File Location: VisualSim/actor/lib/Database
o Used as a lookup table for doing searches.
o Examples of usage include routing table, lookup values to match certain attributes like disk drive zone and speed.
o Cmpares up to 6 fields of the input transaction with 6 columns in the database.
o Database content is available for viewing and processing using the RegEx functions.
This block is a lookup table or database containing rows and columns. Each row is a data structure. Each column of the row is a field of the data structure. For every input, the block matches upto 6 fields of the incoming Data Structure and with matching 6 columns of the Table. The following are the main features of the Database block:
Three functions- Read, Write and Erase
Match format:
Types of matches:
Database content entry:
Points to note:
File Name: This block accepts a file name as a parameter. There are a number of file path options available for this block. To see the list, view the section on File Paths in the Reference Guide document here. The file name is a concatenation of any number of individual strings and parameters, separated by "+". To view the file path in a demo model, click here.
Sample Lookup table Syntax for csv and txt files:
a) for TXT format,
ID MyStr MyInt MyDbl ;
0 "Str_1" 1 1.0 ;
1 "Str_2" 2 2.0 ;
2 "Str_3" 3 3.0 ;
0 "Str_4" 1 4.0 ;
1 "Str_5" 2 5.0 ;
b) for CSV format,
ID,MyStr,MyInt,MyDbl
int,string,int,double
0,Str_1,1,1.0
1,Str_2,2,2.0
2,Str_3,3,3.0
0,Str_4,1,4.0
1,Str_5,2,5.0
Note: Maximum Limit of Input_Fields and Lookup_Fields is 6.
The Database table data can be access and processed using the RegEx utility function that is described below. RegEx Example
The block has 5 utility functions that can access the Database table from anywhere in the model and at any time during the simulation.
Function 1:
getColumn (String database_name, String column_name)
Eg: Result_A = getColumn("Linking_1","dest")
Output:
{"0", "0", "1", "2"}
Description: This function is used to get an Array of Column entries from Database block. This output the column name as an Array .
Function 2:
getNextResource (String database_name, String column_name)
Eg: Result_A = getNextResource("Linking_1","dest")
Output:
"Processor_1"
Description: This function is used to get the item in the next row in a column from the Database block. The Return type should be based on the Datatype exists in the table.
Function 3:
getResourceActivity (String database_name, String column_name)
Eg: Result_A = getResourceActivity("Linking_1","dest")
Output:
{Resource_Name, Resource_Length, Resource_Name, Resource_Length,.... Resource_Name, Resource_Length}
{"0", "9", "0", "9", "1", "0", "2", "0"}
Description: This function is used to get an Array of Resource Activity from Database block, based on Column Name, returned as an Array. Assumes all column named resources exist in the model and can be accessed. Method supports Processor, SystemResource, SystemResource_Extend blocks. With one RegEx command user can get current queue length of a column of named resources as an array. Processor and other hardware blocks use "Architecture_Name.Processor_Name"format.
Function 4:
getRows (String database_name, String row_name, String column_name)
Eg: Result_A = getRows("Linking_1","1","dest")
Output:
{{BLOCK = "Database3",
DELTA = 0.0,
DS_NAME = "DS_Database3",
ID = 0,
INDEX = 0,
TIME = 0.0,
dest = "0",
hop = 5,
sequence = 0,
source = "0"}, {BLOCK = "Database3",
DELTA = 0.0,
DS_NAME = "DS_Database3",
ID = 1,
INDEX = 0,
TIME = 0.0,
dest = "0",
hop = 6,
sequence = 0,
source = "1"}}
Description: This function looks for each row_name that matches what is in the column. If column_name equals "Destination", and row_name equals "Node_1", then this method returns all rows as Data Structure with the "Destination" column equal to "Node_1" as an Array. This is handy for obtaining additional information for this destination, either in terms of routing, or data size/rates.
Function 5:
getRows (String database_name, String row_name, String column_name, String row_name2, String column_name2)
Eg: Result_A = getRows("Linking_1","0","dest","3","source")
Output:
{{BLOCK = "Database3",
DELTA = 0.0,
DS_NAME = "DS_Database3",
ID = 2,
INDEX = 0,
TIME = 0.0,
dest = "1",
hop = 7,
sequence = 0,
source = "3"}}
Description: This function looks for multiple match between rows and column. If column_name equals "Source", and row_name equals "Node_1", column_name2 equals "Destination", and row_name equals "Node_2", then this method returns all rows as Data Structure with the "Source" column equal to "Node_1", "Destination" column equal to "Node_2" as an Array. This is handy for obtaining additional information for routing (multiple paths), or data size/rates.
To illustrate the usage, look at the following examples in the Block Diagram Editor.
Database and Lookup Example
File Access Example
Read Mode
Write Mode
Remove Mode
RegEx Example
Expression on Output Expression Parameter Example
Parameter |
Explanation |
Type |
Example |
Linking_Name |
This is an unique memory name for this block. This is an optional field and is required when multiple database blocks need to reference this block for the content or the content of this database will be used in an Expression. This name is used to link multiple Database blocks that need to use the same lookup table. If this field is set to "None", or left to default, then no linking with other Database blocks. All blocks using the same lookup table must have the same linking name. The main block will have the Data_Structure_Text defined while all the referring blocks will have the 'Data_Structure_Text' parameter set to "extern". |
String |
"Linking_Name_or_None" |
Data_Structure_Text |
The content can be placed directly in the window, in a file (TXT or CSV) or a reference to another database block (extern). |
String |
ID MyStr MyInt MyDbl |
Input_Fields |
This is a list of fields in the incoming data structure. The values in these fields are matched with the respective list in the index fields (Lookup_Fields) of the Database. There can be a maximum of Six fields in a comma separated format. The match is between the first in the Input_Field with first in the Lookup_Field, second in the Input_Field with second in the Lookup_Field,and so, on. All fields have to match. |
String |
"Fld_Name_1, Fld_Name_2, Fld_Name_3.." |
Lookup_Fields |
This is a list of column names in the database. The values in these columns are matched with the respective list in the fields of the incoming data structure (Input_Fields) of the Database. There can be a maximum of Six fields in a comma separated format. The match is between the first in the Input_Field with first in the Lookup_Field, second in the Input_Field with second in the Lookup_Field,and so, on. All fields have to match. |
String |
"Fld_Name_A, Fld_Name_B, Fld_Name_C.." |
Output_Expression |
Parameter that specifies the match type and the value to be placed on the output port. The match type and the expression are combined in this field. |
String |
"output = match" /* FORMAT output = match.fieldb */ |
Mode |
This parameter specifies if this block instance is used lookup (Read), write incoming Data Structures (Write) or delete (Remove). This is a string-valued attribute that defaults to "Read". |
String |
Read, Write, Remove |
Port |
Explanation |
Type |
input |
The Data Structure containing the fields that is matched against the Lookup table Index field. |
General |
output |
The result of the output_expression is sent on the output port. |
General |
exception |
The exception port sends the requesting Data Structure to this port if a match cannot be found for the "Read" and "Remove" operations. |
General |
Note: Database block have no impact on newly added input and output port.
Created with the Personal Edition of HelpNDoc: News and information about help authoring tools and software