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