6 from subprocess
import call
16 Run_type = sys.argv[1]
17 Run_Number = [
int(x)
for x
in sys.argv[2:]]
18 CMSSW_BASE =
str(os.popen(
'echo ${CMSSW_BASE}').read().
strip())
21 if Run_type ==
'Cosmics' or Run_type ==
'StreamExpress' or Run_type ==
'StreamExpressCosmics' or 'ZeroBias' or re.match(
'ZeroBias([0-9]+?)',Run_type):
25 print "please enter a valid run type: Cosmics | ZeroBias | StreamExpress | StreamExpressCosmics ";
29 for i
in range(len(Run_Number)):
31 if Run_Number[i] > 308336:
32 DataLocalDir=
'Data2018' 33 DataOfflineDir=
'Commissioning2018' 35 elif Run_Number[i] > 294644:
36 DataLocalDir=
'Data2017' 37 DataOfflineDir=
'Run2017' 39 elif Run_Number[i] > 290123:
40 DataLocalDir=
'Data2017' 41 DataOfflineDir=
'Commissioning2017' 44 elif Run_Number[i] > 284500:
45 DataLocalDir=
'Data2016';
46 DataOfflineDir=
'PARun2016';
49 elif Run_Number[i] > 271024:
50 DataLocalDir=
'Data2016';
51 DataOfflineDir=
'Run2016';
54 elif Run_Number[i] > 264200:
55 DataLocalDir=
'Data2016';
56 DataOfflineDir=
'Commissioning2016';
59 elif Run_Number[i] > 246907:
60 DataLocalDir=
'Data2015';
61 DataOfflineDir=
'Run2015' 64 elif Run_Number[i] > 232881:
65 DataLocalDir=
'Data2015';
66 DataOfflineDir=
'Commissioning2015';
69 elif Run_Number[i] > 211658:
70 DataLocalDir=
'Data2013';
71 DataOfflineDir=
'Run2013';
74 elif Run_Number[i] > 209634:
75 DataLocalDir=
'Data2013';
76 DataOfflineDir=
'HIRun2013';
78 elif Run_Number[i] > 190450:
79 DataLocalDir=
'Data2012';
80 DataOfflineDir=
'Run2012';
83 print "Please enter vaild run numbers" 88 nnnOut = Run_Number[i]/1000
89 nnnOnline = Run_Number[i]/10000
91 print 'Processing '+Run_type+
' in '+DataOfflineDir+
"..." 95 print 'Directory to fetch the DQM file from: https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/'+DataOfflineDir+
'/'+Run_type+
'/000'+
str(nnn)+
'xx/' 96 url =
'https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/'+DataOfflineDir+
'/'+Run_type+
'/000'+
str(nnn)+
'xx/' 97 os.popen(
"curl -k --cert /data/users/cctrkdata/current/auth/proxy/proxy.cert --key /data/users/cctrkdata/current/auth/proxy/proxy.cert -X GET "+url+
" > index.html")
98 f=codecs.open(
"index.html",
'r') 100 if any(
str(Run_Number[i])
in s
for s
in index):
103 if (
str(Run_Number[i])
in s)
and (
"__DQMIO.root" in s):
106 print 'No DQM file available. Please check the Offline server' 109 print 'Downloading DQM file:'+File_Name
112 os.system(
'curl -k --cert /data/users/cctrkdata/current/auth/proxy/proxy.cert --key /data/users/cctrkdata/current/auth/proxy/proxy.cert -X GET https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/'+DataOfflineDir+
'/'+Run_type+
'/000'+
str(nnn)+
'xx/'+File_Name+
' > /tmp/'+File_Name)
119 url1 =
'https://cmsweb.cern.ch/dqm/online/data/browse/Original/000'+
str(nnnOnline)+
'xxxx/000'+
str(nnn)+
'xx/' 120 os.popen(
"curl -k --cert /data/users/cctrkdata/current/auth/proxy/proxy.cert --key /data/users/cctrkdata/current/auth/proxy/proxy.cert -X GET "+url1+
" > index_online.html")
122 url2 =
'https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OnlineData/original/000'+
str(nnnOnline)+
'xxxx/000'+
str(nnn)+
'xx/' 123 os.popen(
"curl -k --cert /data/users/cctrkdata/current/auth/proxy/proxy.cert --key /data/users/cctrkdata/current/auth/proxy/proxy.cert -X GET "+url2+
" > index_online_backup.html")
124 f_online_backup=codecs.open(
"index_online_backup.html",
'r') 125 index_online_backup = f_online_backup.readlines() 127 f_online=codecs.open("index_online.html",
'r') 128 index_online = f_online.readlines() 129 if any(
str(Run_Number[i])
in x
for x
in index_online):
130 for x
in index_online:
131 if (
str(Run_Number[i])
in x)
and (
"_PixelPhase1_" in x):
135 print "Can't find any file in offline server, trying the online server" 136 if any(
str(Run_Number[i])
in y
for y
in index_online_backup):
137 for y
in index_online:
138 if (
str(Run_Number[i])
in y)
and (
"_PixelPhase1_" in y):
142 print 'No Online DQM file available. Skip dead roc map' 145 if deadRocMap ==
True:
146 print 'Downloading DQM file:'+File_Name_online
149 os.system(
'curl -k --cert /data/users/cctrkdata/current/auth/proxy/proxy.cert --key /data/users/cctrkdata/current/auth/proxy/proxy.cert -X GET https://cmsweb.cern.ch/dqm/online/data/browse/Original/000'+
str(nnnOnline)+
'xxxx/000'+
str(nnn)+
'xx/'+File_Name_online+
' > /tmp/'+File_Name_online)
151 os.remove(
'index_online.html')
152 os.remove(
'index_online_backup.html')
159 print "get the run status from DQMFile" 162 check_command =
'check_runcomplete '+filepath+File_Name
163 Check_output = subprocess.call(check_command, shell=
True)
166 if Check_output == 0:
167 print 'Using DQM file: '+File_Name
169 print '*****************Warning: DQM file is not ready************************';
170 input_var = raw_input(
"DQM file is incompleted, do you want to continue? (y/n): ")
171 if (input_var ==
'y')
or (input_var ==
'Y'):
172 print 'Using DQM file: '+File_Name
179 checkfolder = os.path.exists(
str(Run_Number[i]))
180 if checkfolder ==
True:
181 shutil.rmtree(
str(Run_Number[i]))
182 os.makedirs(
str(Run_Number[i])+
'/'+Run_type)
184 os.makedirs(
str(Run_Number[i])+
'/'+Run_type)
188 globalTag_v0 = os.popen(
'getGTfromDQMFile.py '+ filepath+File_Name+
' ' +
str(Run_Number[i])+
' globalTag_Step1').readline().
strip()
189 print "Global Tag: " + globalTag_v0
190 globalTag = globalTag_v0
192 for z
in range(len(globalTag_v0)-2):
193 if (globalTag_v0[z].isdigit())
and (globalTag_v0[z+1].isdigit())
and (globalTag_v0[z+2].isdigit())
and (globalTag_v0[z+3].isupper()):
194 globalTag = globalTag_v0[z:]
199 print " No GlobalTag found: trying from DAS.... ";
200 globalTag =
str(os.popen(
'getGTscript.sh '+filepath+ File_Name+
' ' +
str(Run_Number[i])));
202 print " No GlobalTag found for run: "+
str(Run_Number[i]);
204 print " Creating the TrackerMap.... " 206 detIdInfoFileName =
'TkDetIdInfo_Run'+
str(Run_Number[i])+
'_'+Run_type+
'.root' 207 workPath = os.popen(
'pwd').readline().
strip()
209 os.chdir(
str(Run_Number[i])+
'/'+Run_type)
212 os.system(
'cmsRun ${CMSSW_BASE}/src/DQM/SiStripMonitorClient/test/SiStripDQM_OfflineTkMap_Template_cfg_DB.py globalTag='+globalTag+
' runNumber='+
str(Run_Number[i])+
' dqmFile='+filepath+
'/'+File_Name+
' detIdInfoFile='+detIdInfoFileName)
213 os.system(
'rm -f *svg')
215 sefile =
'QualityTest_run'+
str(Run_Number[i])+
'.txt' 216 shutil.move(
'QTBadModules.log',sefile)
226 if Run_type ==
"Cosmics" or Run_type ==
"StreamExpressCosmics":
227 os.system(
'cat ${CMSSW_BASE}/src/DQM/SiStripMonitorClient/data/index_template_TKMap_cosmics.html | sed -e "s@RunNumber@'+
str(Run_Number[i])+
'@g" > index.html')
229 os.system(
'cat ${CMSSW_BASE}/src/DQM/SiStripMonitorClient/data/index_template_TKMap.html | sed -e "s@RunNumber@'+
str(Run_Number[i])+
'@g" > index.html')
231 shutil.copyfile(CMSSW_BASE+
'/src/DQM/SiStripMonitorClient/data/fedmap.html',
'fedmap.html')
232 shutil.copyfile(CMSSW_BASE+
'/src/DQM/SiStripMonitorClient/data/psumap.html',
'psumap.html')
234 print " Check TrackerMap on "+
str(Run_Number[i])+
'/'+Run_type+
" folder" 237 output.append(os.popen(
"/bin/ls ").readline().
strip())
241 print " Creating the list of bad modules " 243 os.system(
'listbadmodule '+filepath+
'/'+File_Name+
' PCLBadComponents.log')
263 os.system(
'bs_bad_ls_harvester . '+
str(Run_Number[i]))
270 if (Run_type ==
"Cosmics")
or (Run_type ==
"StreamExpressCosmics"):
275 os.system(
'cmsRun ${CMSSW_BASE}/src/DQM/SiStripMonitorClient/test/mergeBadChannel_Template_cfg.py globalTag='+globalTag+
' runNumber='+
str(Run_Number[i])+
' dqmFile='+filepath+
'/'+File_Name)
276 shutil.move(
'MergedBadComponents.log',
'MergedBadComponents_run'+
str(Run_Number[i])+
'.txt')
278 os.system(
"mkdir -p /data/users/event_display/TkCommissioner_runs/"+DataLocalDir+
"/"+dest+
" 2> /dev/null")
281 shutil.copyfile(detIdInfoFileName,
'/data/users/event_display/TkCommissioner_runs/'+DataLocalDir+
'/'+dest+
'/'+detIdInfoFileName)
283 os.remove(detIdInfoFileName)
284 os.remove(
'MergedBadComponentsTkMap_Canvas.root')
285 os.remove(
'MergedBadComponentsTkMap.root')
287 print "countig dead pixel ROCs" 288 if (Run_Number[i] < 290124) :
290 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/DeadROCCounter.py '+filepath+
'/'+File_Name)
292 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/DeadROCCounter_Phase1.py '+filepath+
'/'+File_Name)
294 os.system(
'mkdir -p /data/users/event_display/'+DataLocalDir+
'/'+dest+
'/'+
str(nnnOut)+
'/'+
str(Run_Number[i])+
'/'+Run_type+
' 2> /dev/null')
296 shutil.move(
'PixZeroOccROCs_run'+
str(Run_Number[i])+
'.txt',workPath+
'/PixZeroOccROCs_run'+
str(Run_Number[i])+
'.txt')
303 if deadRocMap ==
True:
305 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/DeadROC_duringRun.py '+filepath+File_Name_online+
' '+filepath+File_Name)
306 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/change_name.py')
307 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/PixelMapPlotter.py MaskedROC_sum.txt -c')
308 os.remove(
'MaskedROC_sum.txt')
310 print 'No Online DQM file available, Dead ROC maps will not be produced' 316 if deadRocMap ==
True:
318 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/InefficientDoubleROC.py '+filepath+File_Name_online)
321 print 'No Online DQM file available, inefficient DC list will not be produced' 328 strip_files = os.listdir(
'.')
329 for file_name
in strip_files:
330 full_stripfile_name = os.path.join(
'.', file_name)
331 if (os.path.isfile(full_stripfile_name)):
332 shutil.copy(full_stripfile_name,
'/data/users/event_display/'+DataLocalDir+
'/'+dest+
'/'+
str(nnnOut)+
'/'+
str(Run_Number[i])+
'/'+Run_type)
339 shutil.rmtree(
str(Run_Number[i]))
340 os.remove(
'index.html')
344 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/TH2PolyOfflineMaps.py ' + filepath+
'/'+File_Name+
' 3000 2000')
345 shutil.move(workPath+
'/PixZeroOccROCs_run'+
str(Run_Number[i])+
'.txt',
'OUT/PixZeroOccROCs_run'+
str(Run_Number[i])+
'.txt')
349 pixel_files = os.listdir(
'./OUT')
350 for file_name
in pixel_files:
351 full_pixelfile_name = os.path.join(
'./OUT/', file_name)
352 if (os.path.isfile(full_pixelfile_name)):
353 shutil.copy(full_pixelfile_name,
'/data/users/event_display/'+DataLocalDir+
'/'+dest+
'/'+
str(nnnOut)+
'/'+
str(Run_Number[i])+
'/'+Run_type)
360 pixelTreeFileName =
'PixelPhase1Tree_Run'+
str(Run_Number[i])+
'_'+Run_type+
'.root' 361 os.system(
'${CMSSW_BASE}/src/DQM/SiStripMonitorClient/scripts/PhaseITreeProducer.py ' + filepath+
'/'+File_Name +
' ' + pixelTreeFileName)
363 shutil.copyfile(pixelTreeFileName,
'/data/users/event_display/TkCommissioner_runs/'+DataLocalDir+
'/'+dest+
'/'+pixelTreeFileName)
364 os.remove(pixelTreeFileName)
365 os.remove(filepath+File_Name)
366 os.remove(filepath+File_Name_online)
bool any(const std::vector< T > &v, const T &what)