ATLAS Offline Software
Loading...
Searching...
No Matches
CaloPrefetch.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef CALOEVENT_CALOPREFETCH_H
8#define CALOEVENT_CALOPREFETCH_H
9//--------------------------------------------------------------------------
10// File and Version Information:
11// $Id$
12//------------------------------------------------------------------------
13
14#include "CxxUtils/prefetch.h"
15#include "CaloEvent/CaloCell.h"
17#include <cstddef>
18
19// ---------------------
20// -- Class Interface --
21// ---------------------
22
32
33namespace CaloPrefetch {
34
35
45template <typename Iter>
46inline
47void nextDDE(Iter iter, Iter endIter)
48{
49 if (++iter != endIter) {
50 // Get DDE, cell itself is expected to be in the cache already
51 CxxUtils::prefetchObj((*iter)->caloDDE());
52 if (++iter != endIter) {
53 // prefetch cell two steps ahead
55 }
56 }
57}
58
70template <typename Iter>
71inline
72void nextDDE(Iter iter, Iter endIter, int count)
73{
74 for (int i = 0; i != count; ++ i) {
75 if (++iter != endIter) {
76 // Get DDE, cell itself is expected to be in the cache already
77 CxxUtils::prefetchObj((*iter)->caloDDE());
78 } else {
79 return;
80 }
81 }
82 for (int i = 0; i != count; ++ i) {
83 if (++iter != endIter) {
84 // prefetch cell two steps ahead
86 } else {
87 return;
88 }
89 }
90}
91
101template <class T, class ALLOC, int COUNT=1>
102class ArenaHandlePrefetch : public SG::ArenaHandle<T, ALLOC>{
103
105
106public:
107
112 {
113 for (int i = 0; i != COUNT; ++ i) {
114 m_buf[i] = Base::allocate();
115 }
116 for (int i = 0; i != COUNT; ++ i) {
118 }
119 }
120
124 void* allocate()
125 {
126 void* res = m_buf[0];
127 std::move(m_buf + 1, m_buf + COUNT, m_buf);
128 m_buf[COUNT-1] = Base::allocate();
130 return res;
131 }
132
136 void erase() {
137 Base::erase();
138 for (int i = 0; i != COUNT; ++ i) {
139 m_buf[i] = Base::allocate();
140 }
141 for (int i = 0; i != COUNT; ++ i) {
143 }
144 }
145
146private:
147 void* m_buf[COUNT];
148};
149
150} // namespace CaloPrefetch
151
152
153#endif // CALOEVENT_CALOPREFETCH_H
User interface for allocating memory. See Arena.h for an overview of the arena-based memory allocator...
std::pair< std::vector< unsigned int >, bool > res
SG::ArenaHandle< T, ALLOC > Base
void * allocate()
Return space for new element, then allocate and prefetch one more.
void erase()
Free all allocated elements.
void erase()
Free all allocated elements and release memory back to the system (of this type in the current Arena)...
User interface for allocating memory.
Definition ArenaHandle.h:73
void * allocate()
Allocate a new element.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
This software was developed for the ATLAS project.
void nextDDE(Iter iter, Iter endIter)
Prefetch next CaloDDE.
void prefetchN(const void *ptr)
Prefetch an N-byte block of memory.
Definition prefetch.h:85
void prefetchObj(const T *ptr)
Generic prefetch of the object of specific types (sizes).
Definition prefetch.h:108
Functions to prefetch blocks of memory.