ATLAS Offline Software
FillerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
14 #include "FillerAlg.h"
15 #include "D3PDMakerTest/Obj1.h"
16 #include "D3PDMakerTest/Obj3.h"
17 #include "D3PDMakerTest/Obj4.h"
18 #include "D3PDMakerTest/Obj5.h"
19 #include "D3PDMakerTest/MyVec2.h"
24 #include <sstream>
25 #include <stdint.h>
26 
27 
28 using CLHEP::GeV;
29 using std::make_unique;
30 
31 
32 namespace D3PDTest {
33 
34 
35 // Dufus-quality RNG, using LCG. Constants from numerical recipies.
36 // I don't particularly care about RNG quality here, just about
37 // getting something that's reproducible.
38 std::atomic<uint32_t> seed = 1;
39 const uint32_t rngmax = static_cast<uint32_t> (-1);
41 {
42  seed = (1664525*seed + 1013904223);
43  return seed;
44 }
45 
46 double randf (double rmax, double rmin = 0)
47 {
48  return static_cast<double>(rng()) / rngmax * (rmax-rmin) + rmin;
49 }
50 
51 
52 
53 
59 FillerAlg::FillerAlg (const std::string& name,
60  ISvcLocator* svcloc)
61  : AthAlgorithm (name, svcloc),
62  m_count (0)
63 {
64  declareProperty ("SGKeyObj1Cont", m_sgkeyObj1cont = "obj1container");
65  declareProperty ("SGKeyObj1Sel", m_sgkeyObj1sel = "obj1sel");
66  declareProperty ("SGKeyObj1", m_sgkeyObj1 = "obj1");
67  declareProperty ("SGKeyObj3Cont", m_sgkeyObj3cont = "obj3container");
68  declareProperty ("SGKeyObj4Cont", m_sgkeyObj4cont = "obj4container");
69  declareProperty ("SGKeyObj5Cont", m_sgkeyObj5cont = "obj5container");
70 }
71 
72 
77 {
78  Obj1Container::dvlinfo(); // TEMP
79  m_count = 0;
80  return AthAlgorithm::initialize();
81 }
82 
83 
88 {
89  return AthAlgorithm::finalize();
90 }
91 
92 
97 {
100  for (unsigned i = 0; i < 10; i++) {
101  Obj1* o1 = new Obj1 (10*m_count + i);
102  for (unsigned int j=0; j < i; j++)
103  o1->m_vo2.push_back (Obj2 (10*m_count + i + 100*j));
104  c->push_back (o1);
105 
106  if (i % (m_count+1) == 0)
107  s->SetBit (i);
108  }
109  CHECK( this->evtStore()->record (c, m_sgkeyObj1cont) );
110  CHECK( this->evtStore()->record (s, m_sgkeyObj1sel) );
111 
112  Obj1* o1 = new Obj1;
113  for (int i = 0; i < m_count; i++)
114  o1->m_vo2.push_back (Obj2 (i + 23*m_count));
115  for (int i = 0; i < 2*m_count; i++)
116  o1->m_vo3.push_back (Obj2 (i + 27*m_count));
117  c = new Obj1Container;
118  c->push_back (o1);
119  CHECK( this->evtStore()->record (c, m_sgkeyObj1) );
120 
121  return StatusCode::SUCCESS;
122 }
123 
124 
129 {
131  for (unsigned i = 0; i < 10; i++) {
132  double pt = randf(100*GeV);
133  double eta = randf(5, -5);
134  double phi = randf(-M_PI, M_PI);
135  double m = randf(10*GeV);
136  Obj3* o3 = new Obj3 (pt, eta, phi, m);
137  c->push_back (o3);
138  }
139  CHECK( this->evtStore()->record (c, m_sgkeyObj3cont) );
140  return StatusCode::SUCCESS;
141 }
142 
143 
148 {
150  for (unsigned i = 0; i < 10; i++) {
151  Obj4* o4 = new Obj4 (30*m_count + i);
152  c->push_back (o4);
153  }
154  CHECK( this->evtStore()->record (c, m_sgkeyObj4cont) );
155 
156  return StatusCode::SUCCESS;
157 }
158 
159 
164 {
165  auto c = make_unique<Obj5Container>();
166  auto store = make_unique<SG::AuxStoreInternal>();
167  c->setStore (store.get());
168 
169  static const Obj5::Accessor<int> anInt ("anInt");
170  static const Obj5::Accessor<float> aFloat ("aFloat");
171  static const Obj5::Accessor<std::string> aString ("aString");
172  static const Obj5::Accessor<D3PDTest::MyVec2> aFourvec ("aFourvec");
173 
174  for (unsigned i = 0; i < 10; i++) {
175  c->push_back (make_unique<Obj5> (300*m_count + i));
176  anInt(*c->back()) = 400*m_count + i;
177  aFloat(*c->back()) = 500*m_count + i + 0.5;
178 
179  std::ostringstream os;
180  os << "aux " << 600*m_count + i;
181  aString(*c->back()) = os.str();
182 
183  double pt = randf(100*GeV);
184  double eta = randf(-5, 5);
185  double phi = randf(-M_PI, M_PI);
186  double m = randf(10*GeV);
187  aFourvec(*c->back()).SetPtEtaPhiM (pt, eta, phi, m);
188  }
189  CHECK( this->evtStore()->record (std::move(c), m_sgkeyObj5cont) );
190  CHECK( this->evtStore()->record (std::move(store), m_sgkeyObj5cont + "Aux.") );
191 
192  return StatusCode::SUCCESS;
193 }
194 
195 
200 {
205 
206  ++m_count;
207  return StatusCode::SUCCESS;
208 }
209 
210 
211 } // namespace D3PDTest
D3PDTest::FillerAlg::execute
virtual StatusCode execute()
Standard Gaudi execute method.
Definition: FillerAlg.cxx:199
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
D3PDTest::FillerAlg::finalize
virtual StatusCode finalize()
Standard Gaudi finalize method.
Definition: FillerAlg.cxx:87
D3PDTest::Obj1
Test class for D3PD maker.
Definition: Obj1.h:38
D3PDTest::FillerAlg::m_sgkeyObj1
std::string m_sgkeyObj1
Definition: FillerAlg.h:72
initialize
void initialize()
Definition: run_EoverP.cxx:894
D3PDTest::Obj3
Test class for D3PD maker.
Definition: Obj3.h:33
test_pyathena.pt
pt
Definition: test_pyathena.py:11
M_PI
#define M_PI
Definition: ActiveFraction.h:11
SelectedParticles.h
D3PDTest::Obj1Container
Definition: Obj1.h:66
D3PDTest::rng
uint32_t rng()
Definition: FillerAlg.cxx:40
D3PDTest::FillerAlg::m_count
int m_count
Definition: FillerAlg.h:77
D3PDTest::FillerAlg::m_sgkeyObj1sel
std::string m_sgkeyObj1sel
Definition: FillerAlg.h:71
D3PDTest::rngmax
const uint32_t rngmax
Definition: FillerAlg.cxx:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
INavigable4MomentumCollection
DataVector< INavigable4Momentum > INavigable4MomentumCollection
Definition: INavigable4MomentumCollection.h:22
Obj4.h
Test class for D3PD maker.
D3PDTest::FillerAlg::fillObj3Collections
StatusCode fillObj3Collections()
Fill collections involving Obj3.
Definition: FillerAlg.cxx:128
lumiFormat.i
int i
Definition: lumiFormat.py:92
Obj5.h
Test class for D3PD maker (aux data).
D3PDTest::FillerAlg::FillerAlg
FillerAlg(const std::string &name, ISvcLocator *svcloc)
Standard Gaudi algorithm constructor.
Definition: FillerAlg.cxx:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
INavigable4MomentumCollection.h
Obj3.h
Test class for D3PD maker.
D3PDTest::randf
double randf(double rmax, double rmin=0)
Definition: FillerAlg.cxx:46
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PDTest::seed
std::atomic< uint32_t > seed
Definition: FillerAlg.cxx:38
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
D3PDTest::FillerAlg::fillObj1Collections
StatusCode fillObj1Collections()
Fill collections involving Obj1/2.
Definition: FillerAlg.cxx:96
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
AthAlgorithm
Definition: AthAlgorithm.h:47
D3PDTest::FillerAlg::fillObj5Collections
StatusCode fillObj5Collections()
Fill collections involving Obj5.
Definition: FillerAlg.cxx:163
MyVec2.h
Test class for D3PD maker.
D3PDTest::FillerAlg::m_sgkeyObj4cont
std::string m_sgkeyObj4cont
Definition: FillerAlg.h:74
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
errorcheck.h
Helpers for checking error return status codes and reporting errors.
D3PDTest::FillerAlg::m_sgkeyObj3cont
std::string m_sgkeyObj3cont
Definition: FillerAlg.h:73
D3PDTest::FillerAlg::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: FillerAlg.cxx:76
SelectedParticles
Definition: SelectedParticles.h:54
Obj1.h
Test class for D3PD maker.
DataVector< Obj1 >::dvlinfo
static const DataModel_detail::DVLInfoBase & dvlinfo()
Return the DV/DL info struct for this class.
D3PDTest::FillerAlg::m_sgkeyObj1cont
std::string m_sgkeyObj1cont
Definition: FillerAlg.h:70
FillerAlg.h
Put objects into StoreGate to test D3PD maker.
D3PDTest::Obj4Container
Definition: Obj4.h:54
D3PDTest
Definition: MapDumper.h:25
python.changerun.o1
o1
Definition: changerun.py:44
AuxStoreInternal.h
An auxiliary data store that holds data internally.
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
python.compressB64.c
def c
Definition: compressB64.py:93
D3PDTest::FillerAlg::fillObj4Collections
StatusCode fillObj4Collections()
Fill collections involving Obj4.
Definition: FillerAlg.cxx:147
D3PDTest::Obj2
Test class for D3PD maker.
Definition: Obj2.h:28
D3PDTest::Obj4
Test class for D3PD maker.
Definition: Obj4.h:34
D3PDTest::FillerAlg::m_sgkeyObj5cont
std::string m_sgkeyObj5cont
Definition: FillerAlg.h:75