ATLAS Offline Software
MuonAnalysisAlgorithmsConfigTest_eljob.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 # @author Nils Krumnack
6 
7 
8 # Read the submission directory as a command line argument. You can
9 # extend the list of arguments with your private ones later on.
10 import optparse
11 parser = optparse.OptionParser()
12 parser.add_option( '-d', '--data-type', dest = 'data_type',
13  action = 'store', type = 'string', default = 'data',
14  help = 'Type of data to run over. Valid options are data, mc, afii' )
15 parser.add_option( '-s', '--submission-dir', dest = 'submission_dir',
16  action = 'store', type = 'string', default = 'submitDir',
17  help = 'Submission directory for EventLoop' )
18 parser.add_option( '-u', '--unit-test', dest='unit_test',
19  action = 'store_true', default = False,
20  help = 'Run the job in "unit test mode"' )
21 ( options, args ) = parser.parse_args()
22 
23 # Set up (Py)ROOT.
24 import ROOT
25 ROOT.xAOD.Init().ignore()
26 
27 # Force-load some xAOD dictionaries. To avoid issues from ROOT-10940.
28 ROOT.xAOD.TauJetContainer()
29 
30 # ideally we'd run over all of them, but we don't have a mechanism to
31 # configure per-sample right now
32 
33 dataType = options.data_type
34 
35 if dataType not in ["data", "mc", "afii"] :
36  raise Exception ("invalid data type: " + dataType)
37 
38 # Set up the sample handler object. See comments from the C++ macro
39 # for the details about these lines.
40 import os
41 sh = ROOT.SH.SampleHandler()
42 sh.setMetaString( 'nc_tree', 'CollectionTree' )
43 sample = ROOT.SH.SampleLocal (dataType)
44 if dataType == "data" :
45  sample.add (os.getenv ('ASG_TEST_FILE_DATA'))
46  pass
47 if dataType == "mc" :
48  sample.add (os.getenv ('ASG_TEST_FILE_MC'))
49  pass
50 if dataType == "afii" :
51  sample.add (os.getenv ('ASG_TEST_FILE_MC_AFII'))
52  pass
53 sh.add (sample)
54 sh.printContent()
55 
56 # Create an EventLoop job.
57 job = ROOT.EL.Job()
58 job.sampleHandler( sh )
59 job.options().setDouble( ROOT.EL.Job.optMaxEvents, 500 )
60 
61 
62 from MuonAnalysisAlgorithms.MuonAnalysisConfigTest import makeSequence
63 algSeq = makeSequence (dataType)
64 print( algSeq ) # For debugging
65 algSeq.addSelfToJob( job )
66 
67 # Make sure that both the ntuple and the xAOD dumper have a stream to write to.
68 job.outputAdd( ROOT.EL.OutputStream( 'ANALYSIS' ) )
69 
70 # Find the right output directory:
71 submitDir = options.submission_dir
72 if options.unit_test:
73  import os
74  import tempfile
75  submitDir = tempfile.mkdtemp( prefix = 'muonTest_'+dataType+'_', dir = os.getcwd() )
76  os.rmdir( submitDir )
77  pass
78 
79 # Run the job using the local driver. This is intentionally the local
80 # driver, unlike most other tests that use the direct driver. That
81 # way it tests whether the code works correctly with that driver,
82 # which is a lot more similar to the way the batch/grid drivers work.
83 driver = ROOT.EL.LocalDriver()
84 driver.submit( job, submitDir )
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70