Project
Loading...
Searching...
No Matches
GeneratorTParticle.cxx
Go to the documentation of this file.
1// Copyright 2023-2099 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
16#include <SimConfig/SimConfig.h>
17#include <fairlogger/Logger.h>
18#include <TFile.h>
19#include <TChain.h>
20#include <TClonesArray.h>
21#include <TParticle.h>
22
23namespace o2
24{
25namespace eventgen
26{
27/*****************************************************************/
32
33/*****************************************************************/
35{
36 if (mChain) {
37 TFile* file = mChain->GetCurrentFile();
38 if (file) {
39 mChain->RecursiveRemove(file);
40 }
41 delete mChain;
42 }
43 if (mCmd.empty()) {
44 return;
45 }
46 // Must be executed before removing the temporary file, otherwise the child
47 // process might still be writing to it
48 stop();
49 removeTemp();
50}
51/*****************************************************************/
53{
54 if (mCmd.empty()) {
55 return;
56 }
58}
59/*****************************************************************/
61{
62 mChain = new TChain(mTreeName.c_str());
63 mTParticles = new TClonesArray("TParticle");
64 mChain->SetBranchAddress(mBranchName.c_str(), &mTParticles);
65
66 if (not mCmd.empty()) {
67 if (mFileNames.empty()) {
68 // Set filename to be a temporary name
69 if (not makeTemp(false)) {
70 return false;
71 }
72 } else {
73 // Use the first filename as output for cmd line
74 if (not makeTemp(true)) {
75 return false;
76 }
77 }
78
79 // Build command line, Assumes command line parameter
80 std::string cmd = makeCmdLine();
81 LOG(info) << "EG command line is \"" << cmd << "\"";
82
83 // Execute the background command
84 if (not executeCmdLine(cmd)) {
85 LOG(fatal) << "Failed to spawn \"" << cmd << "\"";
86 return false;
87 }
88 }
89 for (auto filename : mFileNames) {
90 mChain->AddFile(filename.c_str());
91 }
92
93 // Clear the array of file names
94 mFileNames.clear();
95
96 return true;
97}
98
99/*****************************************************************/
102 const conf::SimConfig& config)
103{
104 GeneratorFileOrCmd::setup(param0, config);
105 setTreeName(param.treeName);
106 setBranchName(param.branchName);
107}
108
109/*****************************************************************/
111{
112 // If this is the first entry, and we're executing a command, then
113 // wait until the input file exists and actually contain some data.
114 if (mEntry == 0 and not mCmd.empty()) {
116 }
117
118 // Read in the next entry in the chain
119 int read = mChain->GetEntry(mEntry);
120 mEntry++;
121
122 // If we got an error while reading, then give error message
123 if (read < 0) {
124 LOG(error) << "Failed to read entry " << mEntry << " of chain";
125 }
126
127 // If we had an error or nothing was read back, then return false
128 if (read <= 0) {
129 return false;
130 }
131
132 return true;
133}
134
136{
137 for (auto* object : *mTParticles) {
138 TParticle* particle = static_cast<TParticle*>(object);
139 auto statusCode = particle->GetStatusCode();
140 if (!mcgenstatus::isEncoded(statusCode)) {
141 statusCode = mcgenstatus::MCGenStatusEncoding(statusCode, 0)
143 }
144
145 mParticles.emplace_back(particle->GetPdgCode(),
146 statusCode,
147 particle->GetFirstMother(),
148 particle->GetSecondMother(),
149 particle->GetFirstDaughter(),
150 particle->GetLastDaughter(),
151 particle->Px(),
152 particle->Py(),
153 particle->Pz(),
154 particle->Energy(),
155 particle->Vx(),
156 particle->Vy(),
157 particle->Vz(),
158 particle->T());
159 auto& tgt = mParticles[mParticles.size() - 1];
160 tgt.SetPolarTheta(particle->GetPolarTheta());
161 tgt.SetPolarPhi(particle->GetPolarPhi());
162 tgt.SetCalcMass(particle->GetCalcMass());
163 tgt.SetWeight(particle->GetWeight());
164 }
165 return true;
166}
167} // namespace eventgen
168} // namespace o2
169//
170// EOF
171//
void setup(const GeneratorFileOrCmdParam &param0, const GeneratorTParticleParam &param, const conf::SimConfig &config)
void setBranchName(const std::string &val)
void setTreeName(const std::string &val)
std::vector< TParticle > mParticles
Definition Generator.h:151
GLuint object
Definition glcorearb.h:4041
GLenum GLfloat param
Definition glcorearb.h:271
bool isEncoded(MCGenStatusEncoding statusCode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
void setup(const GeneratorFileOrCmdParam &param, const conf::SimConfig &config)
std::list< std::string > mFileNames
void setOutputSwitch(const std::string &opt)
static constexpr unsigned int sStopGraceMillis
virtual bool terminateCmd(unsigned int graceMillis=0)
virtual std::string makeCmdLine() const
virtual void waitForData(const std::string &filename) const
virtual bool executeCmdLine(const std::string &cmd)
virtual bool makeTemp(const bool &)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"