ATLAS Offline Software
LWPoolArea.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 
7 // //
8 // Implementation of class LWPoolArea //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: April 2009 //
12 // //
14 
15 #include "LWPoolArea.h"
16 #ifndef NDEBUG
17 #include <iostream>
18 #endif
19 
20 //____________________________________________________________________
21 unsigned LWPoolArea::calcNChunks(unsigned chunksize,unsigned length_of_mem)
22 {
23  assert(chunksize<UINT_MAX);
24  unsigned nchunks;
25  //ntotbytes will be used like this:
26  //
27  // [The AllocArea class]
28  // [The book-keeper class + the internal fields in the book-keeper class]
29  // [area=nchunks*chunksize][<chunksize bytes]
30  //
31  // The difficult part is the second field, which depends on nchunks.
32 
33  //1) Trivially remove the bytes needed for AllocArea:
34  const unsigned ntotbytes = length_of_mem-sizeof(LWPoolArea);
35 
36  //2) Get an upper limit for nchunks, assuming the internal book-keeper fields are zero length:
37  nchunks = ntotbytes/chunksize;
38 
39  //3) How many bytes, if any, are we in the red now?
40 
41  int balance = ntotbytes - nchunks*chunksize - LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks);
42  if (balance<0) {
43  nchunks -= (-balance)/chunksize;
44  //Should be ok now, but now we might have undershot a bit, since
45  //the number of internal bins might have come down! Jeeesus...:
46  while (ntotbytes >= nchunks*chunksize + LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks))
47  ++nchunks;
48  --nchunks;
49  }
50  assert(ntotbytes >= nchunks*chunksize + LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks));
51 #ifndef NDEBUG
52  long wastage = ntotbytes - nchunks*chunksize-LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks);
53  assert(wastage>=0);
54  assert(wastage<std::max(9l,long(chunksize+sizeof(LWPoolAreaBookKeeper::BitField))));
55  if (wastage*1.0>0.05*ntotbytes||wastage>640) {
56  std::cout<<"LWHist MemPool (chunksize: "<<chunksize<<") WARNING: Wasting "
57  <<wastage<<" bytes per area ("<<(wastage*100.0/ntotbytes)<<" %)"<<std::endl;
58 
59  std::cout<<"chunksize "<<chunksize<<": totsize:"<<length_of_mem<<std::endl;
60  std::cout<<"chunksize "<<chunksize<<": sizeof(LWPoolArea):"<<sizeof(LWPoolArea)<<std::endl;
61  std::cout<<"chunksize "<<chunksize<<": bytes for bookkeep:"<<LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks)<<std::endl;
62  unsigned bytes_useful(nchunks*chunksize);
63  unsigned bytes_overhead(length_of_mem-bytes_useful);
64  std::cout<<"chunksize "<<chunksize<<": nchunks:"<<nchunks<<" => "<<bytes_useful<<" bytes"<<std::endl;
65  std::cout<<"chunksize "<<chunksize<<": rounding wastage:"<<wastage<<std::endl;
66  std::cout<<"chunksize "<<chunksize<<": total overhead:"
67  <<bytes_overhead<<" ("<<bytes_overhead*100.0/bytes_useful<<"% ~ "
68  <<bytes_overhead*CHAR_BIT*1.0/nchunks<<" bits/chunk)"<<std::endl;
69  }
70 #endif
71  return nchunks;
72 
73 }
max
#define max(a, b)
Definition: cfImp.cxx:41
LWPoolAreaBookKeeper::BitField
unsigned BitField
Definition: LWPoolAreaBookKeeper.h:48
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
LWPoolAreaBookKeeper::nBytesNeededForCreate
static unsigned nBytesNeededForCreate(unsigned nEntries)
Definition: LWPoolAreaBookKeeper.cxx:25
LWPoolArea.h
LWPoolArea::calcNChunks
static unsigned calcNChunks(unsigned chunksize, unsigned length_of_mem)
Definition: LWPoolArea.cxx:21
LWPoolArea::LWPoolArea
LWPoolArea(const LWPoolArea &)