ATLAS Offline Software
PoolAttributeHelper.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 """ A basic module that helps with setting various common Pool Attributes """
4 
5 def setPoolAttribute( **kwargs ):
6  """ The low-level function that builds the requested Pool Attribure string. """
7 
8  # Resolve the variables for convenience
9  fileName = kwargs.get('fileName')
10  contName = kwargs.get('contName')
11  attrName = kwargs.get('attrName')
12  attrValue = kwargs.get('attrValue')
13 
14  # Now let's build the string
15  result = ""
16 
17  # First set the domain attribute
18  if not attrName or not attrValue:
19  return result
20  result += f"{attrName} = '{attrValue}';"
21 
22  # Then set database and container level attributes
23  # These are optional: can set both, only one, or neither
24  if contName:
25  result = f"ContainerName = '{contName}'; {result}"
26  if fileName:
27  result = f"DatabaseName = '{fileName}'; {result}"
28 
29  # Finally return the result
30  return result
31 
32 def setFileCompAlg( fileName = None, compAlg = None ):
33  """ Convenience method for setting the compression algorithm for a given file. """
34 
35  return setPoolAttribute( fileName = fileName,
36  attrName = "COMPRESSION_ALGORITHM",
37  attrValue = compAlg )
38 
39 def setFileCompLvl( fileName = None, compLvl = None ):
40  """ Convenience method for setting the compression level for a given file. """
41 
42  return setPoolAttribute( fileName = fileName,
43  attrName = "COMPRESSION_LEVEL",
44  attrValue = compLvl )
45 
46 def setMaxBufferSize( fileName = None, bufferSize = None ):
47  """ Convenience method for setting the maximum basket buffer size """
48 
49  return setPoolAttribute( fileName = fileName,
50  attrName = "MAXIMUM_BUFFERSIZE",
51  attrValue = bufferSize )
52 
53 def setMinBufferEntries( fileName = None, nEntries = None ):
54  """ Convenience method for setting the minimum basket buffer entries """
55 
56  return setPoolAttribute( fileName = fileName,
57  attrName = "MINIMUM_BUFFERENTRIES",
58  attrValue = nEntries )
59 
60 def setTreeAutoFlush( fileName = None, treeName = None, autoFlush = None ):
61  """ Convenience method for setting the AutoFlush for a tree in a given file. """
62 
63  return setPoolAttribute( fileName = fileName,
64  contName = f"TTree={treeName}",
65  attrName = "TREE_AUTO_FLUSH",
66  attrValue = autoFlush )
67 
68 def setContainerSplitLevel( fileName = None, treeName = None, splitLvl = None ):
69  """ Convenience method for setting the split level for a tree in a given file. """
70 
71  return setPoolAttribute( fileName = fileName,
72  contName = f"TTree={treeName}",
73  attrName = "CONTAINER_SPLITLEVEL",
74  attrValue = splitLvl )
75 
76 def setBranchBasketSize( fileName = None, treeName = None, basketSize = None ):
77  """ Convenience method for setting the branch basket size for a tree in a given file. """
78 
79  return setPoolAttribute( fileName = fileName,
80  contName = f"TTree={treeName}",
81  attrName = "BRANCH_BASKET_SIZE",
82  attrValue = basketSize )
83 
84 # Main Function: Only to check the basic functionality
85 # Can be run via python PoolAttributeHelper.py
86 if "__main__" in __name__:
87 
88  # Test Basic Functionality
89  attrs = []
90 
91  # High-level
92  attrs += [ setFileCompAlg( "AOD.pool.root", 2 ) ]
93  attrs += [ setFileCompLvl( "AOD.pool.root", 1 ) ]
94  attrs += [ setMaxBufferSize( "*", 131072 ) ]
95  attrs += [ setMinBufferEntries( "*", 10 ) ]
96  attrs += [ setTreeAutoFlush( "AOD.pool.root", "CollectionTree", 10 ) ]
97  attrs += [ setContainerSplitLevel( None, "POOLContainerForm(DataHeaderForm)", 99 ) ]
98 
99  # Low-level
100  attrs += [ setPoolAttribute( attrName = "DEFAULT_SPLITLEVEL", attrValue = 0) ]
101 
102  # Print the configuration
103  for attr in attrs:
104  print( f"{attr}" )
python.PoolAttributeHelper.setTreeAutoFlush
def setTreeAutoFlush(fileName=None, treeName=None, autoFlush=None)
Definition: PoolAttributeHelper.py:60
python.PoolAttributeHelper.setFileCompLvl
def setFileCompLvl(fileName=None, compLvl=None)
Definition: PoolAttributeHelper.py:39
python.PoolAttributeHelper.setMinBufferEntries
def setMinBufferEntries(fileName=None, nEntries=None)
Definition: PoolAttributeHelper.py:53
python.PoolAttributeHelper.setPoolAttribute
def setPoolAttribute(**kwargs)
Definition: PoolAttributeHelper.py:5
python.PoolAttributeHelper.setBranchBasketSize
def setBranchBasketSize(fileName=None, treeName=None, basketSize=None)
Definition: PoolAttributeHelper.py:76
python.PoolAttributeHelper.setFileCompAlg
def setFileCompAlg(fileName=None, compAlg=None)
Definition: PoolAttributeHelper.py:32
python.PoolAttributeHelper.setContainerSplitLevel
def setContainerSplitLevel(fileName=None, treeName=None, splitLvl=None)
Definition: PoolAttributeHelper.py:68
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.PoolAttributeHelper.setMaxBufferSize
def setMaxBufferSize(fileName=None, bufferSize=None)
Definition: PoolAttributeHelper.py:46