Project
Loading...
Searching...
No Matches
O2MCApplication.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_MC_APPLICATION_H
13#define O2_MC_APPLICATION_H
14
15#include "FairMCApplication.h"
17#include "Rtypes.h" // for Int_t, Bool_t, Double_t, etc
18#include <iostream>
19#include <TParticle.h>
20#include <vector>
21#include <DetectorsBase/Stack.h>
23#include <FairRootManager.h>
24#include <FairDetector.h>
25
26#include <fairmq/FwdDecls.h>
27#include <TRandom.h>
28#include <memory>
29
30namespace o2
31{
32namespace steer
33{
34
35// O2 specific changes/overrides to FairMCApplication
36// (like for device based processing in which we
37// forward the data instead of using FairRootManager::Fill())
39{
40 public:
42 ~O2MCApplication() override = default;
43
44 // multithreaded Geant4: each worker thread gets its own copy of the application
46 TVirtualMCApplication* CloneForWorker() const override;
47 void InitOnWorker() override;
48 void BeginRunOnWorker() override;
49 void FinishRunOnWorker() override;
50
52 void BeginEvent() override;
53
54 // triggers data sending/io
55 void SendData();
56
57 void initLate();
58
60 void FinishEvent() override
61 {
62 if (mIsEndOfWork) {
63 // the empty event that ends a worker thread's loop: nothing to send
64 for (auto det : listActiveDetectors) {
65 det->EndOfEvent();
66 }
67 fStack->Reset();
68 return;
69 }
70 // update the stack
73
75
76 // detectors finalize their hits (e.g. sorting, summing duplicates) before these are sent
77 for (auto det : listActiveDetectors) {
78 det->FinishEvent();
79 }
80
81 // This special finish event version does not fill the output tree of FairRootManager
82 // but forwards the data to the HitMerger
83 SendData();
84
85 // call end of event on active detectors
86 for (auto det : listActiveDetectors) {
87 det->EndOfEvent();
88 }
89 fStack->Reset();
90 }
91
93 void FinishRun();
94
95 void attachSubEventInfo(fair::mq::Parts&, o2::data::SubEventInfo const& info) const;
96
98 void GeneratePrimaries() override
99 {
100 // ordinarily we would call the event generator ...
101 LOG(debug) << "O2MCApplication: Init primaries from external buffer " << mPrimaries.size();
102 GetStack()->Reset();
103 // but here we init the stack from
104 // a vector of particles that someone sets externally
105 static_cast<o2::data::Stack*>(GetStack())->initFromPrimaries(mPrimaries);
106 }
107
108 void setPrimaries(std::vector<TParticle> const& p)
109 {
110 mPrimaries = p;
111 }
112 void setPrimaries(std::vector<TParticle>&& p)
113 {
114 mPrimaries = std::move(p);
115 }
116
118 static bool isSelectedSubEvent(int eventID, int part);
119
120 void setSimDataChannel(fair::mq::Channel* channel) { mSimDataChannel = channel; }
122
123 std::vector<TParticle> mPrimaries;
124
125 fair::mq::Channel* mSimDataChannel = nullptr;
127 std::vector<o2::base::Detector*> mActiveO2Detectors;
128
129 private:
130 void fetchWorkerChunk();
131 bool mIsMTWorker = false;
132 bool mIsEndOfWork = false;
133 bool mWorkerInitialized = false;
134 o2::data::SubEventInfo mWorkerSubEventInfo;
135 std::unique_ptr<TRandom> mWorkerRandom;
136
137 ClassDefOverride(O2MCApplication, 1); //Interface to MonteCarlo application
138};
139
140} // end namespace steer
141} // end namespace o2
142
143#endif
Definition of the Stack class.
std::ostringstream debug
int32_t i
virtual void UpdateTrackIndex(TRefArray *)
virtual void FillTrackArray()
virtual void Reset()
std::list< FairDetector * > listActiveDetectors
FairGenericStack * fStack
FairGenericStack * GetStack()
TRefArray * fActiveDetectors
void finishEventCommon()
some common parts of finishEvent
o2::data::SubEventInfo * mSubEventInfo
generic channel on which to send sim data
fair::mq::Channel * mSimDataChannel
std::vector< o2::base::Detector * > mActiveO2Detectors
what are we currently processing?
void setPrimaries(std::vector< TParticle > &&p)
static bool isSelectedSubEvent(int eventID, int part)
whether a sub-event passes the O2SIM_RESTRICT_EVENTPART ("event:part") selection, a debugging aid
void setSimDataChannel(fair::mq::Channel *channel)
void BeginEvent() override
a worker thread asks the primary server for its sub-event here, as a worker process does before Proce...
void GeneratePrimaries() override
void attachSubEventInfo(fair::mq::Parts &, o2::data::SubEventInfo const &info) const
~O2MCApplication() override=default
void setPrimaries(std::vector< TParticle > const &p)
std::vector< TParticle > mPrimaries
TVirtualMCApplication * CloneForWorker() const override
void setSubEventInfo(o2::data::SubEventInfo *i)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"