FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MCStepInterceptor.cxx
Go to the documentation of this file.
1 // Copyright CERN and copyright holders of ALICE O2. This software is
2 // distributed under the terms of the GNU General Public License v3 (GPL
3 // Version 3), copied verbatim in the file "COPYING".
4 //
5 // See https://alice-o2.web.cern.ch/ for full licensing information.
6 //
7 // In applying this license CERN does not waive the privileges and immunities
8 // granted to it by virtue of its status as an Intergovernmental Organization
9 // or submit itself to any jurisdiction.
10 
11 //****************************************************************************
12 //* This file is free software: you can redistribute it and/or modify *
13 //* it under the terms of the GNU General Public License as published by *
14 //* the Free Software Foundation, either version 3 of the License, or *
15 //* (at your option) any later version. *
16 //* *
17 //* Primary Authors: Sandro Wenzel <sandro.wenzel@cern.ch> *
18 //* *
19 //* The authors make no claims about the suitability of this software for *
20 //* any purpose. It is provided "as is" without express or implied warranty. *
21 //****************************************************************************
22 
23 // @file MCStepInterceptor.cxx
24 // @author Sandro Wenzel
25 // @since 2017-06-29
26 // @brief A LD_PRELOAD logger hooking into Stepping of FairMCApplication's
27 // @author Radoslaw Karabowicz
28 // @since 2018-10-22
29 // @brief Modified for FairRoot
30 
31 // (re)declare symbols to be able to hook into them
32 #define DECLARE_INTERCEPT_SYMBOLS(APP) \
33  class APP \
34  { \
35  public: \
36  void Stepping(); \
37  void FinishEvent(); \
38  void FinishRun(); \
39  };
40 
42 
43 extern "C" void performLogging(FairMCApplication *);
44 extern "C" void dispatchStepping(FairMCApplication *, char const *libname, char const *);
45 extern "C" void dispatchFinishEvent(FairMCApplication *, char const *libname, char const *);
46 extern "C" void dispatchFinishRun(FairMCApplication *, char const *libname, char const *);
47 extern "C" void flushLog();
48 extern "C" void flushFinalLog();
49 
50 #define INTERCEPT_STEPPING(APP, LIB, SYMBOL) \
51  void APP::Stepping() \
52  { \
53  auto baseptr = reinterpret_cast<FairMCApplication *>(this); \
54  performLogging(baseptr); \
55  dispatchStepping(baseptr, LIB, SYMBOL); \
56  }
57 
58 #define INTERCEPT_FINISHEVENT(APP, LIB, SYMBOL) \
59  void APP::FinishEvent() \
60  { \
61  auto baseptr = reinterpret_cast<FairMCApplication *>(this); \
62  flushLog(); \
63  dispatchFinishEvent(baseptr, LIB, SYMBOL); \
64  }
65 
66 #define INTERCEPT_FINISHRUN(APP, LIB, SYMBOL) \
67  void APP::FinishRun() \
68  { \
69  auto baseptr = reinterpret_cast<FairMCApplication *>(this); \
70  flushFinalLog(); \
71  dispatchFinishRun(baseptr, LIB, SYMBOL); \
72  }
73 
74 // the runtime will now dispatch to these functions due to LD_PRELOAD
75 INTERCEPT_STEPPING(FairMCApplication, "libBase", "_ZN17FairMCApplication8SteppingEv")
76 INTERCEPT_FINISHEVENT(FairMCApplication, "libBase", "_ZN17FairMCApplication11FinishEventEv")
77 INTERCEPT_FINISHRUN(FairMCApplication, "libBase", "_ZN17FairMCApplication9FinishRunEv")
#define INTERCEPT_FINISHEVENT(APP, LIB, SYMBOL)
void dispatchFinishEvent(FairMCApplication *, char const *libname, char const *)
#define INTERCEPT_FINISHRUN(APP, LIB, SYMBOL)
void dispatchStepping(FairMCApplication *, char const *libname, char const *)
#define INTERCEPT_STEPPING(APP, LIB, SYMBOL)
void flushLog()
void flushFinalLog()
void dispatchFinishRun(FairMCApplication *, char const *libname, char const *)
#define DECLARE_INTERCEPT_SYMBOLS(APP)
void performLogging(FairMCApplication *)