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 from __future__ import print_function
44 import cppyy as PyLCGDict
45 import string
46 
48  def __init__(self, t ) :
49  if type(t) is str : t = PyLCGDict.makeClass(t)
50  # print "type is string: ",t
51  # t = PyLCGDict.makeClass(t)
52  #t = PyLCGDict.makeClass(t)
53  self.type = t
54  def cast(self, obj) :
55  if obj :
56  ip = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
57  if obj._isvc.queryInterface(self.type.interfaceID(), ip).isSuccess() :
58  return ip
59  return None
60 
62  def __init__(self, descr):
63  print(descr)
64  self.descr = descr
65  def extract(self, start, stop) :
66  print('descr, size', self.descr, len(self.descr))
67  begin = string.find(self.descr, start)
68  print('begin', begin)
69  begin += len(start)
70  end = string.find(self.descr, stop)
71  print('end', end)
72  if begin < len(self.descr) and end < len(self.descr) :
73  result = self.descr[begin:end]
74  else :
75  result = "Unable to find: " + start + ", " + stop
76  return result
77 
78 
80  def __init__(self, theApp) :
81  # PersistencySvc
82  pers = theApp.service('EventPersistencySvc')
83 
84  # PersistencySvc via its IConverter interface
85  iConverter = InterfaceRDS('IConverter')
86  self.icnv = iConverter.cast(pers)
87 
88  # PersistencySvc via its IAddressCreator interface
89  iAddrCreator = InterfaceRDS('IAddressCreator')
90  self.iaddr = iAddrCreator.cast(pers)
91 
92  # Create instance of cast object
93  self.dbCast = PyLCGDict.makeClass('DataBucketCast')
94 
96  # This method is temporary until we migrate to ROOT
97  # delete iterator types to prevent spurious typedeffing
98  import libPyROOT
99 
100  try:
101  del libPyROOT.const_iterator
102  except AttributeError:
103  pass
104 
105  try:
106  del libPyROOT.iterator
107  except AttributeError:
108  pass
109 
110 
111  def setDescription(self, descr) :
112  self.descr = descr
113  # extract type name and type
114  decoder = DescriptionDecoder(descr)
115  self.typeName = decoder.extract('<typeName>','</typeName>')
116  self.type = PyLCGDict.makeClass(self.typeName)
117  # extract the address header
118  self.header = decoder.extract('<addrHeader>','</addrHeader>')
119  self.header += 'POOLContainer_CondAttrListCollection][CLID=x'
120 
121  print("Type name, type, header ",self.typeName,self.type,self.header)
122 
124  # Get IOpaqueAddress
125  ioa = PyLCGDict.libPyROOT.MakeNullPointer('IOpaqueAddress')
126 
127  # Get DataBucketBase pointer
128  dbb = PyLCGDict.libPyROOT.MakeNullPointer('DataBucketBase')
129 
130  # Create IOA from string address
131  self.iaddr.createAddress( 0, 0, self.header, ioa )
132 
133  # Read in object as DataObject (or DatabucketBase)
134  self.icnv.createObj(ioa, dbb)
135 
136  # Cast to correct type and return it
137  result = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
138  self.dbCast.castObject(self.typeName, dbb, result)
139 
140  return result
141 
142  def getMultiCondContainer(self, channels, attrListColl, iovs) :
143 
144  # Args:
145  # channels - list of channels from COOL
146  # attrListColl - collection of AttributeLists with string address from COOL for each channel
147  # iovs - list of IOVs for each channel
148  # cont - the LArConditionsContainer object
149 
150  # Print out channels and IOV
151  print("Channels, IOV, and string addresses")
152  i = 0
153  for chan in channels :
154  iov = iovs[i]
155  print("added chan/iov: ", chan, iov.iovPrint())
156  i += 1
157 
158  # print out collection
159  #attrListColl.dump()
160 
161  # Must set dummy string address to include type name for
162  # AthenaPoolCnvSvc statistics gathering
163  strAddress = self.header
164 
165  # Get IOpaqueAddress
166  print("Create IOpaqueAddress pointer")
167  ioa = PyLCGDict.libPyROOT.MakeNullPointer('GenericAddress')
168 
169  # Get DataBucketBase pointer
170  print("Create DataBucketBase pointer")
171  dbb = PyLCGDict.libPyROOT.MakeNullPointer('DataBucketBase')
172 
173  # Create IOA from string address
174  print("Create IOpaqueAddress for address list")
175  sc = self.iaddr.createAddress( 0, 0, strAddress, ioa )
176  print("Status code: ", sc)
177 
178  # Create CondAttrListCollAddress and add in attribute list
179  CondAttrListCollAddress = PyLCGDict.makeClass('CondAttrListCollAddress')
180  collAddr = CondAttrListCollAddress(ioa)
181  collAddr.setAttrListColl(attrListColl)
182 
183 
184  # Read in object as DataObject (or DatabucketBase)
185  print("Retrieve data object for IOA")
186  sc = self.icnv.createObj(collAddr, dbb)
187  print("Status code: ", sc)
188  if sc.isFailure(): raise RuntimeError("Cannot read object")
189 
190  # Cast to correct type and return it
191  print("cast data object to correct type: ",self.typeName)
192  result = PyLCGDict.libPyROOT.MakeNullPointer(self.type)
193  self.dbCast.castObject(self.typeName, dbb, result)
194 
195  # Reset iterator to allow a new type - bug in pyroot
196  #self.pyroot_typedef_bug_workaround()
197 
198  return result
199 
python.ConditionsContainerAccess.ConditionsContainerAccess.setDescription
def setDescription(self, descr)
Definition: ConditionsContainerAccess.py:111
python.ConditionsContainerAccess.InterfaceRDS.type
type
Definition: ConditionsContainerAccess.py:53
python.ConditionsContainerAccess.ConditionsContainerAccess.descr
descr
Definition: ConditionsContainerAccess.py:112
python.ConditionsContainerAccess.DescriptionDecoder.__init__
def __init__(self, descr)
Definition: ConditionsContainerAccess.py:62
python.ConditionsContainerAccess.ConditionsContainerAccess.iaddr
iaddr
Definition: ConditionsContainerAccess.py:90
python.ConditionsContainerAccess.ConditionsContainerAccess
Definition: ConditionsContainerAccess.py:79
python.ConditionsContainerAccess.ConditionsContainerAccess.typeName
typeName
Definition: ConditionsContainerAccess.py:115
python.ConditionsContainerAccess.ConditionsContainerAccess.dbCast
dbCast
Definition: ConditionsContainerAccess.py:93
python.ConditionsContainerAccess.DescriptionDecoder
Definition: ConditionsContainerAccess.py:61
python.ConditionsContainerAccess.ConditionsContainerAccess.getMultiCondContainer
def getMultiCondContainer(self, channels, attrListColl, iovs)
Definition: ConditionsContainerAccess.py:142
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:65
python.ConditionsContainerAccess.ConditionsContainerAccess.header
header
Definition: ConditionsContainerAccess.py:118
python.ConditionsContainerAccess.ConditionsContainerAccess.getSingleCondContainer
def getSingleCondContainer(self)
Definition: ConditionsContainerAccess.py:123
python.ConditionsContainerAccess.DescriptionDecoder.descr
descr
Definition: ConditionsContainerAccess.py:64
python.ConditionsContainerAccess.ConditionsContainerAccess.icnv
icnv
Definition: ConditionsContainerAccess.py:86
python.ConditionsContainerAccess.InterfaceRDS.__init__
def __init__(self, t)
Definition: ConditionsContainerAccess.py:48
python.ConditionsContainerAccess.ConditionsContainerAccess.type
type
Definition: ConditionsContainerAccess.py:116
python.ConditionsContainerAccess.InterfaceRDS
Definition: ConditionsContainerAccess.py:47
python.ConditionsContainerAccess.ConditionsContainerAccess.__init__
def __init__(self, theApp)
Definition: ConditionsContainerAccess.py:80
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.ConditionsContainerAccess.InterfaceRDS.cast
def cast(self, obj)
Definition: ConditionsContainerAccess.py:54
pickleTool.object
object
Definition: pickleTool.py:30
python.ConditionsContainerAccess.ConditionsContainerAccess.pyroot_typedef_bug_workaround
def pyroot_typedef_bug_workaround(self)
Definition: ConditionsContainerAccess.py:95