Belle II Software  light-2205-abys
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 include
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 
26 using namespace std;
27 using namespace Belle2;
28 
29 //-----------------------------------------------------------------
30 // Register module
31 //-----------------------------------------------------------------
32 
33 REG_MODULE(ParticleCopier);
34 
35 //-----------------------------------------------------------------
36 // Implementation
37 //-----------------------------------------------------------------
38 
39 ParticleCopierModule::ParticleCopierModule() : Module()
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  const unsigned int origSize = plist->getListSize();
68  std::vector<Particle*> copies(origSize);
69 
70  for (unsigned i = 0; i < origSize; i++) {
71  const Particle* origP = plist->getParticle(i);
72 
73  // copy the particle
74  Particle* copyP = ParticleCopy::copyParticle(origP);
75  copies.at(i) = copyP;
76  }
77 
78  // clear the original list and fill it with copies
79  plist->clear();
80  for (unsigned i = 0; i < origSize; i++)
81  plist->addParticle(copies[i]);
82 
83  unsigned int copySize = plist->getListSize();
84 
85  // cppcheck-suppress knownConditionTrueFalse; we know that this shouldn't happen
86  if (copySize != origSize)
87  B2FATAL("Size of the ParticleList " << inputListName
88  << " has changed while copying the Particles! original size = "
89  << origSize << " vs. new size = " << copySize);
90 
91  }
92 }
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:74
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:95
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.
Definition: ClusterUtils.h:23