29 LFLOAT_valueMagField = [0.0,2.0,3.0,3.5,3.8,4.0]
30 TD_shiftUTC = datetime.timedelta(hours = 2)
32 LSTR_true = [
'1',
'TRUE' ,
'True' ,
'true' ]
33 LSTR_false = [
'0',
'FALSE',
'False',
'false']
34 STR_default =
'DEFAULT'
36 LSTR_auto = [
'AUTO',
'Auto',
'auto']
37 STR_nameCmsswPackage =
'DQM/SiStripMonitorClient'
38 STR_textUsage =
""" CMSSW/DQM/SiStripMonitorClient/scripts/submitDQMOfflineCAF.py
40 This script submits batch jobs to the CAF in order to process the full
41 granularity SiStrip offline DQM.
42 Questions and comments to: volker.adler@cern.ch
44 Func_Usage(): submitDQMOfflineCAF.py (-s, --submit | -c, --create |
56 Function letters: One of the following options m u s t be used.
59 create jobs and submit them to CAF;
63 create jobs, but do not submit them;
72 number of run to process;
73 required by funtion letters '-s' and '-c'
75 -d, --dataset PRIMARY_DATASET
76 specify dataset for DBS query;
77 required by funtion letters '-s' and '-c'
80 submit or submit not using CRAB;
83 NOTE: This script runs only with CRAB 2.4.0 or higher.
85 -S, --server CRAB_SERVER
87 available: None (default)
89 bari (CRAB version >= 2.4.1,
90 s. https://twiki.cern.ch/twiki/bin/view/CMS/CrabServer#Server_available_for_users)
92 NOTE: CRAB server submission is disabled at the moment.
94 -e, --email EMAIL_ADDRESS
95 where the CRAB server should send its messages;
96 default: volker.adler@cern.ch
99 number of jobs to create;
102 -g, --global-tag GLOBAL_TAG
103 global tag to be used;
104 default: CRAFT_V4P::All
106 -M, --magnetic-field FIELD
107 specification of field to be used;
109 - average field during run in Tesla, given as float (e.g.: 3.8),
110 - specification referring to existing configuration files (e.g.: 38T)
111 (s. Configuration/StandardSequences/python/MagneticField_[FIELD]_cff.py),
112 - usage of automatic average field determination from CMS WBM by using "auto"
115 NOTE: "auto" is disabled for the moment due to unavailablity of CMS WBM outside '.cms' network.
117 -f, --filter TRUE/FALSE
118 use or use not HLT filters to select events to process;
122 path to copy job output *.root files to;
123 currently (almost) no check performed;
124 must be in AFS or CASTOR
125 default: /castor/cern.ch/user/c/cctrack/DQM
128 path to merge the job output *.root files;
129 currently (almost) no check performed;
130 must be in AFS or on local computer (e.g. /tmp/[user])
131 default: /afs/cern.ch/cms/CAF/CMSCOMM/COMM_TRACKER/DQM/SiStrip/jobs/merged
133 LSTR_datatiers = [
'RECO',
'RAW']
135 LSTR_wordArgument = sys.argv[1:]
138 LSTR_server = [STR_none,
'caf',
'bari']
139 STR_server = LSTR_server[0]
140 STR_email =
'volker.adler@cern.ch'
142 STR_globalTag =
'CRAFT_V4P::All'
144 BOOL_magFieldAuto =
False
146 STR_outpath =
'/castor/cern.ch/user/c/cctrack/DQM'
147 BOOL_useCastor =
True
148 STR_mergepath =
'/afs/cern.ch/cms/CAF/CMSCOMM/COMM_TRACKER/DQM/SiStrip/jobs/merged'
150 LSTR_functionLetters = [
'-s',
'-c',
'-h']
151 DICT_functionLetters = {
'--submit':LSTR_functionLetters[0],
152 '--create':LSTR_functionLetters[1],
153 '--help' :LSTR_functionLetters[2]}
154 LSTR_optionLetters = [
'-r',
'-C',
'-S',
'-e',
'-j',
'-M',
'-g',
'-f',
'-d',
'-o',
'-m']
155 DICT_optionLetters = {
'--run' :LSTR_optionLetters[0],
156 '--CRAB' :LSTR_optionLetters[1],
157 '--server' :LSTR_optionLetters[2],
158 '--email' :LSTR_optionLetters[3],
159 '--jobs' :LSTR_optionLetters[4],
160 '--magnetic-field':LSTR_optionLetters[5],
161 '--global-tag' :LSTR_optionLetters[6],
162 '--filter' :LSTR_optionLetters[7],
163 '--dataset' :LSTR_optionLetters[8],
164 '--outpath' :LSTR_optionLetters[9],
165 '--mergepath' :LSTR_optionLetters[10]}
166 STR_mailSmtp =
'localhost'
167 STR_mailServer =
'@mail.cern.ch'
168 STR_mailTextOpener =
"""Dear """ + os.getenv(
'USER').capitalize() +
""",
170 on """ + str(time.ctime()) +
""", you have submitted run """
172 for SiStrip offline DQM at the CAF.
173 Unfortunately, this needed to be done from your private account. So, only you
174 are able to finalize this submission -- even after the end of your shift.
175 To do so, please forward all emails from the LSF batch system referring to the
176 respective jobs to the list t h i s message was sent to.
177 -- and then your shift is r e a l l y done :-)
179 We are very sorry for the inconvenience.
183 your SiStrip DQM team
186 To reply to this email, simply use the "Reply to all" function of your email
193 global Dict_arguments
204 global Float_magField
205 global Bool_magFieldAuto
207 global Bool_useCastor
210 global Str_pathCurrentDir
211 global Str_pathCmsswBase
212 global Str_nameCmsswRel
213 global Str_pathCmsswBasePackage
215 global Str_pathRunIncludeDir
216 global Str_pathInputFilesCAFCff
221 Bool_CRAB = BOOL_CRAB
222 Str_server = STR_server
223 Str_email = STR_email
225 Str_globalTag = STR_globalTag
226 Bool_filter = BOOL_filter
227 Str_magField = STR_magField
228 Float_magField = float(Str_magField[:-1])/10.
229 Bool_magFieldAuto = BOOL_magFieldAuto
230 Str_outpath = STR_outpath
231 Bool_useCastor = BOOL_useCastor
232 Str_mergepath = STR_mergepath
238 """ Function Func_Usage():
239 Displays usage of the script
247 """ Function Func_Exit():
258 """ Function Func_ExitUsage():
259 Exit after wrong invocation of script
270 """ Function Func_ExitBool():
271 Exit after wrong assignment of bool option
273 print '> submitDQMOfflineCAF.py > option %s expects 0/1, FALSE/TRUE, False/True or false/true' %(DICT_optionLetters.items()[int_index])
280 """ Function Func_MkDir():
283 shutil.rmtree(str_path,
True)
290 """ Func_MagConfig(float_magFieldMeasured):
291 Determine configuration to be used for a given magnetic field
294 for float_valueMagField
in LFLOAT_valueMagField:
295 if math.fabs(float_valueMagField-float_magFieldMeasured) < math.fabs(float_magField-float_magFieldMeasured):
296 float_magField = float_valueMagField
297 return float_magField
305 Str_pathCurrentDir = os.getcwd()
306 Str_pathCmsswBase = os.getenv(
'CMSSW_BASE')
307 if not Str_pathCmsswBase:
308 print '> submitDQMOfflineCAF.py > CMSSW environment not set properly;'
311 print ' $ cd [your/CMSSW/release/area]/src'
315 Str_nameCmsswRel = os.getenv(
'CMSSW_VERSION')
316 Str_pathCmsswBasePackage = Str_pathCmsswBase +
'/src/' + STR_nameCmsswPackage
317 str_suffixShell =
'csh'
318 if not os.getenv(
'SHELL')[-3:] == str_suffixShell:
319 str_suffixShell =
'sh'
323 if len(LSTR_wordArgument) == 0:
325 int_nFunctionLetters = 0
326 for str_argument
in LSTR_wordArgument:
327 if str_argument
in LSTR_functionLetters
or\
328 DICT_functionLetters.has_key(str_argument) :
329 int_nFunctionLetters += 1
330 if int_nFunctionLetters == 0:
331 print '> submitDQMOfflineCAF.py > no or unknown function letter used'
333 elif int_nFunctionLetters > 1:
334 print '> submitDQMOfflineCAF.py > too many function letter used'
339 str_argumentFormer =
''
341 for str_argument
in LSTR_wordArgument:
342 if not ( str_argument
in LSTR_functionLetters
or DICT_functionLetters.has_key(str_argument)
or\
343 str_argument
in LSTR_optionLetters
or DICT_optionLetters.has_key(str_argument) ):
344 if str_argument[0] ==
'-':
345 print '> submitDQMOfflineCAF.py > unknown option used'
348 print '> submitDQMOfflineCAF.py > value without option used'
350 Dict_arguments[str_argumentFormer] = str_argument
354 Dict_arguments[str_argumentFormer] = STR_default
355 if str_argumentFormer
in LSTR_optionLetters
or\
356 DICT_optionLetters.has_key(str_argumentFormer):
357 print '> submitDQMOfflineCAF.py > option "%s" w/o value' %(str_argumentFormer)
358 print ' default used'
360 bool_standBy =
not ( str_argument
in LSTR_functionLetters
or\
361 DICT_functionLetters.has_key(str_argument) )
363 Dict_arguments[str_argument] = STR_default
364 str_argumentFormer = str_argument
366 Dict_arguments[str_argumentFormer] = STR_default
367 if str_argumentFormer
in LSTR_optionLetters
or\
368 DICT_optionLetters.has_key(str_argumentFormer) :
369 print '> submitDQMOfflineCAF.py > option "%s" w/o value' %(str_argumentFormer)
370 print ' default used'
375 dict_arguments = Dict_arguments
376 for str_key, str_value
in dict_arguments.items():
377 if str_key
in DICT_functionLetters.keys():
378 del Dict_arguments[str_key]
379 Dict_arguments[DICT_functionLetters[str_key]] = str_value
380 if str_key
in DICT_optionLetters.keys():
381 del Dict_arguments[str_key]
382 Dict_arguments[DICT_optionLetters[str_key]] = str_value
386 if Dict_arguments.has_key(LSTR_functionLetters[2]):
393 if Dict_arguments.has_key(LSTR_optionLetters[0])
and\
394 Dict_arguments[LSTR_optionLetters[0]] != STR_default :
395 Str_run = Dict_arguments[LSTR_optionLetters[0]]
397 print '> submitDQMOfflineCAF.py > no run number given'
400 if Dict_arguments.has_key(LSTR_optionLetters[1])
and\
401 Dict_arguments[LSTR_optionLetters[1]] != STR_default :
402 if Dict_arguments[LSTR_optionLetters[1]]
in LSTR_true:
404 elif Dict_arguments[LSTR_optionLetters[1]]
in LSTR_false:
409 if Dict_arguments.has_key(LSTR_optionLetters[2])
and\
410 Dict_arguments[LSTR_optionLetters[2]] != STR_default :
411 Str_server = Dict_arguments[LSTR_optionLetters[2]]
413 if Dict_arguments.has_key(LSTR_optionLetters[3])
and\
414 Dict_arguments[LSTR_optionLetters[3]] != STR_default :
415 Str_email = Dict_arguments[LSTR_optionLetters[3]]
417 if Dict_arguments.has_key(LSTR_optionLetters[4])
and\
418 Dict_arguments[LSTR_optionLetters[4]] != STR_default :
419 Int_jobs = int(Dict_arguments[LSTR_optionLetters[4]])
421 if Dict_arguments.has_key(LSTR_optionLetters[5])
and\
422 Dict_arguments[LSTR_optionLetters[5]] != STR_default :
423 Str_magField = Dict_arguments[LSTR_optionLetters[5]]
424 if Str_magField
in LSTR_auto:
426 print '> submitDQMOfflineCAF.py > automatic determination of magnetic field disabled at the moment'
429 if Dict_arguments.has_key(LSTR_optionLetters[6])
and\
430 Dict_arguments[LSTR_optionLetters[6]] != STR_default :
431 Str_globalTag = Dict_arguments[LSTR_optionLetters[6]]
433 if Dict_arguments.has_key(LSTR_optionLetters[7])
and\
434 Dict_arguments[LSTR_optionLetters[7]] != STR_default :
435 if Dict_arguments[LSTR_optionLetters[7]]
in LSTR_true:
437 elif Dict_arguments[LSTR_optionLetters[7]]
in LSTR_false:
442 if Dict_arguments.has_key(LSTR_optionLetters[8])
and\
443 Dict_arguments[LSTR_optionLetters[8]] != STR_default :
444 Str_dataset = Dict_arguments[LSTR_optionLetters[8]]
446 print '> submitDQMOfflineCAF.py > no primary dataset given'
449 if Dict_arguments.has_key(LSTR_optionLetters[9])
and\
450 Dict_arguments[LSTR_optionLetters[9]] != STR_default :
451 Str_outpath = Dict_arguments[LSTR_optionLetters[9]]
453 if Dict_arguments.has_key(LSTR_optionLetters[10])
and\
454 Dict_arguments[LSTR_optionLetters[10]] != STR_default :
455 Str_mergepath = Dict_arguments[LSTR_optionLetters[10]]
461 str_buffer = commands.getoutput(
'which crab')
462 if str_buffer.find(
'which: no crab in') >= 0:
463 str_suffixShell =
'csh'
464 if not os.getenv(
'SHELL')[-3:] == str_suffixShell:
465 str_suffixShell =
'sh'
466 print '> submitDQMOfflineCAF.py > CRAB environment not set properly;'
469 print ' $ source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.%s' %(str_suffixShell)
473 if not Str_server
in LSTR_server:
474 print '> submitDQMOfflineCAF.py > CRAB server "%s" not available' %(Str_server)
479 print '> submitDQMOfflineCAF.py > number of requested jobs was 0'
482 if Str_magField
in LSTR_auto:
484 print '> submitDQMOfflineCAF.py > automatic determination of magnetic field disabled at the moment'
486 elif Str_magField[-1] ==
'T':
487 bool_foundField =
False
488 for float_valueMagField
in LFLOAT_valueMagField:
489 if str(int(float_valueMagField*10)) == Str_magField[:-1]:
490 Float_magField = float_valueMagField
491 bool_foundField =
True
493 if not bool_foundField:
494 print '> submitDQMOfflineCAF.py > no magnet configuration for \'%s\' available' %(Str_magField)
497 Float_magField = float(Str_magField)
500 str_datatier = Str_dataset.split(
'/')[-1]
501 if str_datatier ==
'RAW-RECO':
502 Str_datatier = LSTR_datatiers[1]
504 Str_datatier = str_datatier
505 Str_datatier = Str_dataset.split(
'/')[-1]
506 if not Str_datatier
in LSTR_datatiers:
507 print '> submitDQMOfflineCAF.py > datatier "%s" not processable' %(Str_datatier)
511 if Str_outpath.split(
'/')[1] ==
'afs':
512 Bool_useCastor =
False
513 elif Str_outpath.split(
'/')[1] !=
'castor':
514 print '> submitDQMOfflineCAF.py > output path not accepted'
518 str_castorCp =
'rfcp'
520 if Str_mergepath.split(
'/')[1] !=
'afs':
521 print '> submitDQMOfflineCAF.py > merge path not accepted'
527 Str_nameRun =
'R' + Str_run.zfill(9)
530 Str_pathRunIncludeDir = Str_pathCmsswBasePackage +
'/python/' + Str_nameRun
532 str_nameInputFilesFile = Str_nameRun +
'/' + Str_nameRun +
'.txt'
533 str_nameRunIncludeDir = STR_nameCmsswPackage.replace(
'/',
'.') +
'.' + Str_nameRun
539 file_inputFilesCff =
file(str_nameInputFilesFile,
'w')
541 str_dbsParams = urllib.urlencode({
'dbsInst':
'cms_dbs_prod_global',
'blockName':
'*',
'dataset':Str_dataset,
'userMode':
'user',
'run':Str_run,
'what':
'py'})
542 file_dbsOutput = urllib.urlopen(
"https://cmsweb.cern.ch/dbs_discovery/getLFN_txt", str_dbsParams)
543 for str_iLine
in file_dbsOutput.readlines():
544 lstr_wordsLine = str_iLine.split(
"/")
545 if len(lstr_wordsLine) >= 5:
546 if lstr_wordsLine[1] ==
'store' and\
547 lstr_wordsLine[2] ==
'data' and\
548 Str_dataset.find(lstr_wordsLine[3]) >= 0
and\
549 Str_dataset.find(lstr_wordsLine[4]) >= 0
and\
550 lstr_wordsLine[5] == str_datatier :
552 file_inputFilesCff.write(str_iLine)
553 if int_nInputFiles == 0:
554 print '> submitDQMOfflineCAF.py > no input files found in DBS for run %s in dataset %s' %(Str_run,Str_dataset)
556 file_inputFilesCff.close()
557 print '> submitDQMOfflineCAF.py > input files for run %s: %i' %(Str_run,int_nInputFiles)
558 if int_nInputFiles < Int_jobs:
559 Int_jobs = int_nInputFiles
560 print ' number of requested jobs reduced accordingly'
561 Int_jobsNew = Int_jobs
565 if Bool_magFieldAuto:
567 str_cmsmonParams = urllib.urlencode({
'RUN':Str_run})
568 file_cmsmonOutput = urllib.urlopen(
"http://cmsmon.cern.ch/cmsdb/servlet/RunSummary", str_cmsmonParams)
571 for str_cmsmonOutput
in file_cmsmonOutput.readlines():
572 if str_cmsmonOutput.find(
'HREF=Component?RUN=' + Str_run +
'&NAME=TRACKER') >= 0:
573 lstr_timeQuery = str_cmsmonOutput.split(
'HREF=Component?RUN=' + Str_run +
'&NAME=TRACKER&')[1].
split(
'>TRACKER')[0].
split(
'&')
574 for str_timeQuery
in lstr_timeQuery:
575 str_nameStamp = str_timeQuery.split(
'=')[0]
576 lstr_timeDate = str_timeQuery.split(
'=')[1].
split(
'_')[0].
split(
'.')
577 lstr_timeTime = str_timeQuery.split(
'=')[1].
split(
'_')[1].
split(
':')
578 dt_stampOld = datetime.datetime(int(lstr_timeDate[0]),int(lstr_timeDate[1]),int(lstr_timeDate[2]),int(lstr_timeTime[0]),int(lstr_timeTime[1]),int(lstr_timeTime[2]))
579 dt_stampNew = dt_stampOld - TD_shiftUTC
580 str_timeStamp = str(dt_stampNew).
replace(
'-',
'.')
581 if str_nameStamp ==
'TIME_BEGIN':
582 str_timeBegin = str_timeStamp
583 elif str_nameStamp ==
'TIME_END':
584 str_timeEnd = str_timeStamp
586 str_cmsmonParams = urllib.urlencode({
'TIME_BEGIN':str_timeBegin,
'TIME_END':str_timeEnd})
587 file_cmsmonOutput = urllib.urlopen(
"http://cmsmon.cern.ch/cmsdb/servlet/MagnetHistory", str_cmsmonParams)
588 bool_foundField =
False
589 for str_cmsmonOutput
in file_cmsmonOutput.readlines():
590 if str_cmsmonOutput.find(
'BFIELD, Tesla') >= 0:
591 Float_magField = float(str_cmsmonOutput.split(
'</A>')[0].
split(
'>')[-1])
592 bool_foundField =
True
594 if not bool_foundField:
595 print '> submitDQMOfflineCAF.py > could not extract magnetic field'
596 print ' please provide value'
600 Str_magField = str(int(float_magField*10)) +
'T'
601 print '> submitDQMOfflineCAF.py > (average) magnetic field in run %s: %s T' %(Str_run,Float_magField)
602 print ' using %s T for configuration' %(float_magField)
608 file_inputFilesCff =
file(str_nameInputFilesFile)
609 lstr_linesInput = file_inputFilesCff.readlines()
610 file_inputFilesCff.close()
613 str_sedCommand =
'sed '
614 str_sedCommand +=
'-e \"s#xMAG_FIELDx#' + Str_magField +
'#g\" '
615 str_sedCommand +=
'-e \"s#xGLOBAL_TAGx#' + Str_globalTag +
'#g\" '
616 str_sedCommand +=
'-e \"s#xINCLUDE_DIRECTORYx#' + str_nameRunIncludeDir +
'#g\" '
617 str_sedCommand +=
'-e \"s#xMERGE_PATHx#' + Str_mergepath +
'#g\" '
618 str_sedCommand += Str_pathCmsswBasePackage +
'/test/SiStripCAFHarvest_template_cfg.py > ' + Str_nameRun +
'/SiStripCAFHarvest_cfg.py'
619 os.system(str_sedCommand)
620 str_sedCommand =
'sed '
621 str_sedCommand +=
'-e \"s#xCMSSW_BASEx#' + Str_pathCmsswBase +
'#g\" '
622 str_sedCommand +=
'-e \"s#xRUN_NAMEx#' + Str_nameRun +
'#g\" '
623 str_sedCommand +=
'-e \"s#xMERGE_PATHx#' + Str_mergepath +
'#g\" '
624 str_sedCommand +=
'-e \"s#xCURRENT_DIRx#' + Str_pathCurrentDir +
'#g\" '
625 str_sedCommand +=
'-e \"s#xDATA_TIERx#' + Str_datatier +
'#g\" '
626 str_sedCommand +=
'-e \"s#xCMSSW_VERSIONx#' + Str_nameCmsswRel +
'#g\" '
627 str_sedCommand += Str_pathCmsswBasePackage +
'/scripts/SiStripDQMCAFHarvest_template.job > ' + Str_nameRun +
'/SiStripCAFHarvest.job'
628 os.system(str_sedCommand)
630 Str_pathInputFilesCAFCff = Str_pathRunIncludeDir +
'/inputFilesCAF_cff.py'
631 file_inputFilesCAFCff =
file(Str_pathInputFilesCAFCff,
'w')
632 file_inputFilesCAFCff.write(
'import FWCore.ParameterSet.Config as cms\n\nsource = cms.Source ("PoolSource",\n processingMode = cms.untracked.string( \'Runs\' ),\n fileNames = cms.untracked.vstring(\n')
633 for int_iJob
in range(1,Int_jobs+1):
634 str_lineInput = Str_outpath +
'/SiStripDQMOfflineGlobalRunCAF-' + Str_nameRun +
'_' + str(int_iJob) +
'.root'
636 str_lineInput =
'rfio:' + str_lineInput
637 str_lineInput =
' \'' + str_lineInput +
'\''
638 if int_iJob == Int_jobs:
639 str_lineInput +=
'\n'
640 file_inputFilesCAFCff.write(str_lineInput)
642 str_lineInput +=
',\n'
643 file_inputFilesCAFCff.write(str_lineInput)
644 file_inputFilesCAFCff.write(
' )\n)\n')
645 file_inputFilesCAFCff.close()
647 str_sedCommandCommon =
'sed '
649 str_sedCommandCommon +=
'-e \"s#xHLT_FILTERx# #g\" '
651 str_sedCommandCommon +=
'-e \"s#xHLT_FILTERx#\# #g\" '
652 if Str_datatier ==
'RECO':
653 str_sedCommandCommon +=
'-e \"s#xRECO_FROM_RAWx#\# #g\" '
654 str_sedCommandCommon +=
'-e \"s#xDQM_FROM_RAWx#\# #g\" '
656 str_sedCommandCommon +=
'-e \"s#xRECO_FROM_RAWx# #g\" '
657 str_sedCommandCommon +=
'-e \"s#xDQM_FROM_RAWx# #g\" '
658 str_sedCommandCommon +=
'-e \"s#xMAG_FIELDx#' + Str_magField +
'#g\" '
659 str_sedCommandCommon +=
'-e \"s#xGLOBAL_TAGx#' + Str_globalTag +
'#g\" '
660 str_sedCommandCommon +=
'-e \"s#xRUN_NAMEx#' + Str_nameRun +
'#g\" '
663 os.chdir(Str_nameRun)
666 str_sedCommand = str_sedCommandCommon
667 str_sedCommand +=
'-e \"s#xINCLUDE_DIRECTORYx#' + str_nameRunIncludeDir +
'#g\" '
668 str_sedCommand +=
'-e \"s#xOUTPUT_DIRECTORYx#' + str_outputDir +
'#g\" '
669 str_sedCommand += Str_pathCmsswBasePackage +
'/test/SiStripDQMOfflineGlobalRunCAF_template_cfg.py > SiStripDQMOfflineGlobalRunCAF_cfg.py'
670 os.system(str_sedCommand)
672 str_pathInputFilesJobCff = Str_pathRunIncludeDir +
'/inputFiles_cff.py'
673 file_inputFilesJobCff =
file(str_pathInputFilesJobCff,
'w')
674 file_inputFilesJobCff.write(
'import FWCore.ParameterSet.Config as cms\n\nsource = cms.Source ("PoolSource",\n fileNames = cms.untracked.vstring (\n')
676 for str_linesInput
in lstr_linesInput:
678 str_correctedLine1 = str_linesInput.replace(
') );',
',')
679 str_correctedLine = str_correctedLine1.replace(
' ] );',
',')
680 if nLines == len(lstr_linesInput):
681 str_actualLine = str_correctedLine.replace(
',',
'\n )\n)\n')
682 elif nLines%255 == 0:
683 str_actualLine = str_correctedLine.replace(
',',
'\n )\n)\nsource.fileNames.extend(\n (')
685 str_actualLine = str_correctedLine
686 file_inputFilesJobCff.write(str_actualLine)
687 file_inputFilesJobCff.close()
689 lstr_outpath = Str_outpath.split(
'/', 3)
690 str_outpath = lstr_outpath[0] +
'/' + lstr_outpath[1] +
'/' + lstr_outpath[2]
691 str_sedCommand =
'sed '
692 str_sedCommand +=
'-e \"s#xSERVER_NAMEx#' + Str_server +
'#g\" '
693 str_sedCommand +=
'-e \"s#xDATASETPATHx#' + Str_dataset +
'#g\" '
694 str_sedCommand +=
'-e \"s#xRUNSELECTIONx#' + Str_run +
'#g\" '
695 str_sedCommand +=
'-e \"s#xNUMBER_OF_JOBSx#' + str(Int_jobs) +
'#g\" '
696 str_sedCommand +=
'-e \"s#xEMAILx#' + Str_email +
'#g\" '
697 str_sedCommand +=
'-e \"s#xRUN_NAMEx#' + Str_nameRun +
'#g\" '
698 str_sedCommand +=
'-e \"s#xSTORAGE_PATHx#' + str_outpath +
'#g\" '
699 str_sedCommand +=
'-e \"s#xLFNx#' + lstr_outpath[3] +
'#g\" '
700 str_sedCommand +=
'-e \"s#xCOPY_DATAx#' + str(int(Bool_useCastor)) +
'#g\" '
701 str_sedCommand += Str_pathCmsswBasePackage +
'/test/SiStripDQMOfflineCAF_template.crab > crab.cfg'
702 os.system(str_sedCommand)
703 os.chdir(Str_pathCurrentDir)
706 int_nInputFilesJob = int(int_nInputFiles/Int_jobs) + 1
707 if int_nInputFiles%Int_jobs == 0:
708 int_nInputFilesJob -= 1
709 if int_nInputFiles == int_nInputFilesJob*(Int_jobs-1)
and Int_jobs > 1:
712 for int_iJob
in range(1,Int_jobs+1):
713 str_nameJob = Str_nameRun +
'_' + str(int_iJob).zfill(4)
715 str_nameJobDir = Str_nameRun +
"/" + str_nameJob
716 str_outputDir =
'/tmp/' + os.getenv(
'USER') +
'/' + str_nameJobDir
717 str_pathJobIncludeDir = Str_pathRunIncludeDir +
'/' + str_nameJob
718 str_nameJobIncludeDir = STR_nameCmsswPackage.replace(
'/',
'.') +
'.' + str_nameJobDir.replace(
'/',
'.')
719 os.mkdir(str_nameJobDir)
720 os.chdir(str_nameJobDir)
722 str_sedCommand =
'sed '
723 str_sedCommand +=
'-e \"s#xCMSSW_BASEx#' + Str_pathCmsswBase +
'#g\" '
724 str_sedCommand +=
'-e \"s#xRUN_NAMEx#' + Str_nameRun +
'#g\" '
725 str_sedCommand +=
'-e \"s#xJOB_NAMEx#' + str_nameJob +
'#g\" '
726 str_sedCommand +=
'-e \"s#xCURRENT_DIRx#' + Str_pathCurrentDir +
'#g\" '
727 str_sedCommand +=
'-e \"s#xCOPYx#' + str_castorCp +
'#g\" '
728 str_sedCommand +=
'-e \"s#xOUTPUT_DIRx#' + Str_outpath +
'#g\" '
729 str_sedCommand += Str_pathCmsswBasePackage +
'/scripts/SiStripDQMOfflineCAF_template.job > SiStripDQMOfflineCAF.job'
730 os.system(str_sedCommand)
732 str_sedCommand = str_sedCommandCommon
733 str_sedCommand +=
'-e \"s#xINCLUDE_DIRECTORYx#' + str_nameJobIncludeDir +
'#g\" '
734 str_sedCommand +=
'-e \"s#xOUTPUT_DIRECTORYx#' + str_outputDir +
'#g\" '
735 str_sedCommand += Str_pathCmsswBasePackage +
'/test/SiStripDQMOfflineGlobalRunCAF_template_cfg.py > SiStripDQMOfflineGlobalRunCAF_cfg.py'
736 os.system(str_sedCommand)
738 os.mkdir(str_pathJobIncludeDir)
740 str_pathInputFilesJobCff = str_pathJobIncludeDir +
'/inputFiles_cff.py'
741 file_inputFilesJobCff =
file(str_pathInputFilesJobCff,
'w')
742 file_inputFilesJobCff.write(
'import FWCore.ParameterSet.Config as cms\n\nsource = cms.Source ("PoolSource",\n fileNames = cms.untracked.vstring (\n')
743 for n_iActualLine
in range(int_nLinesRead,
min(int_nLinesRead+int_nInputFilesJob, int_nInputFiles)):
744 str_linesInput = lstr_linesInput[n_iActualLine].
replace(
') );',
',')
746 str_actualLine = str_linesInput
747 if (n_iActualLine+1)%int_nInputFilesJob == 0
or int_nLinesRead == int_nInputFiles-1:
748 str_actualLine = str_linesInput.split(
',')[0] +
'\n'
749 file_inputFilesJobCff.write(str_actualLine)
751 file_inputFilesJobCff.write(
' )\n)\n')
752 file_inputFilesJobCff.close()
754 os.chdir(Str_pathCurrentDir)
756 if int_nLinesRead >= int_nInputFiles:
757 Int_jobsNew = int_iJob
762 os.chdir(Str_pathRunIncludeDir+
'/..')
763 os.system(
'scramv1 b python')
764 os.chdir(Str_pathCurrentDir)
770 os.chdir(Str_nameRun)
771 os.system(
'crab -create')
775 file_logCRAB =
file(
'crab'+Str_nameRun+
'/log/crab.log')
776 for str_iLine
in file_logCRAB.readlines():
777 if str_iLine.startswith(
'Total of ')
and str_iLine.endswith(
' jobs created.\n'):
779 Int_jobsNew = int(str_iLine.split()[2])
782 os.chdir(Str_pathCurrentDir)
784 print '> submitDQMOfflineCAF.py > could not extract number of jobs created by CRAB; check'
785 print ' %s' %(Str_pathInputFilesCAFCff)
786 print ' and modify manually, if necessary'
791 print '> submitDQMOfflineCAF.py > number of created jobs: %i' %(Int_jobsNew)
793 if Int_jobsNew != Int_jobs:
794 file_inputFilesCAFCff =
file(Str_pathInputFilesCAFCff,
'w')
795 file_inputFilesCAFCff.write(
'import FWCore.ParameterSet.Config as cms\n\nsource = cms.Source ("PoolSource",\n processingMode = cms.untracked.string( \'Runs\' ),\n fileNames = cms.untracked.vstring(\n')
796 for int_iJob
in range(1,Int_jobsNew+1):
797 str_lineInput = Str_outpath +
'/SiStripDQMOfflineGlobalRunCAF-' + Str_nameRun +
'_' + str(int_iJob) +
'.root'
799 str_lineInput =
'rfio:' + str_lineInput
800 str_lineInput =
' \'' + str_lineInput +
'\''
801 if int_iJob == Int_jobsNew:
802 str_lineInput +=
'\n'
803 file_inputFilesCAFCff.write(str_lineInput)
805 str_lineInput +=
',\n'
806 file_inputFilesCAFCff.write(str_lineInput)
807 file_inputFilesCAFCff.write(
' )\n)\n')
808 file_inputFilesCAFCff.close()
812 if Dict_arguments.has_key(LSTR_functionLetters[0]):
813 os.chdir(Str_nameRun)
815 str_crabCommand =
'crab -submit -c crab' + Str_nameRun
816 print '> submitDQMOfflineCAF.py >'
817 print ' %s : %s' %(os.getcwd(),str_crabCommand)
818 os.system(str_crabCommand)
821 os.system(
'crab -status -c crab' + Str_nameRun)
823 for int_iJob
in range(Int_jobs):
824 str_nameJobDir = Str_nameRun +
'_' + str(int_iJob).zfill(4)
825 os.chdir(str_nameJobDir)
826 os.chmod(
'SiStripDQMOfflineCAF.job',OCT_rwx_r_r)
827 str_batchCommand =
'bsub -q cmscaf SiStripDQMOfflineCAF.job'
828 print '> submitDQMOfflineCAF.py >'
829 print ' %s : %s' %(os.getcwd(),str_batchCommand)
830 os.system(str_batchCommand)
834 os.system(
'bjobs -q cmscaf')
835 os.chmod(
'SiStripCAFHarvest.job',OCT_rwx_r_r)
836 os.chdir(Str_pathCurrentDir)
840 if Dict_arguments.has_key(LSTR_functionLetters[0])
and not Bool_CRAB:
841 str_mailFrom = os.getenv(
'USER') + STR_mailServer
842 str_mailTo = [str_mailFrom,
843 'volker.adler@cern.ch',
844 'suchandra.dutta@cern.ch',
845 'domenico.giordano@cern.ch',
846 'vitaliano.ciulli@cern.ch']
847 str_mailSubject =
'Your SiStrip offline DQM shift on ' + str(datetime.date.today()) +
', run ' + Str_run
848 str_mailText = STR_mailTextOpener + Str_run + STR_mailText
849 str_mailMessage =
"""From: %s
854 """ % (str_mailFrom,
", ".
join(str_mailTo), str_mailSubject, str_mailText)
855 server = smtplib.SMTP(STR_mailSmtp)
856 server.sendmail(str_mailFrom, str_mailTo, str_mailMessage)
def Func_Usage
Function Func_Usage()
def Func_MkDir
Function Func_MkDir()
def Func_MagConfig
Function Func_MagConfig(float_magFieldMeasured)
def Func_Exit
Function Func_Exit()
def Func_ExitBool
Function Func_ExitBool()
static std::string join(char **cmd)
def Func_ExitUsage
Function Func_ExitUsage()