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)
502 if not os.path.exists(residualsFirst):
504 self.
runResidualCalib(run,runselection,trial,ttrig_input_db,
'Residuals',residualsFirst,config)
506 self.
runResidualCalib(run,runselection,trial,
None,
'Residuals',residualsFirst,config)
507 if not os.path.exists(residualsFirst):
raise RuntimeError,
'Could not produce %s' % residualsFirst
510 if not os.path.exists(ttrig_residuals_db):
513 if not os.path.exists(ttrig_residuals_db):
raise RuntimeError,
'Could not produce %s' % ttrig_residuals_db
516 self.
runTtrigValid(run,runselection,trial,ttrig_residuals_db,
'ResidualsResidCorr',config)
519 # Summary of validation
520 if not os.path.exists(summaryResiduals):
521 self.runTtrigValidSummary(run,residualsResidCorr,summaryResiduals,config)
522 if not os.path.exists(summaryResiduals): raise RuntimeError,'Could not produce %s' % summaryResiduals
525 dqm_output_dir = self.
dqmOutputDir(
'TTrigValidation',
'ResidualsResidCorr',config)
528 elif mode ==
'validation':
529 residualsValid = os.path.abspath(result_dir +
'/' +
'DTResidualValidation_' + run +
'.root')
530 summaryResiduals = os.path.abspath(result_dir +
'/' +
'SummaryResiduals_' + run +
'.root')
533 print "Writing configuration files.."
535 self.
runTtrigValid(run,runselection,trial,ttrig_input_db,
'Residuals',config,
False)
537 self.
runTtrigValid(run,runselection,trial,
None,
'Residuals',config,
False)
546 self.
runTtrigValid(run,runselection,trial,ttrig_input_db,
'Residuals',config)
548 self.
runTtrigValid(run,runselection,trial,
None,
'Residuals',config)
551 # Summary of validation
552 if not os.path.exists(summaryResiduals):
553 self.runTtrigValidSummary(run,residualsValid,summaryResiduals,config)
554 if not os.path.exists(summaryResiduals): raise RuntimeError,'Could not produce %s' % summaryResiduals
558 dqm_output_dir = self.
dqmOutputDir(
'TTrigValidation',
'Residuals',config)
568 runselection = config.runselection
569 result_dir = config.result_dir
570 if mode ==
'segment':
571 vDriftHistos = os.path.abspath(result_dir +
'/' +
'DTVDriftHistos_' + run +
'.root')
572 vDrift_segment_db = os.path.abspath(result_dir +
'/' +
'vDrift_segment_' + run +
'.db')
575 print "Writing configuration files.."
582 if not os.path.exists(vDriftHistos):
584 if not os.path.exists(vDriftHistos):
raise RuntimeError,
'Could not produce %s' % vDriftHistos
588 if not os.path.exists(vDrift_segment_db):
raise RuntimeError,
'Could not produce %s' % vDrift_segment_db
590 elif mode ==
'meantimer':
591 vDriftTMaxHistos = os.path.abspath(result_dir +
'/' +
'DTTMaxHistos_' + run +
'.root')
592 vDrift_meantimer_db = os.path.abspath(result_dir +
'/' +
'vDrift_meantimer_' + run +
'.db')
595 print "Writing configuration files.."
602 if not os.path.exists(vDriftTMaxHistos):
604 if not os.path.exists(vDriftTMaxHistos):
raise RuntimeError,
'Could not produce %s' % vDriftTMaxHistos
608 if not os.path.exists(vDrift_meantimer_db):
raise RuntimeError,
'Could not produce %s' % vDrift_meantimer_db
616 print "Processing noise calibration"
619 runselection = config.runselection
620 result_dir = config.result_dir
621 result_file = os.path.abspath(result_dir +
'/' +
'dtNoiseCalib_' + run +
'.root')
622 noise_db = os.path.abspath(result_dir +
'/' +
'noise_' + run +
'.db')
623 noise_txt = os.path.abspath(result_dir +
'/' +
'noise_' + run +
'.txt')
627 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/NoiseCalibration/' +
'v' + str(trial)
629 task_dir = config.base_dir +
'/NoiseCalib'
634 dtNoiseCalibration.writeCfg()
637 dtNoiseCalibration.writeCfg()
638 project_noise = dtNoiseCalibration.run()
640 print "Sent calibration jobs with project",project_noise
641 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
644 crabNoiseCalibration.setThreshold(config.jobsFinishedThreshold)
645 crabNoiseCalibration.start()
646 crabNoiseCalibration.join()
648 if config.stageOutLocal:
649 crab_output_dir = project_noise +
"/res"
652 elif config.stageOutCAF:
653 castor_dir = config.castorpath +
"/" + config.userdircaf
670 print "Processing DQM validation"
672 runselection = config.runselection
673 result_dir = config.result_dir
676 config.userdircaf =
'DTCalibration/' + datasetstr +
'/Run' + str(run) +
'/DQMValidation/' + dirLabel +
'/' +
'v' + str(trial)
678 task_dir = config.base_dir +
'/' + dirLabel
683 dtDQMValid.writeCfg()
689 dtDQMValid.writeCfg()
690 project_valid = dtDQMValid.run()
692 print "Sent validation jobs with project",project_valid
693 print "%.0f%% of jobs are required to finish" % config.jobsFinishedThreshold
696 crabValid.setThreshold(config.jobsFinishedThreshold)
701 dqm_output_dir = self.
dqmOutputDir(
'DQMValidation',dirLabel,config)
704 dqm_merge_dir = os.path.abspath(result_dir)
713 print "Processing analysis workflow"
715 runselection = config.runselection
716 result_dir = config.result_dir
717 if mode ==
'residuals':
718 residualsFile = os.path.abspath(result_dir +
'/' +
'DTResiduals_' + run +
'.root')
721 print "Writing configuration files.."
727 if not os.path.exists(residualsFile):
729 if not os.path.exists(residualsFile):
raise RuntimeError,
'Could not produce %s' % residualsFile
737 print "Processing DB validation"
739 dtDBValidation =
None
743 input_files=inputFiles,
744 output_dir=config.result_dir,
751 print "Finished processing:"
752 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