ATLAS Offline Software
ConditionsContainerAccess.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 # File: IOVDbSvc/python/ConditionsContainerAccess.py
4 # Author: RD Schaffer (R.D.Schaffer@cern.ch)
5 
6 # The ConditionsContainerAccess provides access to the objects
7 # referenced from COOL and stored in POOL.
8 #
9 # Usage:
10 # 1) Create a ConditionsContainerAccess providing theApp from
11 # athena.py:
12 # # Get Conditions Container Accessor
13 # accessor = ConditionsContainerAccess(theApp)
14 #
15 # 2) Provide with folder description obtained from a COOL folder:
16 # accessor.setDescription(descr)
17 #
18 # 3) For single channel containers:
19 # myCont = accessor.getSingleCondContainer()
20 #
21 # or for multichannels, one must provide three lists: channel
22 # numbers, a CondAttrListCollection filled with the collection of
23 # AttributeLists for each multichannel, and the list of IOVs:
24 #
25 # myCont = accessor.getMultiCondContainer(chans, attrListColl, iovs)
26 #
27 # where filling the attrListColl can be done as:
28 #
29 # CondAttrListCollection = PyLCGDict.makeClass('CondAttrListCollection')
30 # hasRunEventTime = 1
31 # attrListColl = CondAttrListCollection(hasRunEventTime)
32 # i = 0
33 # for a in folderAttributeList :
34 # # Add in attribute list
35 # attrListColl.add(chans[i], attrList)
36 # i += 1
37 # i = 0
38 # for iov in folderIOVList :
39 # # Add in the IOVs for each channel
40 # attrListColl.add(chans[i], iov)
41 # i += 1
42 
43 import cppyy as PyLCGDict
44 import string
45 
47  def __init__(self, t ) :
48  if type(t) is str : t = PyLCGDict.makeClass(t)
49  # print "type is string: ",t
50  # t = PyLCGDict.makeClass(t)
51  #t = PyLCGDict.makeClass(t)
52  self.type = t
53  def cast(self, obj) :
54  if obj :
55  ip = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
56  if obj._isvc.queryInterface(self.type.interfaceID(), ip).isSuccess() :
57  return ip
58  return None
59 
61  def __init__(self, descr):
62  print(descr)
63  self.descr = descr
64  def extract(self, start, stop) :
65  print('descr, size', self.descr, len(self.descr))
66  begin = string.find(self.descr, start)
67  print('begin', begin)
68  begin += len(start)
69  end = string.find(self.descr, stop)
70  print('end', end)
71  if begin < len(self.descr) and end < len(self.descr) :
72  result = self.descr[begin:end]
73  else :
74  result = "Unable to find: " + start + ", " + stop
75  return result
76 
77 
79  def __init__(self, theApp) :
80  # PersistencySvc
81  pers = theApp.service('EventPersistencySvc')
82 
83  # PersistencySvc via its IConverter interface
84  iConverter = InterfaceRDS('IConverter')
85  self.icnv = iConverter.cast(pers)
86 
87  # PersistencySvc via its IAddressCreator interface
88  iAddrCreator = InterfaceRDS('IAddressCreator')
89  self.iaddr = iAddrCreator.cast(pers)
90 
91  # Create instance of cast object
92  self.dbCast = PyLCGDict.makeClass('DataBucketCast')
93 
95  # This method is temporary until we migrate to ROOT
96  # delete iterator types to prevent spurious typedeffing
97  import libPyROOT
98 
99  try:
100  del libPyROOT.const_iterator
101  except AttributeError:
102  pass
103 
104  try:
105  del libPyROOT.iterator
106  except AttributeError:
107  pass
108 
109 
110  def setDescription(self, descr) :
111  self.descr = descr
112  # extract type name and type
113  decoder = DescriptionDecoder(descr)
114  self.typeName = decoder.extract('<typeName>','</typeName>')
115  self.type = PyLCGDict.makeClass(self.typeName)
116  # extract the address header
117  self.header = decoder.extract('<addrHeader>','</addrHeader>')
118  self.header += 'POOLContainer_CondAttrListCollection][CLID=x'
119 
120  print("Type name, type, header ",self.typeName,self.type,self.header)
121 
123  # Get IOpaqueAddress
124  ioa = PyLCGDict.libPyROOT.MakeNullPointer('IOpaqueAddress')
125 
126  # Get DataBucketBase pointer
127  dbb = PyLCGDict.libPyROOT.MakeNullPointer('DataBucketBase')
128 
129  # Create IOA from string address
130  self.iaddr.createAddress( 0, 0, self.header, ioa )
131 
132  # Read in object as DataObject (or DatabucketBase)
133  self.icnv.createObj(ioa, dbb)
134 
135  # Cast to correct type and return it
136  result = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
137  self.dbCast.castObject(self.typeName, dbb, result)
138 
139  return result
140 
141  def getMultiCondContainer(self, channels, attrListColl, iovs) :
142 
143  # Args:
144  # channels - list of channels from COOL
145  # attrListColl - collection of AttributeLists with string address from COOL for each channel
146  # iovs - list of IOVs for each channel
147  # cont - the LArConditionsContainer object
148 
149  # Print out channels and IOV
150  print("Channels, IOV, and string addresses")
151  i = 0
152  for chan in channels :
153  iov = iovs[i]
154  print("added chan/iov: ", chan, iov.iovPrint())
155  i += 1
156 
157  # print out collection
158  #attrListColl.dump()
159 
160  # Must set dummy string address to include type name for
161  # AthenaPoolCnvSvc statistics gathering
162  strAddress = self.header
163 
164  # Get IOpaqueAddress
165  print("Create IOpaqueAddress pointer")
166  ioa = PyLCGDict.libPyROOT.MakeNullPointer('GenericAddress')
167 
168  # Get DataBucketBase pointer
169  print("Create DataBucketBase pointer")
170  dbb = PyLCGDict.libPyROOT.MakeNullPointer('DataBucketBase')
171 
172  # Create IOA from string address
173  print("Create IOpaqueAddress for address list")
174  sc = self.iaddr.createAddress( 0, 0, strAddress, ioa )
175  print("Status code: ", sc)
176 
177  # Create CondAttrListCollAddress and add in attribute list
178  CondAttrListCollAddress = PyLCGDict.makeClass('CondAttrListCollAddress')
179  collAddr = CondAttrListCollAddress(ioa)
180  collAddr.setAttrListColl(attrListColl)
181 
182 
183  # Read in object as DataObject (or DatabucketBase)
184  print("Retrieve data object for IOA")
185  sc = self.icnv.createObj(collAddr, dbb)
186  print("Status code: ", sc)
187  if sc.isFailure(): raise RuntimeError("Cannot read object")
188 
189  # Cast to correct type and return it
190  print("cast data object to correct type: ",self.typeName)
191  result = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
192  self.dbCast.castObject(self.typeName, dbb, result)
193 
194  # Reset iterator to allow a new type - bug in pyroot
195  #self.pyroot_typedef_bug_workaround()
196 
197  return result
198 
python.ConditionsContainerAccess.ConditionsContainerAccess.setDescription
def setDescription(self, descr)
Definition: ConditionsContainerAccess.py:110
python.ConditionsContainerAccess.InterfaceRDS.type
type
Definition: ConditionsContainerAccess.py:52
python.ConditionsContainerAccess.ConditionsContainerAccess.descr
descr
Definition: ConditionsContainerAccess.py:111
python.ConditionsContainerAccess.DescriptionDecoder.__init__
def __init__(self, descr)
Definition: ConditionsContainerAccess.py:61
python.ConditionsContainerAccess.ConditionsContainerAccess.iaddr
iaddr
Definition: ConditionsContainerAccess.py:89
python.ConditionsContainerAccess.ConditionsContainerAccess
Definition: ConditionsContainerAccess.py:78
python.ConditionsContainerAccess.ConditionsContainerAccess.typeName
typeName
Definition: ConditionsContainerAccess.py:114
python.ConditionsContainerAccess.ConditionsContainerAccess.dbCast
dbCast
Definition: ConditionsContainerAccess.py:92
python.ConditionsContainerAccess.DescriptionDecoder
Definition: ConditionsContainerAccess.py:60
python.ConditionsContainerAccess.ConditionsContainerAccess.getMultiCondContainer
def getMultiCondContainer(self, channels, attrListColl, iovs)
Definition: ConditionsContainerAccess.py:141
CondAttrListCollAddress
This class provides the an IOpaqueAddress/GenericAddress which can hold a pointer to an CondAttrListC...
Definition: CondAttrListCollAddress.h:27
python.ConditionsContainerAccess.DescriptionDecoder.extract
def extract(self, start, stop)
Definition: ConditionsContainerAccess.py:64
python.ConditionsContainerAccess.ConditionsContainerAccess.header
header
Definition: ConditionsContainerAccess.py:117
python.ConditionsContainerAccess.ConditionsContainerAccess.getSingleCondContainer
def getSingleCondContainer(self)
Definition: ConditionsContainerAccess.py:122
python.ConditionsContainerAccess.DescriptionDecoder.descr
descr
Definition: ConditionsContainerAccess.py:63
python.ConditionsContainerAccess.ConditionsContainerAccess.icnv
icnv
Definition: ConditionsContainerAccess.py:85
python.ConditionsContainerAccess.InterfaceRDS.__init__
def __init__(self, t)
Definition: ConditionsContainerAccess.py:47
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.ConditionsContainerAccess.ConditionsContainerAccess.type
type
Definition: ConditionsContainerAccess.py:115
python.ConditionsContainerAccess.InterfaceRDS
Definition: ConditionsContainerAccess.py:46
python.ConditionsContainerAccess.ConditionsContainerAccess.__init__
def __init__(self, theApp)
Definition: ConditionsContainerAccess.py:79
python.ConditionsContainerAccess.InterfaceRDS.cast
def cast(self, obj)
Definition: ConditionsContainerAccess.py:53
pickleTool.object
object
Definition: pickleTool.py:29
python.ConditionsContainerAccess.ConditionsContainerAccess.pyroot_typedef_bug_workaround
def pyroot_typedef_bug_workaround(self)
Definition: ConditionsContainerAccess.py:94