ATLAS Offline Software
collListGuids.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 #
5 # @author Marcin Nowak
6 # @date 08.2012
7 # @brief example of how to extract data from Collections in Python
8 #
9 # this example/utility prints EventNumber and all file GUIDs for this Event
10 # supports queries (without trigger bits decoding though)
11 #
12 
13 import ROOT
14 ROOT.gROOT.SetBatch(True)
15 import re,sys
16 
17 def toiter (beg, end):
18  while beg != end:
19  #yield beg.__deref__()
20  yield beg
21  beg.__preinc__()
22  return
23 
24 def toiter1 (c):
25  return toiter (c.begin(), c.end())
26 
27 
28 query_string = ''
29 for i in range(1, len(sys.argv) ):
30  if sys.argv[i] == '-src':
31  collection_name = sys.argv[i+1]
32  i += 1
33  collection_name = re.sub('\.root$', '', collection_name)
34  if sys.argv[i] == '-query':
35  query_string = sys.argv[i+1]
36  i += 1
37  if sys.argv[i] == '-h':
38  print "Currently implemented options: -src -query"
39 
40 
41 colsvc = ROOT.pool.CollectionService()
42 read_only_flag = True
43 col=colsvc.open(collection_name, 'RootCollection', '', read_only_flag)
44 
45 des = col.description()
46 attributes = map( lambda n: des.attributeColumn(n, 0).name(), range(0, des.numberOfAttributeColumns()) )
47 if 'RunNumber' not in attributes or 'EventNumber' not in attributes:
48  print "RunNumber/EventNumber attribute not found in the collection"
49  exit(1)
50 
51 #for c in range(0, des.numberOfAttributeColumns()):
52 # print "Attribute: ", des.attributeColumn(c, 0).name(), " type:", des.attributeColumn(c, 0).type()
53 #for c in range(0, des.numberOfTokenColumns()):
54 # print "Reference: ", des.tokenColumn(c, 0).name()
55 
56 query = col.newQuery()
57 query.selectAll();
58 query.setCondition( query_string )
59 #query.addToOutputList( des.attributeColumn(0, 0).name() )
60 #query.addToOutputList( des.attributeColumn(1, 0).name() )
61 
62 cursor = query.execute()
63 
64 if( cursor.next() ):
65  row = cursor.currentRow()
66 
67  tlist = row.tokenList()
68  alist = row.attributeList()
69  print "Attributes # = ", alist.size(), " References # = ", tlist.size()
70 
71  for i in range(0,alist.size()):
72  attr_name = alist[i].specification().name()
73 
74  queryopt = ['RunNumber', 'EventNumber']
75 
76  attrdata_func_name = {}
77  line = ''
78  for atr in queryopt:
79  attrdata_func_name[atr] = 'data<' + alist[atr].specification().typeName() + '>'
80  line += "%10.10s " % atr
81  for t in toiter1(tlist):
82  line += "%38.38s " % t.tokenName()
83  print line
84 
85  has_row = True
86  while has_row:
87  alist = cursor.currentRow().attributeList()
88  tlist = cursor.currentRow().tokenList()
89  line = ''
90  for atr in queryopt:
91  line += "%10.10s " % str(getattr(alist[atr], attrdata_func_name[atr])())
92  for i in range(0, tlist.size()):
93  line += "%38.38s " % tlist[i].dbID()
94  print line
95  has_row = cursor.next()
96 
97 col.close()
collListGuids.toiter1
def toiter1(c)
Definition: collListGuids.py:24
collListGuids.toiter
def toiter(beg, end)
Definition: collListGuids.py:17
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
calibdata.exit
exit
Definition: calibdata.py:236
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
str
Definition: BTagTrackIpAccessor.cxx:11