-
Notifications
You must be signed in to change notification settings - Fork 19
/
datasetinfo.py
executable file
·58 lines (55 loc) · 2.42 KB
/
datasetinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import sys
import os
from dbs.apis.dbsClient import DbsApi
from optparse import OptionParser
from dataclasses import dataclass, field
import os
@dataclass
class DatasetInfo:
datasetname:list
verbose:bool
instance:str = "phys03"
dataset_fileinfo:dict[str] = field( default_factory=dict)
def getFileListFromDBS3(self):
dbs = DbsApi(f'https://cmsweb.cern.ch/dbs/prod/{self.instance}/DBSReader')
for dataset in self.datasetname:
dataset=dataset.strip()
if(self.verbose):
print(dataset)
self.dataset_fileinfo[dataset] = dbs.listFiles(dataset = dataset, detail=1)
return(self.dataset_fileinfo)
def getFileList(self):
return(self.dataset_fileinfo)
def printFiles(self,dataset=None):
if dataset is None:
print(self.dataset_fileinfo)
else :
if (dataset in self.dataset_fileinfo):
print(self.dataset_fileinfo[dataset])
else:
print(f"Error! {dataset} is not existed.")
def getFileListWithFormat(self,want_dataset=None):
fileinfo_format =[]
for dataset in self.dataset_fileinfo.keys():
if ( want_dataset is not None and dataset != want_dataset): continue
for fileinfo in self.dataset_fileinfo[dataset]:
fileinfo_format.append([fileinfo["logical_file_name"],fileinfo["file_size"],fileinfo["adler32"]])
return(fileinfo_format)
if __name__ == "__main__":
usage=f"Usage: {sys.argv[0]} [options] [dataset1] [dataset2] ..."
parser = OptionParser(usage)
parser.add_option("-f", "--datasetfile", dest="dataset", help="Dataset list file. If this option is set, arguments is ignored.")
parser.add_option("-i", "--instance", dest="instance",default="phys03", help="Instance Name [global or phys03(default)]")
parser.add_option("-v", "--verbose", dest="verbose",action="store_true", help="Verbose mode")
(options, args) = parser.parse_args()
if ( options.dataset is not None):
datasetname = open(options.dataset).readlines()
else:
datasetname = args
ds = DatasetInfo(datasetname=datasetname, verbose=options.verbose, instance=options.instance)
ds.getFileListFromDBS3()
filesinfo = ds.getFileListWithFormat()
for fileinfo in filesinfo:
lfn, size, checksum = fileinfo
print(f"LFN : {lfn} / Size: {size} / Adler32: {checksum}\n")