1 from CalibMuon.DTCalibration.Workflow.DTTTrigProd
import DTTTrigProd
2 from CalibMuon.DTCalibration.Workflow.DTTTrigTimeBoxesWriter
import DTTTrigTimeBoxesWriter
3 from CalibMuon.DTCalibration.Workflow.DTResidualCalibration
import DTResidualCalibration
4 from CalibMuon.DTCalibration.Workflow.DTTTrigResidualCorr
import DTTTrigResidualCorr
5 from CalibMuon.DTCalibration.Workflow.DTTTrigValid
import DTTTrigValid
6 from CalibMuon.DTCalibration.Workflow.DTValidSummary
import DTValidSummary
7 from CalibMuon.DTCalibration.Workflow.DTVDriftSegmentCalibration
import DTVDriftSegmentCalibration
8 from CalibMuon.DTCalibration.Workflow.DTVDriftSegmentWriter
import DTVDriftSegmentWriter
9 from CalibMuon.DTCalibration.Workflow.DTVDriftMeanTimerCalibration
import DTVDriftMeanTimerCalibration
10 from CalibMuon.DTCalibration.Workflow.DTVDriftMeanTimerWriter
import DTVDriftMeanTimerWriter
11 from CalibMuon.DTCalibration.Workflow.DTNoiseCalibration
import DTNoiseCalibration
12 from CalibMuon.DTCalibration.Workflow.DTDQMValidation
import DTDQMValidation
13 from CalibMuon.DTCalibration.Workflow.DTDQMMerge
import DTDQMMerge
14 from CalibMuon.DTCalibration.Workflow.DTDQMHarvesting
import DTDQMHarvesting
15 from CalibMuon.DTCalibration.Workflow.DTDqm
import DTDqm
16 from CalibMuon.DTCalibration.Workflow.DTT0DBValidation
import DTT0DBValidation
17 from CalibMuon.DTCalibration.Workflow.DTAnalysisResiduals
import DTAnalysisResiduals
18 from CalibMuon.DTCalibration.Workflow.CrabWatch
import CrabWatch
19 from CalibMuon.DTCalibration.Workflow.tools
import listFilesInCastor,haddInCastor,listFilesLocal,haddLocal,copyFilesFromCastor,copyFilesLocal,parseInput,getDatasetStr
20 import sys,os,time,optparse
27 def run(self,type,mode,execute):
36 elif type ==
't0': self.
runT0Workflow(mode,refRun,config,execute)
39 elif type ==
'dbvalidation':
41 if config.dbFiles: inputFiles = config.dbFiles
48 if config.stageOutLocal:
49 from crab_util
import findLastWorkDir
51 crab_task_dir = config.base_dir +
'/' + dirLabel
52 os.chdir(crab_task_dir)
53 crabdir = findLastWorkDir(
'crab_0_')
54 if not crabdir:
raise RuntimeError,
'Could not find CRAB dir in %s' % crab_task_dir
56 dqm_output_dir = crabdir +
"/res"
57 elif config.stageOutCAF:
59 dqm_output_dir = config.castorpath +
'/DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/' + type +
'/' + dirLabel +
'/' +
'v' + str(trial)
65 print "Processing tTrig production"
68 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/TTrigCalibration/' +
'TimeBoxes' +
'/' +
'v' + str(trial)
70 task_dir = config.base_dir +
'/TimeBoxes'
72 dtTtrigProd.writeCfg()
75 project_prod = dtTtrigProd.run()
77 print "Sent calibration jobs with project",project_prod
78 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
81 crabProd.setThreshold(config.jobsFinishedThreshold)
85 result_file = config.result_dir +
'/DTTimeBoxes_%s.root'%run
86 if config.stageOutLocal:
87 output_dir = project_prod +
"/res"
89 elif config.stageOutCAF:
90 castor_dir = config.castorpath +
"/" + config.userdircaf
91 haddInCastor(castor_dir,result_file,
'DTTimeBoxes',
'rfio://castorcms/',
'?svcClass=cmscafuser')
99 print "Processing tTrig correction"
101 dtTtrigWriter.writeCfg()
106 print "Finished processing:"
107 for pset
in dtTtrigWriter.configs:
print "--->",pset
109 def runResidualCalib(self,run,runselection,trial,input_db,label,result_file,config,runStep=True):
111 print "Processing tTrig calibration"
114 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/TTrigCalibration/' + label +
'/' +
'v' + str(trial)
116 task_dir = config.base_dir +
'/' + label
121 dtResidualCalib.writeCfg()
124 project_residualCalib = dtResidualCalib.run()
126 print "Sent calibration jobs with project",project_residualCalib
127 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
130 crabResidualCalib.setThreshold(config.jobsFinishedThreshold)
131 crabResidualCalib.start()
132 crabResidualCalib.join()
134 if config.stageOutLocal:
135 output_dir = project_residualCalib +
"/res"
136 haddLocal(output_dir,result_file,
'residuals')
137 elif config.stageOutCAF:
138 castor_dir = config.castorpath +
"/" + config.userdircaf
139 haddInCastor(castor_dir,result_file,
'residuals',
'rfio://castorcms/',
'?svcClass=cmscafuser')
141 return project_residualCalib
147 print "Processing residuals analysis"
149 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/AnalysisResiduals/' + label +
'/' +
'v' + str(trial)
151 task_dir = config.base_dir +
'/' + label
155 dtAnalysisResiduals.writeCfg()
158 project_analysisResiduals = dtAnalysisResiduals.run()
160 print "Sent jobs with project",project_analysisResiduals
161 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
163 crabAnalysisResiduals =
CrabWatch(project_analysisResiduals)
164 crabAnalysisResiduals.setThreshold(config.jobsFinishedThreshold)
165 crabAnalysisResiduals.start()
166 crabAnalysisResiduals.join()
168 if config.stageOutLocal:
169 output_dir = project_analysisResiduals +
"/res"
170 haddLocal(output_dir,result_file,
'residuals')
171 elif config.stageOutCAF:
172 castor_dir = config.castorpath +
"/" + config.userdircaf
173 haddInCastor(castor_dir,result_file,
'residuals',
'rfio://castorcms/',
'?svcClass=cmscafuser')
175 return project_analysisResiduals
181 print "Processing tTrig residual correction"
186 result_dir=config.result_dir,
188 dtTtrigResidualCorr.writeCfg()
191 dtTtrigResidualCorr.run()
193 print "Finished processing:"
194 for pset
in dtTtrigResidualCorr.configs:
print "--->",pset
196 def runTtrigValid(self,run,runselection,trial,input_db,label,config,runStep=True):
198 print "Processing tTrig validation"
201 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/TTrigValidation/' + label +
'/' +
'v' + str(trial)
203 task_dir = config.base_dir +
'/' + label
208 dtTtrigValid.writeCfg()
211 project_valid = dtTtrigValid.run()
213 print "Sent validation jobs with project",project_valid
214 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
217 crabValid.setThreshold(config.jobsFinishedThreshold)
222 if config.stageOutLocal:
223 output_dir = project_valid + "/res"
224 haddLocal(output_dir,result_file,'residuals')
225 elif config.stageOutCAF:
226 castor_dir = config.castorpath + "/" + config.userdircaf
227 haddInCastor(castor_dir,result_file,'residuals','rfio://castorcms/','?svcClass=cmscafuser')
236 print "Processing Validation Summary"
237 dtTtrigValidSummary =
DTValidSummary(run,config.run_dir,input_file,output_file,config)
238 dtTtrigValidSummary.writeCfg()
241 dtTtrigValidSummary.run()
243 print "...Validation Summary finished"
247 print "Processing vDrift calibration"
250 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/VDriftCalibration/' + label +
'/' +
'v' + str(trial)
252 task_dir = config.base_dir +
'/' + label
256 dtVDriftSegment.writeCfg()
259 project_segment = dtVDriftSegment.run()
261 print "Sent validation jobs with project",project_segment
262 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
265 crabVDriftSegment.setThreshold(config.jobsFinishedThreshold)
266 crabVDriftSegment.start()
267 crabVDriftSegment.join()
269 if config.stageOutLocal:
270 output_dir = project_segment +
"/res"
271 haddLocal(output_dir,result_file,
'DTVDriftHistos')
272 elif config.stageOutCAF:
273 castor_dir = config.castorpath +
"/" + config.userdircaf
274 haddInCastor(castor_dir,result_file,
'DTVDriftHistos',
'rfio://castorcms/',
'?svcClass=cmscafuser')
276 return project_segment
282 print "Processing vDrift writer"
285 input_file=root_file,
286 output_dir=config.result_dir,
288 dtVDriftSegmentWriter.writeCfg()
291 dtVDriftSegmentWriter.run()
293 print "Finished processing:"
294 for pset
in dtVDriftSegmentWriter.configs:
print "--->",pset
298 print "Processing vDrift calibration"
301 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/VDriftCalibration/' + label +
'/' +
'v' + str(trial)
303 task_dir = config.base_dir +
'/' + label
307 dtVDriftMeanTimer.writeCfg()
310 project_meantimer = dtVDriftMeanTimer.run()
312 print "Sent validation jobs with project",project_meantimer
313 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
316 crabVDriftMeanTimer.setThreshold(config.jobsFinishedThreshold)
317 crabVDriftMeanTimer.start()
318 crabVDriftMeanTimer.join()
320 if config.stageOutLocal:
321 output_dir = project_meantimer +
"/res"
322 haddLocal(output_dir,result_file,
'DTTMaxHistos')
323 elif config.stageOutCAF:
324 castor_dir = config.castorpath +
"/" + config.userdircaf
325 haddInCastor(castor_dir,result_file,
'DTTMaxHistos',
'rfio://castorcms/',
'?svcClass=cmscafuser')
327 return project_meantimer
333 print "Processing vDrift writer"
336 input_file=root_file,
337 output_dir=config.result_dir,
339 dtVDriftMeanTimerWriter.writeCfg()
342 dtVDriftMeanTimerWriter.run()
344 print "Finished processing:"
345 for pset
in dtVDriftMeanTimerWriter.configs:
print "--->",pset
349 print "Processing DQM Merge"
353 if config.stageOutLocal:
355 dqm_files = [
'file:%s' % item
for item
in dqm_files]
356 dtDqmFinal =
DTDqm(run,config.run_dir,dqm_files,config.result_dir,config)
357 dtDqmFinal.writeCfg()
359 elif config.stageOutCAF:
361 dqm_files = [file.replace(
'/castor/cern.ch/cms',
'')
for file
in dqm_files]
362 dtDqmFinal =
DTDqm(run,config.run_dir,dqm_files,config.result_dir,config)
363 dtDqmFinal.writeCfg()
366 print "...DQM Merge finished"
369 dtDqmFinal =
DTDqm(run,config.run_dir,dqm_files,config.result_dir,config)
370 dtDqmFinal.writeCfg()
374 print "Processing DQM harvesting"
378 if config.stageOutLocal:
380 dqm_files = [
'file:%s' % item
for item
in dqm_files]
381 dtDqmFinal =
DTDQMHarvesting(run,config.run_dir,dqm_files,config.result_dir,config)
382 dtDqmFinal.writeCfg()
384 elif config.stageOutCAF:
386 dqm_files = [file.replace(
'/castor/cern.ch/cms',
'')
for file
in dqm_files]
387 dtDqmFinal =
DTDQMHarvesting(run,config.run_dir,dqm_files,config.result_dir,config)
388 dtDqmFinal.writeCfg()
391 print "...DQM harvesting finished"
394 dtDqmFinal =
DTDQMHarvesting(run,config.run_dir,dqm_files,config.result_dir,config)
395 dtDqmFinal.writeCfg()
399 print "Processing DQM merge"
403 if config.stageOutLocal:
405 dqm_files = [
'file:%s' % item
for item
in dqm_files]
406 dtDQMMerge =
DTDQMMerge(run,config.run_dir,dqm_files,config.result_dir,config)
407 dtDQMMerge.writeCfg()
409 elif config.stageOutCAF:
411 dqm_files = [file.replace(
'/castor/cern.ch/cms',
'')
for file
in dqm_files]
412 dtDQMMerge =
DTDQMMerge(run,config.run_dir,dqm_files,config.result_dir,config)
413 dtDQMMerge.writeCfg()
416 print "...DQM merge finished"
419 dtDQMMerge =
DTDQMMerge(run,config.run_dir,dqm_files,config.result_dir,config)
420 dtDQMMerge.writeCfg()
427 runselection = config.runselection
428 ttrig_input_db =
None
429 if hasattr(config,
'inputTTrigDB')
and config.inputTTrigDB: ttrig_input_db = os.path.abspath(config.inputTTrigDB)
430 result_dir = config.result_dir
431 if mode ==
'timeboxes':
432 timeBoxes = os.path.abspath(result_dir +
'/' +
'DTTimeBoxes_' + run +
'.root')
433 ttrig_timeboxes_db = os.path.abspath(result_dir +
'/' +
'ttrig_timeboxes_' + run +
'.db')
434 residualsFirst = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_' + run +
'.root')
435 ttrig_residuals_db = os.path.abspath(result_dir +
'/' +
'ttrig_residuals_' + run +
'.db')
436 residualsResidCorr = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_ResidCorr_' + run +
'.root')
437 summaryResiduals = os.path.abspath(result_dir +
'/' +
'SummaryResiduals_' + run +
'.root')
440 print "Writing configuration files.."
443 self.
runResidualCalib(run,runselection,trial,ttrig_timeboxes_db,
'Residuals',residualsFirst,config,
False)
445 self.
runTtrigValid(run,runselection,trial,ttrig_residuals_db,
'ResidualsResidCorr',config,
False)
452 if not os.path.exists(timeBoxes): self.
runTtrigProd(run,runselection,trial,config)
453 if not os.path.exists(timeBoxes):
raise RuntimeError,
'Could not produce %s' % timeBoxes
456 if not os.path.exists(ttrig_timeboxes_db): self.
runTtrigWriter(run,config)
457 if not os.path.exists(ttrig_timeboxes_db):
raise RuntimeError,
'Could not produce %s' % ttrig_timeboxes_db
460 if not os.path.exists(residualsFirst):
461 self.
runResidualCalib(run,runselection,trial,ttrig_timeboxes_db,
'Residuals',residualsFirst,config)
462 if not os.path.exists(residualsFirst):
raise RuntimeError,
'Could not produce %s' % residualsFirst
465 if not os.path.exists(ttrig_residuals_db): self.
runTtrigResidualCorr(run,ttrig_timeboxes_db,residualsFirst,config)
466 if not os.path.exists(ttrig_residuals_db):
raise RuntimeError,
'Could not produce %s' % ttrig_residuals_db
469 self.
runTtrigValid(run,runselection,trial,ttrig_residuals_db,
'ResidualsResidCorr',config)
472 # Summary of validation
473 if not os.path.exists(summaryResiduals): self.runTtrigValidSummary(run,residualsResidCorr,summaryResiduals,config)
474 if not os.path.exists(summaryResiduals): raise RuntimeError,'Could not produce %s' % summaryResiduals
477 dqm_output_dir = self.
dqmOutputDir(
'TTrigValidation',
'ResidualsResidCorr',config)
480 elif mode ==
'residuals':
481 residualsFirst = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_' + run +
'.root')
482 ttrig_residuals_db = os.path.abspath(result_dir +
'/' +
'ttrig_residuals_' + run +
'.db')
483 residualsResidCorr = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_ResidCorr_' + run +
'.root')
484 summaryResiduals = os.path.abspath(result_dir +
'/' +
'SummaryResiduals_' + run +
'.root')
487 print "Writing configuration files.."
489 self.
runResidualCalib(run,runselection,trial,ttrig_input_db,
'Residuals',residualsFirst,config,
False)
492 self.
runResidualCalib(run,runselection,trial,
None,
'Residuals',residualsFirst,config,
False)
495 self.
runTtrigValid(run,runselection,trial,ttrig_residuals_db,
'ResidualsResidCorr',config,
False)
503 if not os.path.exists(residualsFirst):
505 self.
runResidualCalib(run,runselection,trial,ttrig_input_db,
'Residuals',residualsFirst,config)
507 self.
runResidualCalib(run,runselection,trial,
None,
'Residuals',residualsFirst,config)
508 if not os.path.exists(residualsFirst):
raise RuntimeError,
'Could not produce %s' % residualsFirst
511 if not os.path.exists(ttrig_residuals_db):
514 if not os.path.exists(ttrig_residuals_db):
raise RuntimeError,
'Could not produce %s' % ttrig_residuals_db
517 self.
runTtrigValid(run,runselection,trial,ttrig_residuals_db,
'ResidualsResidCorr',config)
520 # Summary of validation
521 if not os.path.exists(summaryResiduals):
522 self.runTtrigValidSummary(run,residualsResidCorr,summaryResiduals,config)
523 if not os.path.exists(summaryResiduals): raise RuntimeError,'Could not produce %s' % summaryResiduals
526 dqm_output_dir = self.
dqmOutputDir(
'TTrigValidation',
'ResidualsResidCorr',config)
529 elif mode ==
'validation':
530 residualsValid = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_' + run +
'.root')
531 summaryResiduals = os.path.abspath(result_dir +
'/' +
'SummaryResiduals_' + run +
'.root')
534 print "Writing configuration files.."
536 self.
runTtrigValid(run,runselection,trial,ttrig_input_db,
'Residuals',config,
False)
538 self.
runTtrigValid(run,runselection,trial,
None,
'Residuals',config,
False)
547 self.
runTtrigValid(run,runselection,trial,ttrig_input_db,
'Residuals',config)
549 self.
runTtrigValid(run,runselection,trial,
None,
'Residuals',config)
552 # Summary of validation
553 if not os.path.exists(summaryResiduals):
554 self.runTtrigValidSummary(run,residualsValid,summaryResiduals,config)
555 if not os.path.exists(summaryResiduals): raise RuntimeError,'Could not produce %s' % summaryResiduals
559 dqm_output_dir = self.
dqmOutputDir(
'TTrigValidation',
'Residuals',config)
569 runselection = config.runselection
570 result_dir = config.result_dir
571 if mode ==
'segment':
572 vDriftHistos = os.path.abspath(result_dir +
'/' +
'DTVDriftHistos_' + run +
'.root')
573 vDrift_segment_db = os.path.abspath(result_dir +
'/' +
'vDrift_segment_' + run +
'.db')
576 print "Writing configuration files.."
583 if not os.path.exists(vDriftHistos):
585 if not os.path.exists(vDriftHistos):
raise RuntimeError,
'Could not produce %s' % vDriftHistos
589 if not os.path.exists(vDrift_segment_db):
raise RuntimeError,
'Could not produce %s' % vDrift_segment_db
591 elif mode ==
'meantimer':
592 vDriftTMaxHistos = os.path.abspath(result_dir +
'/' +
'DTTMaxHistos_' + run +
'.root')
593 vDrift_meantimer_db = os.path.abspath(result_dir +
'/' +
'vDrift_meantimer_' + run +
'.db')
596 print "Writing configuration files.."
603 if not os.path.exists(vDriftTMaxHistos):
605 if not os.path.exists(vDriftTMaxHistos):
raise RuntimeError,
'Could not produce %s' % vDriftTMaxHistos
609 if not os.path.exists(vDrift_meantimer_db):
raise RuntimeError,
'Could not produce %s' % vDrift_meantimer_db
617 print "Processing noise calibration"
620 runselection = config.runselection
621 result_dir = config.result_dir
622 result_file = os.path.abspath(result_dir +
'/' +
'dtNoiseCalib_' + run +
'.root')
623 noise_db = os.path.abspath(result_dir +
'/' +
'noise_' + run +
'.db')
624 noise_txt = os.path.abspath(result_dir +
'/' +
'noise_' + run +
'.txt')
628 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/NoiseCalibration/' +
'v' + str(trial)
630 task_dir = config.base_dir +
'/NoiseCalib'
635 dtNoiseCalibration.writeCfg()
638 dtNoiseCalibration.writeCfg()
639 project_noise = dtNoiseCalibration.run()
641 print "Sent calibration jobs with project",project_noise
642 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
645 crabNoiseCalibration.setThreshold(config.jobsFinishedThreshold)
646 crabNoiseCalibration.start()
647 crabNoiseCalibration.join()
649 if config.stageOutLocal:
650 crab_output_dir = project_noise +
"/res"
653 elif config.stageOutCAF:
654 castor_dir = config.castorpath +
"/" + config.userdircaf
671 print "Processing DQM validation"
673 runselection = config.runselection
674 result_dir = config.result_dir
677 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/DQMValidation/' + dirLabel +
'/' +
'v' + str(trial)
679 task_dir = config.base_dir +
'/' + dirLabel
684 dtDQMValid.writeCfg()
690 dtDQMValid.writeCfg()
691 project_valid = dtDQMValid.run()
693 print "Sent validation jobs with project",project_valid
694 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
697 crabValid.setThreshold(config.jobsFinishedThreshold)
702 dqm_output_dir = self.
dqmOutputDir(
'DQMValidation',dirLabel,config)
705 dqm_merge_dir = os.path.abspath(result_dir)
714 print "Processing analysis workflow"
716 runselection = config.runselection
717 result_dir = config.result_dir
718 if mode ==
'residuals':
719 residualsFile = os.path.abspath(result_dir +
'/' +
'DTResiduals_' + run +
'.root')
722 print "Writing configuration files.."
728 if not os.path.exists(residualsFile):
730 if not os.path.exists(residualsFile):
raise RuntimeError,
'Could not produce %s' % residualsFile
738 print "Processing DB validation"
740 dtDBValidation =
None
744 input_files=inputFiles,
745 output_dir=config.result_dir,
752 print "Finished processing:"
753 for pset
in dtDBValidation.configs:
print "--->",pset
def runDBValidationWorkflow
DB Validation workflow.
def runVDriftSegmentWriter
def runAnalysisWorkflow
Analysis workflow.
def runNoiseWorkflow
noise workflow
def runVDriftMeanTimerCalib
def runVDriftWorkflow
vDrift workflow
def runTtrigWorkflow
tTrig workflow
def runT0Workflow
t0 workflow
def runValidationWorkflow
Validation workflow.
def runVDriftMeanTimerWriter
def runVDriftSegmentCalib