ATLAS Offline Software
Loading...
Searching...
No Matches
isDSinFAX.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
5import subprocess, threading, os, sys
6import urllib2
7import json
8
9import argparse
10
11parser = argparse.ArgumentParser(description='Checks if dataset is accessible through FAX.')
12parser.add_argument('dataset', type=str, help='Dataset name')
13parser.add_argument('-af','--accessfile', action='store_const', const='1', help='try to open the first root file of the dataset using root. ')
14parser.add_argument('-aa','--accessall', action='store_const', const='1', help='try to open all the root files of the dataset using root. ')
15
16args = vars(parser.parse_args())
17
18try:
19 import dq2.clientapi.cli.cliutil
20 from dq2.common.cli.DQDashboardTool import DQDashboardTool
21 from dq2.clientapi.cli.cliutil import getDQ2
22 from dq2.filecatalog.lfc.lfcconventions import to_native_lfn
23except ImportError:
24 print ("Environment not set [error importing DQ2 dependencies]!")
25 sys.exit(1)
26
27
29
30 def __init__(self, cmd):
31 self.cmd = cmd
32 self.process = None
33
34 def run(self, timeout):
35 def target():
36# print ('command started: ', self.cmd)
37 self.process = subprocess.Popen(self.cmd, shell=True)
38 self.process.communicate()
39
40 thread = threading.Thread(target=target)
41 thread.start()
42
43 thread.join(timeout)
44 if thread.is_alive():
45 print ('Terminating process')
46 self.process.terminate()
47 thread.join()
48 return self.process.returncode
49
50
51#print ('Geting data from AGIS ...')
52
53class site:
54 name=''
55 host=''
56 port=1094
57
58 def __init__(self, na, ho):
59 self.name=na
60 ho=ho.replace("root://","")
61 self.host=ho.split(":")[0]
62 if ho.count(":"):
63 self.port=ho.split(":")[1]
64
65 def prnt(self, what):
66 if (what>=0 and self.redirector!=what): return
67 print ( 'name:', self.name, '\thost:', self.host, '\tport:', self.port )
68
69sites=[];
70
71try:
72 req = urllib2.Request("http://atlas-agis-api-0.cern.ch/request/service/query/get_se_services/?json&state=ACTIVE&flavour=XROOTD", None)
73 opener = urllib2.build_opener()
74 f = opener.open(req)
75 res=json.load(f)
76 for s in res:
77# print (s["name"], s["rc_site"], s["endpoint"])
78 ns = site( s["rc_site"], s["endpoint"] )
79 sites.append(ns)
80# print (res)
81# print (' got FAX SEs from AGIS.')
82
83except:
84 print ("Unexpected error:", sys.exc_info()[0] )
85
86#for s in sites: s.prnt(-1)
87
88allddms=set()
89
90try:
91 req = urllib2.Request("http://atlas-agis-api-0.cern.ch/request/ddmendpoint/query/list/?json&state=ACTIVE", None)
92 opener = urllib2.build_opener()
93 f = opener.open(req)
94 res=json.load(f)
95 for s in res:
96 for c in sites:
97 if s["rc_site"]==c.name:
98 # print (s["rc_site"], s["name"])
99 allddms.add(s["name"])
100 break
101# print (' got related ddmendpoints from agis.')
102
103except:
104 print ("Unexpected error:", sys.exc_info()[0] )
105
106
107DS=args['dataset']
108
109com=Command('dq2-ls -r '+ DS + ' > fax.tmp' )
110com.run(300)
111dsets={}
112cds=''
113f = open('fax.tmp', 'r')
114for line in f:
115 if line.startswith('Multiple'): break
116 line=line.strip()
117 if line.count(':')==0:continue
118 line=line.split(":")
119 # print (line)
120
121 if line[0]=='INCOMPLETE':
122 if len(line[1])==0: continue
123 rep=line[1].split(',')
124 for r in rep:
125 if r in allddms:
126 dsets[cds][0]+=1
127 continue
128
129 if line[0]=='COMPLETE':
130 if len(line[1])==0: continue
131 rep=line[1].split(',')
132 for r in rep:
133 if r in allddms:
134 dsets[cds][1]+=1
135 continue
136
137 cds=line[0]
138 dsets[cds]=[0,0]
139
140for d in dsets.keys():
141 print (d,'\tcomplete replicas:',dsets[d][1],'\tincomplete:',dsets[d][0])
__init__(self, cmd)
Definition isDSinFAX.py:30
__init__(self, na, ho)
Definition isDSinFAX.py:58
prnt(self, what)
Definition isDSinFAX.py:65
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
Definition run.py:1