Belle II Software  release-06-00-14
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 
28 namespace Belle2 {
34  //-----------------------------------------------------------------
35  // Register module
36  //-----------------------------------------------------------------
37 
38  REG_MODULE(ParticleCopier)
39 
40  //-----------------------------------------------------------------
41  // Implementation
42  //-----------------------------------------------------------------
43 
45  {
46  setDescription("Replaces each Particle in the ParticleList with its copy.\n"
47  "Particle's (grand)^n-daughter Particles are copied as well.\n"
48  "The existing relations of the original Particle (or it's (grand-)^n-daughters)\n"
49  "are copied as well.");
50  setPropertyFlags(c_ParallelProcessingCertified);
51 
52  // Add parameters
53  vector<string> defaultList;
54  addParam("inputListNames", m_inputListNames,
55  "list of input ParticleList names", defaultList);
56  }
57 
58  void ParticleCopierModule::initialize()
59  {
60  // Input lists
61  for (const std::string& listName : m_inputListNames) {
63  }
64  }
65 
66  void ParticleCopierModule::event()
67  {
68  // copy all particles from input lists that pass selection criteria into plist
69  for (const auto& inputListName : m_inputListNames) {
70  const StoreObjPtr<ParticleList> plist(inputListName);
71 
72  const unsigned int origSize = plist->getListSize();
73  std::vector<Particle*> copies(origSize);
74 
75  for (unsigned i = 0; i < origSize; i++) {
76  const Particle* origP = plist->getParticle(i);
77 
78  // copy the particle
79  Particle* copyP = ParticleCopy::copyParticle(origP);
80  copies.at(i) = copyP;
81  }
82 
83  // clear the original list and fill it with copies
84  plist->clear();
85  for (unsigned i = 0; i < origSize; i++)
86  plist->addParticle(copies[i]);
87 
88  unsigned int copySize = plist->getListSize();
89 
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  }
96  }
98 } // end Belle2 namespace
Base class for Modules.
Definition: Module.h:72
Module for creating copies of Particles.
Class to store reconstructed particles.
Definition: Particle.h:74
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
virtual void clear()
Clear contents of this object.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.