ATLAS Offline Software
Loading...
Searching...
No Matches
SampleHandler_QueryAMI.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3
4import ROOT
5import pyAMI.client
6from pyAMI.atlas.api import get_dataset_info
7
9 # set up an AMI client
10 # This is the basic minimum - and it will look for an encrypted file with your user credentals
11 # If it does not find that it will try for a VOMS proxy
12 # Make the encrypted file by running the amo command
13 # ami auth
14 # first.
15 # In the pyAMI doc you will find an example of how to get your program to request a
16 # the user to make a file.
17 # https://atlas-ami.cern.ch/AMI/pyAMI/examples/api.html
18
19 amiClient=pyAMI.client.Client('atlas')
20 # Extract from your mail
21
29
30 data = ROOT.SH.MetaDataQuery()
31 data.messages = 'done by ami query'
32 # I am assuming that "samples" is a list of dataset names, and that
33 # the user already checked that they exist and are valid
34 for sample in samples :
35 sample_noscope=sample.split(':')[-1]
36
37 mydata = ROOT.SH.MetaDataSample(sample)
38 # The first question you ask is it data or mc.
39 # Actually you should be able to tell this without ambiguity from the name
40 # without going to the trouble of a request to AMI.
41 # description: 1 for data, 0 for MC, or -1 if this is not known.
42
43 mydata.source = 'https://atlas-ami.cern.ch/AMI/pyAMI/'
44 mydata.unknown = 0
45
46 if (sample.startswith("mc")) :
47 mydata.isData=0
48 pass
49 elif (sample.startswith("data")) :
50 mydata.isData=1
51 pass
52 else :
53 mydata.isData=-1
54 pass
55
56 # You are calling ths AMI functions with tid suffixes.
57 # AMI does not specifically catalogue TID datasets so
58 # I am stripping off the suffix.
59 # Normally uses should not be concerned with these datasets
60 # but only with the containers.
61 # However if you are really only interested in the output of a particular
62 # prodsys task then we can do it - but it would be more complex
63 # as we need to redo the event and cross section calculations
64 # just for those tasks.
65 if (sample.find("_tid")):
66 print ("Stripping tid suffix from " + sample)
67 sample = sample.split("_tid")[0]
68 pass
69
70
71 # All datasets should have the number of events.
72 # have to convert this to a long int I suppose?
73 amiinfo=get_dataset_info(amiClient, sample_noscope)[0]
74 mydata.nevents = long(amiinfo['totalEvents'])
75
76 # AMI does not yet have a function for getting luminosity.
77 # It IS on the todo list, as luminosity info per run is available
78 # in COMA, and AMI has access to the information in principle
79 # So this is in part a place holder
80 # I do not know anything about k-factor. We have no such parameter sent to us.
81 # This should be taken up with the MC people I suppose.
82
83 if (mydata.isData==1):
84 # get luminosity for the run
85 mydata.crossSection=-1
86 mydata.filterEfficiency=-1
87 pass
88 else:
89 mydata.luminosity = -1
90 # MC - can get cross-section and filter efficiency
91 xsec=float(amiinfo['approx_crossSection'])
92 effic=float(amiinfo['approx_GenFiltEff'])
93 # + conversion string to float.
94 mydata.crossSection= xsec
95 mydata.filterEfficiency= effic
96 if mydata.crossSection > 0 and mydata.filterEfficiency > 0:
97 mydata.luminosity= float (float(mydata.nevents)/(mydata.crossSection*mydata.filterEfficiency))
98 pass
99 pass
100
101 data.addSample (mydata)
102 # print "cross section = "+str(mydata.crossSection)+", filter efficiency = "+str(mydata.filterEfficiency)+", nEvents= "+str(mydata.nevents)
103 pass
104 return data
105
106
107
108
109