-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInsertFiles.py
202 lines (157 loc) · 6.01 KB
/
InsertFiles.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
###############################################################################
"""
Example script to inject LHE files in DBS3
For real usage various "string" defined here needs to
be changed and input file list has to be given with size,
number of events, and checksum
Run it like crab2:
source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh
cmsrel CMSSW_5_3_1 (or whatever recent release)
cd CMSSW_5_3_1
cmsenv
source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh
voms-proxy-init -voms cms
./InsertFiles.py
Useful information (feedback from Stefano and Yuyi):
- acquisition_era: it must be LHE (or CRAB) to bypass the name validation.
- create_by: DBS3 will automatically fill this field
- creation_date: DBS3 will automatically fill this field
"""
###############################################################################
import pprint
from dbs.apis.dbsClient import DbsApi
import uuid
import sys
def createEmptyBlock(ds_info, origin_site_name):
acquisition_era_config = {'acquisition_era_name':'LHE', 'start_date':1954}
processing_era_config = {
'processing_version': 2,
'description': 'test_LHE_injection'}
primds_config = {
#'primary_ds_type': 'mc',
'primary_ds_type': 'test',
'primary_ds_name': ds_info['primary_ds']}
dataset = "/%s/%s/%s" % (ds_info['primary_ds'],ds_info['processed_ds'],ds_info['tier'])
dataset_config = {
'physics_group_name': ds_info['group'],
'dataset_access_type': 'VALID',
'data_tier_name': ds_info['tier'],
'processed_ds_name':ds_info['processed_ds'],
'dataset': dataset }
block_name = "%s#%s" % (dataset, str(uuid.uuid4()))
block_config = {'block_name': block_name, \
'origin_site_name': origin_site_name, \
'open_for_writing': 0}
dataset_conf_list = [{'app_name': ds_info['application'],
'global_tag': 'dummytag',
'output_module_label': 'out',
'pset_hash': 'dummyhash',
'release_version': ds_info['app_version']}]
blockDict = { \
'files': [],
'processing_era': processing_era_config,
'primds': primds_config,
'dataset': dataset_config,
'dataset_conf_list' : dataset_conf_list,
'acquisition_era': acquisition_era_config,
'block': block_config,
'file_parent_list':[],
'file_conf_list':[],
}
return blockDict
def addFilesToBlock(blockDict, files):
blockDict['files'] = files
blockDict['block']['file_count'] = len(files)
blockDict['block']['block_size'] = sum([int(file['file_size']) for file in files])
return blockDict
#===============================================================
# MAIN STARTS HERE
#===============================================================
#pick a DBS3 instance
#instance = 'dev'
instance = 'int'
#instance = 'prod'
if instance=='dev':
#host = 'dbs3-dev01.cern.ch'
host = 'cmsweb-dev.cern.ch'
if instance=='int':
host = 'cmsweb-testbed.cern.ch'
if instance=='prod':
host = 'cmsweb.cern.ch'
globReadUrl = 'https://%s/dbs/%s/global/DBSReader' % (host, instance)
globWriteUrl = 'https://%s/dbs/%s/global/DBSWriter' % (host, instance)
phy3ReadUrl = 'https://%s/dbs/%s/phys03/DBSReader' % (host, instance)
phy3WriteUrl = 'https://%s/dbs/%s/phys03/DBSWriter' % (host, instance)
readApi = DbsApi(url=globReadUrl)
writeApi = DbsApi(url=globWriteUrl)
#readApi = DbsApi(url=phy3ReadUrl)
#writeApi = DbsApi(url=phy3WriteUrl)
# INFORMATION TO BE PUT IN DBS3
# almost free text here, but beware WMCore/Lexicon.py
dataset_info = {
'primary_ds' : 'QCD_HT-100To250_8TeV-madgraph',
'processed_ds' : 'LHE-testAlan_Attempt3-v2',
'tier' : 'LHE',
'group' : 'GEN',
'campaign_name' : 'LHE',
'application' : 'Madgraph',
'app_version' : 'Mad_5_1_3_30',
}
origin_site_name = 'srm-eoscms.cern.ch'
# in following line: no / at beginning but / at the end
# corresponds to the directory in EOS after /store/lhe
directory_path='5475/'
assert(directory_path[0] != '/')
assert(directory_path[-1] == '/')
# FROM NOW ON NO FREE NAMES
# PREPARE COMMON ADDITIONAL INFORMATION FOR FILES
common_lfn_prefix = '/store/lhe/'
common_file_type = 'LHE'
common_dummy_lumi = [{'lumi_section_num': 1, 'run_num': 1}]
# GET INPUT FILES LIST
# NOTE THAT CURRENTLY FILENAME HAS TO END WITH .root
myFilesList=['QCD_HT-100To250_8TeV-madgraph_10001.lhe']
inputFiles=[]
for i in myFilesList:
aFile ={'name':"%s" % i, \
'event_count': 1000000, \
'file_size': 85246505, \
'check_sum': '2291210323', \
#'adler32':'deadbeef'}
'adler32':'NOTSET'}
inputFiles.append(aFile)
# LOOP ON ALL FILES, CREATE BLOCKS AND INSERT THEM
files_in_block=0
max_files_in_block=500
for file in inputFiles:
if files_in_block == 0:
files=[]
blockDict = createEmptyBlock(dataset_info, origin_site_name)
fileDic={}
lfn=common_lfn_prefix + directory_path + file['name']
fileDic['file_type'] = common_file_type
fileDic['logical_file_name'] = lfn
for key in ['check_sum','adler32','file_size','event_count']:
fileDic[key] = file [key]
fileDic['file_lumi_list'] = common_dummy_lumi
files.append(fileDic)
files_in_block += 1
print "file count %d" % files_in_block
if files_in_block == max_files_in_block:
blockDict = addFilesToBlock(blockDict, files)
print "insert block in DBS3: %s" % writeApi.url
print "ALAN: just before writing to DBS."
pprint.pprint(blockDict)
sys.exit(0)
writeApi.insertBulkBlock(blockDict)
files_in_block = 0
# end loop on input Files
# any leftovers ?
if files_in_block:
blockDict = addFilesToBlock(blockDict, files)
print "insert block in DBS3: %s" % writeApi.url
print "ALAN: leftovers just before writing to DBS."
pprint.pprint(blockDict)
sys.exit(0)
writeApi.insertBulkBlock(blockDict)