ATLAS Offline Software
create_period_container.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
12 
13 from __future__ import print_function
14 
15 import sys
16 import pyAMI.client
17 import pyAMI.atlas.api as AtlasAPI
18 from subprocess import call
19 
20 client = pyAMI.client.Client(
21  'atlas'
22  #'atlas-replica'
23 )
24 AtlasAPI.init()
25 
26 
27 def getRuns(grl):
28  listGRL = []
29  for i in grl.split(','):
30  import xml.etree.ElementTree
31  listGRL += [atype.text.split(',') for atype in xml.etree.ElementTree.parse(grl).getroot().find('NamedLumiRange').findall('Metadata') if atype.get('Name') == 'RunList']
32  return listGRL
33 
34 class config1:
35  def __init__(self, project, derivation, period, acceptTags, sTag, autoCreate=False, grl=None):
36  self.project = project
37  self.period = period
38  self.sTag = sTag
39  self.derivation = derivation
40  self.acceptTags = acceptTags
41  self.autoCreate = autoCreate
42  self.grl = grl
43  self.outScript=None
44 
45 def makeContainer(c1):
46 
47  x0 = AtlasAPI.list_datasets(client, patterns = [c1.project+'.%.physics_Main.merge.AOD%'], fields = ['run_number', 'ldn', 'events', 'total_size'], order=None, limit=None, show_archived=False, grl=c1.grl, data_period=c1.period)
48  runs = set([a['run_number'] for a in x0])
49 
50  if len(runs)==0:
51  print ('no run in period'+c1.period+' is listed in GRL:', c1.grl)
52  return
53 
54 
55  x = AtlasAPI.list_datasets(client, patterns = [c1.project+'.%.physics_Main.merg%'+c1.derivation+'%'], fields = ['run_number', 'ldn', 'events', 'total_size'], order=None, limit=None, show_archived=False, grl=c1.grl, data_period=c1.period)
56 
57 
58  dic1={}
59  for a in x:
60  print (a['run_number'], a['ldn'])
61  try:
62  dic1[a['ldn'].split('_')[-1]].append((a['run_number'],a['ldn']))
63  except KeyError:
64  dic1[a['ldn'].split('_')[-1]] = [(a['run_number'],a['ldn'])]
65 
66 
67  allTags = sorted(dic1.keys(), key=lambda k: len(dic1[k]),reverse=True)
68  for tag in allTags:
69  print (tag,':', end='')
70  for xx in dic1[tag]:
71  print (xx[0], end='')
72  print()
73 
74 
75  t_acceptTags = c1.acceptTags if c1.acceptTags else allTags
76 
77 
78  ds = []
79  for t in t_acceptTags:
80  for a in dic1.get(t,[]):
81  found = False
82  for d in ds:
83  if d[0] == a[0]:
84  found = True
85  break
86  if not found:
87  ds.append(a)
88 
89 
90  if len(ds)==0:
91  print ('No dataset in period',c1.period+', exiting...')
92  return
93 
94 
95  for d in ds:
96  print (d[0],d[1])
97  runs.remove(d[0])
98  print (runs)
99 
100 
101  if len(runs) !=0:
102  print ('!'*10)
103  print ('MISSING ', ' '.join(runs))
104 
105 
106  dlist=','.join([d[1] for d in ds])
107  superTag = 'period'+c1.period+','+c1.sTag+ds[0][1][-5:]
108  comments = superTag+','+c1.derivation
109 
110  cmd='ami cmd COMAPopulateSuperProductionDataset -rucioRegistration="yes" -creationComment="'+comments+'" -selectionType="run_config" -superTag="'+superTag+'" -containedDatasets="'+dlist+'" -separator="," '
111  print ('command:',cmd)
112 
113 
114  if c1.outScript:
115  with open(c1.outScript,'a') as f1:
116  f1.write(cmd+'\n')
117  return
118 
119 
120  if not c1.autoCreate:
121  while True:
122  x = raw_input("create contianer: y[es]/N[o]/e[xit]")
123  if x == 'e' or x=='N': return
124  elif x=='y': break
125 
126  call(cmd, shell=True)
127 
128 
130  grl15 = '/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data15_13TeV/20160720/physics_25ns_20.7.xml'
131  grl16 = '/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data16_13TeV/20160916/physics_25ns_20.7_ignoreToroidStatus.xml'
132  c1 = config1('data16_13TeV', 'MUON0', 'A', sTag='grp16_v01_', acceptTags=['p2769','p2689','p2667'], autoCreate=False, grl=grl16)
133  c1.outScript = 'createIt_15.sh'
134 
135 # periods = AtlasAPI.list_dataperiods(client, 2, 16)
136 
137  periods = AtlasAPI.list_dataperiods(client, 2, 15)
138  c1.project = 'data15_13TeV'
139  c1.sTag='grp15_v01_'
140  c1.acceptTags=['p2667']
141  c1.grl = grl15
142 
143  pds =[p['period'] for p in periods if p['status']=='frozen']
144 # print (pds)
145 # sys.exit(0)
146 
147  for p in pds:
148  for d in ['MUON0','MUON1','MUON2','MUON3']:
149 # for d in ['MUON0']:
150  c1.period = p
151  c1.derivation = d
152  makeContainer(c1)
153 
154 def doData15():
155  grl15 = '/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data15_13TeV/20160720/physics_25ns_20.7.xml'
156  c1 = config1('data15_13TeV', 'MUON0', 'A', sTag='grp15_v01_', acceptTags=None, autoCreate=False, grl=None)
157  c1.outScript = 'createIt_15v2.sh'
158 
159  periods = AtlasAPI.list_dataperiods(client, 2, 15)
160  c1.project = 'data15_13TeV'
161  c1.sTag='grp15_v02_'
162  c1.acceptTags=['p2889']
163  c1.grl = grl15
164 
165  pds =[p['period'] for p in periods if p['status']=='frozen']
166 # print (pds)
167 # sys.exit(0)
168 
169  for p in pds:
170  for d in ['MUON0','MUON1','MUON2','MUON3']:
171  c1.period = p
172  c1.derivation = d
173  makeContainer(c1)
174 
175 
177  grl16 = '/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data16_13TeV/20161101/physics_25ns_20.7_ignoreToroidStatus.xml'
178  c1 = config1('data16_13TeV', 'MUON0', 'A', sTag='grp16_v01_', acceptTags=['p2769','p2689','p2667'], autoCreate=False, grl=grl16)
179  c1.outScript = 'createIt_16Later2.sh'
180 
181  periods = AtlasAPI.list_dataperiods(client, 2, 16)
182 
183  c1.project = 'data16_13TeV'
184  c1.sTag='grp16_v01_'
185  c1.acceptTags=None
186  c1.grl = grl16
187 
188 # pds =[p['period'] for p in periods if p['status']=='frozen']
189 # print (pds)
190 # sys.exit(0)
191  pds = ['J', 'K', 'L']
192 
193  for p in pds:
194  for d in ['MUON0','MUON1','MUON2','MUON3']:
195  c1.period = p
196  c1.derivation = d
197  makeContainer(c1)
198 
199 if __name__ == '__main__':
201 # doData15()
create_period_container.config1.acceptTags
acceptTags
Definition: create_period_container.py:40
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
create_period_container.getRuns
def getRuns(grl)
Definition: create_period_container.py:27
create_period_container.config1.autoCreate
autoCreate
Definition: create_period_container.py:41
create_period_container.config1.derivation
derivation
Definition: create_period_container.py:39
create_period_container.doData15
def doData15()
Definition: create_period_container.py:154
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
create_period_container.doFirstTry
def doFirstTry()
Definition: create_period_container.py:129
create_period_container.config1.project
project
Definition: create_period_container.py:36
python.trfUtils.call
def call(args, bufsize=0, executable=None, stdin=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, message="", logger=msg, loglevel=None, timeout=None, retry=2, timefactor=1.5, sleeptime=10)
Definition: trfUtils.py:155
create_period_container.config1.sTag
sTag
Definition: create_period_container.py:38
create_period_container.do2016LaterPeriods
def do2016LaterPeriods()
Definition: create_period_container.py:176
create_period_container.config1.__init__
def __init__(self, project, derivation, period, acceptTags, sTag, autoCreate=False, grl=None)
Definition: create_period_container.py:35
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
create_period_container.config1.grl
grl
Definition: create_period_container.py:42
create_period_container.config1.period
period
Definition: create_period_container.py:37
Trk::open
@ open
Definition: BinningType.h:40
create_period_container.config1
Definition: create_period_container.py:34
create_period_container.config1.outScript
outScript
Definition: create_period_container.py:43
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
create_period_container.makeContainer
def makeContainer(c1)
Definition: create_period_container.py:45