ATLAS Offline Software
Classes | Functions | Variables
python.AtlCoolTool Namespace Reference

Classes

class  AtlCoolTool
 
class  Info
 
class  InfoList
 

Functions

def expandConnectString (connectString)
 
def connect (connectString, verbose=False)
 
def byteSize (spec)
 

Variables

dictionary typeSizes
 

Function Documentation

◆ byteSize()

def python.AtlCoolTool.byteSize (   spec)
Determines the (effective) byte size of an AttributeListSpecification.
This does not account for any extra size for the specification's own
structure but just the byte sizes of the attributes. In other words an
AttributeListSpecification with a single 'int' fields will report a byte
size of 4.

Definition at line 112 of file AtlCoolTool.py.

112 def byteSize( spec ):
113  """
114  Determines the (effective) byte size of an AttributeListSpecification.
115  This does not account for any extra size for the specification's own
116  structure but just the byte sizes of the attributes. In other words an
117  AttributeListSpecification with a single 'int' fields will report a byte
118  size of 4.
119  """
120  size = 0
121  for i in spec:
122  size += typeSizes[i.storageType().id()]
123  return size
124 
125 
126 

◆ connect()

def python.AtlCoolTool.connect (   connectString,
  verbose = False 
)
Connects to the given database and returns a tuple
   database, connectString
where 'database' is a cool.IDatabase object and 'connectString' is the
possibly expanded connectString that 'database' is based on.

This expansion can occur when a connect string without a containing
'://' is specified. In this case the string is interpreted as a sqlite
file name and rewritten to a RAL compliant format:

    TEST.db  --> 'sqlite://;schema=TEST.db;dbname=TEST'
    TEST     --> 'sqlite://;schema=TEST;dbname=TEST'

The filename can have a '.db' suffix which will be stripped for the
'dbname' part of the connect string. Other suffixes will not be recognized.

Note that the COOL database inside the file must have the same name as the
base of the filename for this shortcut to work. Storing a COOL database
MYTEST in a file mytest.db will not work.

Set verbose to True to obtain an error print out.

Definition at line 45 of file AtlCoolTool.py.

45 def connect( connectString, verbose = False):
46  """
47  Connects to the given database and returns a tuple
48  database, connectString
49  where 'database' is a cool.IDatabase object and 'connectString' is the
50  possibly expanded connectString that 'database' is based on.
51 
52  This expansion can occur when a connect string without a containing
53  '://' is specified. In this case the string is interpreted as a sqlite
54  file name and rewritten to a RAL compliant format:
55 
56  TEST.db --> 'sqlite://;schema=TEST.db;dbname=TEST'
57  TEST --> 'sqlite://;schema=TEST;dbname=TEST'
58 
59  The filename can have a '.db' suffix which will be stripped for the
60  'dbname' part of the connect string. Other suffixes will not be recognized.
61 
62  Note that the COOL database inside the file must have the same name as the
63  base of the filename for this shortcut to work. Storing a COOL database
64  MYTEST in a file mytest.db will not work.
65 
66  Set verbose to True to obtain an error print out.
67  """
68  connectString = expandConnectString( connectString )
69  debug=False
70  if (';readoracle' in connectString):
71  # new default is forceOracle - but giving keyword explicitly
72  # forces debug printout
73  connectString=connectString.replace(';readoracle','')
74  debug=True
75  if (';readsqlite' in connectString):
76  connectString=connectString.replace(';readsqlite','')
77  debug=True
78  try:
79  dbSvc = cool.DatabaseSvcFactory.databaseService()
80  readonly=True
81  # frontier/logical cannot do update connections - only real dbs
82  if ('oracle' in connectString or 'mysql' in connectString or 'sqlite' in connectString): readonly=False
83  db=AtlCoolLib.indirectOpen(connectString,readonly,debug)
84  except Exception as e:
85  if 'The database does not exist' in str(e):
86  print ("Creating new database")
87  db = dbSvc.createDatabase( connectString )
88  else:
89  if verbose: print ('Error while connecting:', str(e))
90  db = None
91  return db, connectString
92 
93 

◆ expandConnectString()

def python.AtlCoolTool.expandConnectString (   connectString)
Expands a connect string.

This expansion can occur when a connect string without a containing
'://' or not in the format 'alias/DBNAME' is specified. In this case
the string is interpreted as a sqlite file name and rewritten to a
COOL compliant format:

    TEST.db  --> 'sqlite://;schema=TEST.db;dbname=TEST'
    TEST     --> 'sqlite://;schema=TEST;dbname=TEST'

The filename can have a '.db' suffix which will be stripped for the
'dbname' part of the connect string. Other suffixes will not be recognized.

Actually for ATLAS, a simple string without / is interpreted as a database
instance name within the SQLite file mycool.db, for consistency with
AtlCoolLib behavior

Definition at line 12 of file AtlCoolTool.py.

12 def expandConnectString( connectString ):
13  """
14  Expands a connect string.
15 
16  This expansion can occur when a connect string without a containing
17  '://' or not in the format 'alias/DBNAME' is specified. In this case
18  the string is interpreted as a sqlite file name and rewritten to a
19  COOL compliant format:
20 
21  TEST.db --> 'sqlite://;schema=TEST.db;dbname=TEST'
22  TEST --> 'sqlite://;schema=TEST;dbname=TEST'
23 
24  The filename can have a '.db' suffix which will be stripped for the
25  'dbname' part of the connect string. Other suffixes will not be recognized.
26 
27  Actually for ATLAS, a simple string without / is interpreted as a database
28  instance name within the SQLite file mycool.db, for consistency with
29  AtlCoolLib behavior
30  """
31  if connectString.find( '://' ) == -1:
32  if connectString.endswith( '.db' ):
33  base = connectString[:-3]
34  elif match("[a-zA-Z0-9_-]+/[A-Z0-9_-]{1,8}",connectString):
35  # it is an alias/DBNAME
36  return connectString
37  else:
38  base = connectString
39  #return ( 'sqlite://;schema=%s;dbname=%s' ) % ( connectString, base )
40  return ('sqlite://;schema=mycool.db;dbname=%s' % base)
41  else:
42  return connectString
43 
44 

Variable Documentation

◆ typeSizes

dictionary python.AtlCoolTool.typeSizes
Initial value:
1 = { cool.StorageType.Bool : 1,
2  cool.StorageType.UChar : 1,
3  cool.StorageType.Int16 : 2,
4  cool.StorageType.UInt16 : 2,
5  cool.StorageType.Int32 : 4,
6  cool.StorageType.UInt32 : 4,
7  cool.StorageType.UInt63 : 8,
8  cool.StorageType.Int64 : 8,
9  cool.StorageType.Float : 4,
10  cool.StorageType.Double : 8,
11  cool.StorageType.String255 : 255,
12  cool.StorageType.String4k : 4000,
13  cool.StorageType.String64k : 65535,
14  cool.StorageType.String16M : 16777215,
15  cool.StorageType.Blob64k : 65535,
16  cool.StorageType.Blob16M : 16777215,
17  }

Definition at line 94 of file AtlCoolTool.py.

python.AtlCoolTool.connect
def connect(connectString, verbose=False)
Definition: AtlCoolTool.py:45
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
python.AtlCoolTool.byteSize
def byteSize(spec)
Definition: AtlCoolTool.py:112
str
Definition: BTagTrackIpAccessor.cxx:11
python.AtlCoolTool.expandConnectString
def expandConnectString(connectString)
Definition: AtlCoolTool.py:12
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356