forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergerCache.h
More file actions
95 lines (76 loc) · 2.99 KB
/
MergerCache.h
File metadata and controls
95 lines (76 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef ALICEO2_MERGERCACHE_H
#define ALICEO2_MERGERCACHE_H
/// \file MergerCache.h
/// \brief Definition of O2 Merger cache, v0.1
///
/// \author Piotr Konopka, piotr.jan.konopka@cern.ch
#include <Framework/InputRecord.h>
#include <TObject.h>
#include <memory>
#include <vector>
#include <deque>
namespace o2
{
namespace experimental::mergers
{
/// \brief Merger cache to store input objects before merging them.
class MergerCache
{
/// \brief Cache entry storing one mergable object.
struct CacheEntry {
std::unique_ptr<TObject, void (*)(TObject*)> obj;
bool is_merged = false;
};
/// \biref Cache entry queue storing multiple mergable objects received at one input.
struct CacheEntryQueue {
std::deque<CacheEntry> deque;
bool was_updated = false;
};
public:
/// \brief Default constructor. When overwrite == true, only one object per input is stored.
MergerCache(bool overwrite = true);
/// \brief Default destructor.
~MergerCache() = default;
/// \brief Stores input objects from InputRecord into the cache
void cacheInputRecord(const framework::InputRecord& inputs);
size_t size();
void clear();
bool uninitialized();
const CacheEntryQueue& operator[](size_t i) const;
using const_iterator = std::vector<CacheEntryQueue>::const_iterator;
const_iterator begin() const { return mCache.begin(); }
const_iterator end() const { return mCache.end(); }
void setMerged(size_t i, size_t entry, bool merged = true);
void setAllMerged(bool merged = true);
void setUpdated(size_t i, bool updated = true);
void setAllUpdated(bool updated = true);
// returns the number of inputs that have been updated since the last time the flag was cleared (last publication)
size_t updatedInputs();
// returns the number of inputs that have some corresponding objects cached
size_t cachedInputs();
private:
/// \brief Initializes the cache by seeing the size and contents of DPL's InputRecord
void init(const framework::InputRecord& inputs);
static void deleteTCollections(TObject* obj);
std::vector<CacheEntryQueue> mCache;
// when active, cache keeps only one entry per queue (per input)
bool mOverwrite;
// keeps the index of the timer in the InputRecord
int mTimerPosition{-1};
// counts how many inputs have some corresponding objects cached
size_t mCachedInputs{0};
// counts how many inputs have been updated since the last time the flag was cleared (last publication)
size_t mUpdatedInputs{0};
};
} // namespace experimental::mergers
} // namespace o2
#endif //ALICEO2_MERGERCACHE_H