O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
DQLibGetter Class Reference
Inheritance diagram for DQLibGetter:

Public Member Functions

def __init__ (self)
 
def getAnalysisSelections (self)
 

Detailed Description

Class for Downloading DQ Libraries Github and It gets analysis selections 
like analysis cuts, MC signals and event mixing variables

Args:
    object (object): self

Definition at line 25 of file dqLibGetter.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)

Definition at line 35 of file dqLibGetter.py.

35 def __init__(self):
36 super(DQLibGetter, self).__init__()
37

Member Function Documentation

◆ getAnalysisSelections()

def getAnalysisSelections (   self)
This function allows to get all analysis selections from DQ libraries

Returns:
    allAnalysisCuts, allMCSignals, allSels, allMixing: All analysis selections with order

Definition at line 38 of file dqLibGetter.py.

38 def getAnalysisSelections(self):
39 """This function allows to get all analysis selections from DQ libraries
40
41 Returns:
42 allAnalysisCuts, allMCSignals, allSels, allMixing: All analysis selections with order
43 """
44
45 allAnalysisCuts = [] # all analysis cuts
46 allPairCuts = [] # only pair cuts
47 nAddedallAnalysisCutsList = [] # e.g. muonQualityCuts:2
48 nAddedPairCutsList = [] # e.g paircutMass:3
49 selsWithOneColon = [] # track/muon cut:paircut:n
50 allSels = [] # track/muon cut::n
51 oneColon = ":" # Namespace reference
52 doubleColon = "::" # Namespace reference
53 allMCSignals = [] # Get MC Signals
54 allMixing = [] # Get Event Mixing vars
55
56 headers = {
57 "User-Agent":
58 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36"
59 }
60
61 URL_CUTS_LIBRARY = "https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/CutsLibrary.h?raw=true"
62 URL_MCSIGNALS_LIBRARY = "https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/MCSignalLibrary.h?raw=true"
63 URL_MIXING_LIBRARY = "https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/MixingLibrary.h?raw=true"
64
65 # Github Links for CutsLibrary and MCSignalsLibrary from PWG-DQ --> download from github
66 # This condition solves performance issues
67 if not (os.path.isfile("tempCutsLibrary.h") or os.path.isfile("tempMCSignalsLibrary.h") or os.path.isfile("tempMixingLibrary.h")):
68 print("[INFO] Some Libs are Missing. They will download.")
69
70 # Dummy SSL Adder
71 context = ssl._create_unverified_context() # prevent ssl problems
72 # request = urllib.request.urlopen(URL_CUTS_LIBRARY, context=context)
73
74 # HTTP Request
75 requestCutsLibrary = Request(URL_CUTS_LIBRARY, headers = headers)
76 requestMCSignalsLibrary = Request(URL_MCSIGNALS_LIBRARY, headers = headers)
77 requestMixingLibrary = Request(URL_MIXING_LIBRARY, headers = headers)
78
79 # Get Files With Http Requests
80 htmlCutsLibrary = urlopen(requestCutsLibrary, context = context).read()
81 htmlMCSignalsLibrary = urlopen(requestMCSignalsLibrary, context = context).read()
82 htmlMixingLibrary = urlopen(requestMixingLibrary, context = context).read()
83
84 # Save Disk to temp DQ libs
85 with open("tempCutsLibrary.h", "wb") as f:
86 f.write(htmlCutsLibrary)
87 with open("tempMCSignalsLibrary.h", "wb") as f:
88 f.write(htmlMCSignalsLibrary)
89 with open("tempMixingLibrary.h", "wb") as f:
90 f.write(htmlMixingLibrary)
91
92 # Read Cuts, Signals, Mixing vars from downloaded files
93 with open("tempMCSignalsLibrary.h") as f:
94 for line in f:
95 stringIfSearch = [x for x in f if "if" in x]
96 for i in stringIfSearch:
97 getSignals = re.findall('"([^"]*)"', i)
98 allMCSignals = allMCSignals + getSignals
99
100 with open("tempMixingLibrary.h") as f:
101 for line in f:
102 stringIfSearch = [x for x in f if "if" in x]
103 for i in stringIfSearch:
104 getMixing = re.findall('"([^"]*)"', i)
105 allMixing = allMixing + getMixing
106
107 with open("tempCutsLibrary.h") as f:
108 for line in f:
109 stringIfSearch = [x for x in f if "if" in x] # get lines only includes if string
110 for i in stringIfSearch:
111 getCuts = re.findall('"([^"]*)"', i) # get in double quotes string value with regex exp.
112 getPairCuts = [y for y in getCuts if "pair" in y] # get pair cuts
113 if getPairCuts: # if pair cut list is not empty
114 allPairCuts = (allPairCuts + getPairCuts) # Get Only pair cuts from CutsLibrary.h
115 namespacedPairCuts = [x + oneColon for x in allPairCuts] # paircut:
116 allAnalysisCuts = (allAnalysisCuts + getCuts) # Get all Cuts from CutsLibrary.h
117 nameSpacedallAnalysisCuts = [x + oneColon for x in allAnalysisCuts] # cut:
118 nameSpacedallAnalysisCutsTwoDots = [x + doubleColon for x in allAnalysisCuts] # cut::
119
120 # in Filter PP Task, sels options for barrel and muon uses namespaces e.g. "<track-cut>:[<pair-cut>]:<n> and <track-cut>::<n> For Manage this issue:
121 for k in range(1, 10):
122 nAddedallAnalysisCuts = [x + str(k) for x in nameSpacedallAnalysisCutsTwoDots]
123 nAddedallAnalysisCutsList = nAddedallAnalysisCutsList + nAddedallAnalysisCuts
124 nAddedPairCuts = [x + str(k) for x in namespacedPairCuts]
125 nAddedPairCutsList = nAddedPairCutsList + nAddedPairCuts
126
127 # Style 1 <track-cut>:[<pair-cut>]:<n>:
128 for i in nAddedPairCutsList:
129 Style1 = [x + i for x in nameSpacedallAnalysisCuts]
130 selsWithOneColon = selsWithOneColon + Style1
131
132 # Style 2 <track-cut>:<n> --> nAddedallAnalysisCutsList
133
134 # Merge All possible styles for Sels (cfgBarrelSels and cfgMuonSels) in FilterPP Task
135 allSels = selsWithOneColon + nAddedallAnalysisCutsList
136
137 # TODO : should be flaged
138 return allAnalysisCuts, allMCSignals, allSels, allMixing

The documentation for this class was generated from the following file: