Belle II Software development
ParticleCopierModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <analysis/modules/ParticleCopier/ParticleCopierModule.h>
11
12
13// framework - DataStore
14#include <framework/datastore/StoreObjPtr.h>
15
16// framework aux
17#include <framework/logging/Logger.h>
18
19// dataobjects
20#include <analysis/dataobjects/Particle.h>
21#include <analysis/dataobjects/ParticleList.h>
22
23// utilities
24#include <analysis/utility/ParticleCopy.h>
25
26using namespace std;
27using namespace Belle2;
28
29//-----------------------------------------------------------------
30// Register module
31//-----------------------------------------------------------------
32
33REG_MODULE(ParticleCopier);
34
35//-----------------------------------------------------------------
36// Implementation
37//-----------------------------------------------------------------
38
40{
41 setDescription("Replaces each Particle in the ParticleList with its copy.\n"
42 "Particle's (grand)^n-daughter Particles are copied as well.\n"
43 "The existing relations of the original Particle (or it's (grand-)^n-daughters)\n"
44 "are copied as well.");
46
47 // Add parameters
48 vector<string> defaultList;
49 addParam("inputListNames", m_inputListNames,
50 "list of input ParticleList names", defaultList);
51}
52
54{
55 // Input lists
56 for (const std::string& listName : m_inputListNames) {
58 }
59}
60
62{
63 // copy all particles from input lists that pass selection criteria into plist
64 for (const auto& inputListName : m_inputListNames) {
65 const StoreObjPtr<ParticleList> plist(inputListName);
66
67 bool isReserved = plist->getIsReserved();
68 if (isReserved)
69 plist->setEditable(true);
70
71 const unsigned int origSize = plist->getListSize();
72 std::vector<Particle*> copies(origSize);
73
74 for (unsigned i = 0; i < origSize; i++) {
75 const Particle* origP = plist->getParticle(i);
76
77 // copy the particle
79 copies.at(i) = copyP;
80 }
81
82 // clear the original list and fill it with copies
83 plist->clear();
84 for (unsigned i = 0; i < origSize; i++)
85 plist->addParticle(copies[i]);
86
87 unsigned int copySize = plist->getListSize();
88
89 // cppcheck-suppress knownConditionTrueFalse; we know that this shouldn't happen
90 if (copySize != origSize)
91 B2FATAL("Size of the ParticleList " << inputListName
92 << " has changed while copying the Particles! original size = "
93 << origSize << " vs. new size = " << copySize);
94
95 if (isReserved)
96 plist->setEditable(false);
97 }
98}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::vector< std::string > m_inputListNames
input ParticleList names
Class to store reconstructed particles.
Definition: Particle.h:75
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Definition: ParticleCopy.cc:18
Abstract base class for different kinds of events.
STL namespace.