TGenBase class generator
This tool allows you to describe your data which needs to be stored in a database. You start by creating a project (lets name it TGenBaseCbmSts
here) and adding some classes to it. Add properties to the classes, define their type and, if needed, their database and JSON type (use the Expert mode
for this).
The extra includes allow to use the ROOT classes as the property type. Use only the types which inherit from TObject, for example TH1F
.
When you have several classes described, you can establish relations between them.
- Has One:
allows you to establish a one-to-one relation. Example
StsSensor
Has One
Vendor
of typeStsSensorVendor
. - Has Many:
allows you to establish a one-to-many relation. This requires the other class to know about this class by defining a
Has One
relation to it. Example: given we have already established aStsSensor
Has One
Vendor
relation, we can establish theStsSensorVendor
Has Many
Sensors
of typeStsSensor
through aVendor
property.
Quick start
You can start with class generation right away by navigating to http://pipc40.am15.uni-tuebingen.de:8008
I will try to keep this page online and updated.
Setting up the generator
The docroot
subdirectory of this project contains the pre-built code for the class generator.
You have to serve the generated files with a HTTP server. For example you can use the Wt HTTP server distributed with this project. It will be available after you build the project with the CMake
:
./TGenBaseClassGen.wt --docroot ../docroot --http-address localhost --http-port 8008
or you can use the node's serve
server:
npm install --global serve
serve --port 8008 ../docroot
You will need to install the Node.js for the latter.
Class library generation
When you have described all classes you need to store data from, you can now generate the class library by clicking the Generate C++ class library
button. It will set up for you: the TGenBase C++ classes, the web server which allows you to read and store the data over HTTP using JSON format, the CMake project to compile the generated C++ code. Additionally, there will be a priming macro and database configuration script created. Lastly, there will be a Vue.js project created with the graphical user interface to visualise the data from the database.
CMake project
Unpack the generated code into FairRootSource\dbase\dbExamples\
TGenBaseCbmSts
folder. Edit the FairRootSource\dbase\dbExamples\CMakeLists.txt
and add the
add_subdirectory (TGenBaseCbmSts)
line for your project to be included into the compilation process.
Compilation
Compile the generated code as usual with an out-of-source CMake
build.
SIMPATH=~/FairSoft6; cmake .. -DCMAKE_INSTALL_PREFIX=~/FairRoot6 -DWITH_DBASE=ON && make -j4 install
SIMPATH
is the path to the installed FairSoft in your system. CMAKE_INSTALL_PREFIX
is the path where the FairRoot will be installed after compilation. Change them accordingly if needed.
src
directory
This directory contains the generated TGenBase C++ classes, the LinkDef.h
file used to register your classes inside ROOT and a CMakeLists.txt
file which will compile the classes and generate the ROOT dictionary.
rest
directory
This directory contains the HTTP web server to serve your database data over the web. The web server will be compiled only if the Wt
framework is available. The server binary is then installed in ~/FairRoot6/bin/
. Run it as:
~/FairRoot6/bin/TGenBaseCbmStsREST.wt --docroot `pwd` --http-address 10.211.55.2 --http-port 8008
For each class defined the following REST methods will be generated:
GetById
GetAllVersions
GetArray
GetAll
Store
StoreArray
- Getters for every
Has One
relations, e.g.GetByVendorId
andGetVendor
- Getters for every
Has Many
relations, e.g.GetSensors
The methods are invoked with a POST
method. An example curl
request may look like this:
curl -X POST \
http://10.211.55.2:8008/StsSensorVendor/GetById/ \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{"Id": 0}'
and a response to it:
{
"data": {
"Comment": "They make good sensors",
"ContactInfo": "Phone:(81)53-452-2141 Fax:(81)53-456-7889",
"Id": 0,
"Location": "325-6, Sunayama-cho, Naka-ku, Hamamatsu City, Shizuoka Pref., 430-8587, Japan",
"VendorName": "Hamamatsu"
},
"error": null
}
gui
directory
This directory contains the Vue.js
project generated to visualize the data stored in the database. It makes use of the HTTP server generated in the rest
directory, so make sure you build it and run it.
Refer to README.md
in the vue
subdirectory on how to build and run the GUI.
In the generated project, navigate to the gui/vue/src/main.js
and edit the window.DefaultTGenBaseURL
to point at your HTTP web server. This is a fallback address to all classes generated. If you want to have a per-class configuration, you can do it like this window.StsSensorURL = localhost:8008
.
macro
directory
This directory contains the database configuration script dbconfig.sh
. It is necessary to run it before you can communicate with TGenBase. You can start right away with a simple call:
. dbconfig.sh local_sqlite
This will configure the TGenBase to use the local SQLite database file.
The Prime.C
macro in the directory contains a simple template code to fill the database with data. You can script here the static data creation like this:
void prime_sensor_vendor()
{
string logTitle = "Vendor Priming";
struct vendor_type_t {
Int_t fId;
string fVendorName;
string fLocation;
string fContactInfo;
string fComment;
};
std::vector<vendor_type_t> vendors = {
{0, "Hamamatsu", "325-6, Sunayama-cho, Naka-ku, Hamamatsu City, Shizuoka Pref., 430-8587, Japan", "Phone:(81)53-452-2141 Fax:(81)53-456-7889", "They make good sensors"},
{1, "CIS", "CiS electronic GmbH, Europark Fichtenhain A15, D - 47807 Krefeld", "Tel.: +49 21 51 / 37 87 - 0 Fax.: +49 21 51 / 37 87 - 11", "They make good sensors"},
};
StsSensorVendor vendor;
for (Int_t i=0; i<vendors.size(); i++ ) {
vendor.SetLogTitle(logTitle);
vendor.SetId(i);
vendor.SetVendorName(vendors[i].fVendorName);
vendor.SetLocation(vendors[i].fLocation);
vendor.SetContactInfo(vendors[i].fContactInfo);
vendor.SetComment(vendors[i].fComment);
vendor.store();
}
}
Note
To regenerate the template project if needed, run
cd template
zip -r -X template.zip ./*
mv -f template.zip ../vue/src/assets/template.zip
cd ../vue
npm run build
cd ..