Frontend user code (object oriented - TMFE)

From MidasWiki
Revision as of 13:01, 6 April 2023 by Bsmith (talk | contribs)
Jump to navigation Jump to search


This page is a work in progress!


Links

Introduction

This page will document using object-oriented C++ to create a midas Frontend. For the classic C-style frontend see Frontend user code. For python frontends see Python.

Regardless of the framework you use, all midas frontends follow the same concept of "equipment" (which can be periodic or polled) that produce data in midas banks that can eventually get logged to file or the midas history system. If you don't need to produce data, you can write midas clients without using one of the frontend frameworks.

Key differences to the C-style frontend framework

  • In the C-style framework you must link against libmfe.a and libmidas.a. In this framework you should only link against libmidas.a.
  • In the C-style framework you do not write a main() function - you just implement functions (and variables) that the framework uses. In this framework you write your own main() function (generally just 2 lines of code).
  • In the C-style framework you populate nested structs with important information like the equipment name and type. In this framework you set member variables of classes instead.

Examples

Examples of TMFE-based frontends can be found at

  • $MIDASSYS/progs/tmfe_example.cxx - minimal frontend with a periodic equipment
  • $MIDASSYS/progs/tmfe_example_frontend.cxx - the equivalent of $MIDASSYS/examples/experiment/frontend.cxx
  • $MIDASSYS/progs/tmfe_example_indexed.cxx - example of a frontend that handles the -i argument. If you pass -i 3 on the command line, the equipment will appear as example_03 and write data to BUF03
  • $MIDASSYS/progs/tmfe_example_multithread.cxx - example of a frontend that offloads some tasks to other threads. You can offload RPC communication (ODB updates, run transitions etc), periodic equipment checks, polled equipment checks into 3 separate threads if desired. The default is to run all checks in the main thread.
  • $MIDASSYS/progs/tmfe_example_everything.cxx - "kitchen sink" example that uses almost all features of the framework.
  • $MIDASSYS/progs/fetest.cxx - contains several periodic equipment and one that only reacts to RPC commands and never writes any data.

Frontend code

Major classes

The main base classes you will need to derive from are:

  • TMFrontend
  • TMFeEquipment

Other classes you will interact with are:

  • TMFE - wrapper of some midas functions (cm_msg()/fMfe->Msg(), cm_yield()/fMfe->Yield() etc) that also contains some global state (fRunNumber etc).
  • TMFeResult - used by the framework to report success/failure of commands (rather than raw integer status codes used in the C-style framework). Note that the framework does NOT use exceptions to report errors.
  • MVOdb - simplified access to ODB that suits some use cases. You can still use the db_* family of C-style functions or the midas::odb JSON-like interface.

Status - TMFEResult

TMFeOk(), TMFeErrorMessage(), TMFeMidasError()

Equipment - derive from TMFeEquipment

Frontend - derive from TMFrontend

main()

 int main(int argc, char* argv[]) {
    MyFrontend fe;
    return fe.FeMain(argc, argv);
 }

TMFE singleton

MVOdb

Compilation