Frontend user code (object oriented - TMFE): Difference between revisions

From MidasWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:
= Introduction =
= 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]].
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.
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 <code>libmfe.a</code> and <code>libmidas.a</code>. In this framework you should only link against <code>libmidas.a</code>.
* In the C-style framework you do not write a <code>main()</code> function - you just implement functions (and variables) that the framework uses. In this framework you write your own <code>main()</code> 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 =


Examples of TMFE-based frontends can be found at
Examples of TMFE-based frontends can be found at
* <code>$MIDASSYS/progs/fetest.cxx</code>
* <code>$MIDASSYS/progs/tmfe_example.cxx</code> - minimal frontend with a periodic equipment
* <code>$MIDASSYS/progs/tmfe_example.cxx</code> - minimal frontend with a periodic equipment
* <code>$MIDASSYS/progs/tmfe_example_frontend.cxx</code> - the equivalent of <code>$MIDASSYS/examples/experiment/frontend.cxx</code>
* <code>$MIDASSYS/progs/tmfe_example_frontend.cxx</code> - the equivalent of <code>$MIDASSYS/examples/experiment/frontend.cxx</code>
* <code>$MIDASSYS/progs/tmfe_example_indexed.cxx</code> - example of a frontend that handles the <code>-i</code> argument. If you pass <code>-i 3</code> on the command line, the equipment will appear as <code>example_03</code> and write data to <code>BUF03</code>
* <code>$MIDASSYS/progs/tmfe_example_indexed.cxx</code> - example of a frontend that handles the <code>-i</code> argument. If you pass <code>-i 3</code> on the command line, the equipment will appear as <code>example_03</code> and write data to <code>BUF03</code>
* <code>$MIDASSYS/progs/tmfe_example_multithreaded.cxx</code>
* <code>$MIDASSYS/progs/tmfe_example_multithread.cxx</code> - 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.
* <code>$MIDASSYS/progs/tmfe_example_everything.cxx</code>
* <code>$MIDASSYS/progs/tmfe_example_everything.cxx</code> - "kitchen sink" example that uses almost all features of the framework.
* <code>$MIDASSYS/progs/fetest.cxx</code> - 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:
* <code>TMFrontend</code>
* <code>TMFeEquipment</code>
 
Other classes you will interact with are:
* <code>TMFE</code> - wrapper of some midas functions (<code>cm_msg()/fMfe->Msg()</code>, <code>cm_yield()/fMfe->Yield()</code> etc) that also contains some global state (<code>fRunNumber</code> etc).
* <code>TMFeResult</code> - 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.
* <code>MVOdb</code> - simplified access to ODB that suits some use cases. You can still use the <code>db_*</code> family of [https://bitbucket.org/tmidas/midas/src/develop/include/midas.h C-style functions] or the <code>midas::odb</code> [[Odbxx|JSON-like interface]].
 
== Status - TMFEResult ==
 
TMFeOk(), TMFeErrorMessage(), TMFeMidasError()
 
== Equipment - derive from TMFeEquipment ==
 
== Frontend - derive from TMFrontend ==
 
== main() ==
 
<code>
int main(int argc, char* argv[]) {
  MyFrontend fe;
  return fe.FeMain(argc, argv);
}
</code>
 
== TMFE singleton ==
 
== MVOdb ==
 
== Compilation ==
 
</code>

Revision as of 16:58, 31 March 2023


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