ATLAS Offline Software
Functions
top-el.cxx File Reference
#include "TFile.h"
#include "TTree.h"
#include "AnaAlgorithm/AnaAlgorithmConfig.h"
#include "AsgMessaging/MessageCheck.h"
#include "EventLoop/DirectDriver.h"
#include "EventLoop/Job.h"
#include "EventLoop/OutputStream.h"
#include "SampleHandler/SampleHandler.h"
#include "SampleHandler/SampleLocal.h"
#include "TopAnalysis/Tools.h"
#include "TopConfiguration/ConfigurationSettings.h"
#include "TopConfiguration/TopConfig.h"
#include "TopEvent/EventTools.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODRootAccess/tools/TFileAccessTracer.h"
#include "PathResolver/PathResolver.h"
#include "TopAnalysis/MsgCategory.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 31 of file top-el.cxx.

31  {
32 
33  // set appropriate msg level
34  setMsgLevel(MSG::Level::INFO);
35 
36  if (argc != 4) {
37  ATH_MSG_INFO("Code to perform object and event selection and write-out\n"
38  << "a few histograms and / or a tree in xAOD format.\n"
39  << "Use like:\n"
40  << " " << argv[0] << " cuts.txt input.txt\n"
41  << " cuts.txt - file containing cuts\n"
42  << " input.txt - file containing list of input files\n"
43  << " submitdir - path for EventLoop submit directory\n"
44  << "\n"
45  << "For example\n"
46  << " " << argv[0]
47  << " $ROOTCOREBIN/data/TopAnalysis/nocuts.txt "
48  "$ROOTCOREBIN/data/TopAnalysis/input-13TeV-fondueworld.txt output\n");
49  return 1;
50  }
51  gErrorAbortLevel = kError;
52 
53  // to disable the sending of file access statistics
55 
56  // magic xAOD stuff
57  // true = fail at even the slightest xaod issue
58  top::xAODInit(true);
59  StatusCode::enableFailure();
60  ANA_CHECK_SET_TYPE(int);
61 
62  EL::AnaAlgorithmConfig algConfig("top::TopxAODAlg/TopxAODAlg");
63 
64  ATH_MSG_INFO("INPUT: Configuration file (argv[1]) = " << argv[1] << "\n");
65  std::string settingsFilename =
67 
68  ATH_MSG_INFO("LOCATED (using PathResolverFindFile ): Configuration file = " << settingsFilename
69  << "\n");
70  ANA_CHECK(algConfig.setProperty("ConfigPath", settingsFilename));
71 
72  ATH_MSG_INFO("Configuration Files:\n" << settingsFilename << "\n" << argv[2] << "\n");
73 
74  // load the settings from the input file
76  settings->loadFromFile(settingsFilename);
77  ATH_MSG_INFO("Configuration:\n" << *settings << "\n");
78 
79  // only after printing full configuration check if there are issues and inform
80  // user and crash if necessary
81  settings->checkSettings();
82 
83  const std::string libraryNames = settings->value("LibraryNames");
84  top::loadLibraries(libraryNames);
85  ANA_CHECK(algConfig.setProperty("LibraryNames", libraryNames));
86 
87  // A configuration that John can easily understand
88  // This is not the same as a good configuration
89  std::shared_ptr<top::TopConfig> topConfig(new top::TopConfig());
90 
91  // open the files (to check they exist) and count how many events we have
92  std::vector<std::string> filenames = top::fileList(std::string(argv[2]));
93 
95  // METADATA READING (SOMETHING THAT SHOULD NOT BE DONE HERE)
97 
98  // picking the first file was a bad idea because in the derivations it often
99  // has no events (no CollectionTree). Be sure to pick a file with events in
100  // it -- this is needed to determine the year to setup triggers
101  // FIXME -- can we have this in MetaData without having to open CollectionTree
102  // ?
103  {
104  std::string usethisfile = filenames[0];
105  for (const auto &filename : filenames) {
106  std::unique_ptr<TFile> checkingYieldFile(TFile::Open(filename.c_str()));
107 
108  // collection tree means > 0 events
109  const TTree *const collectionTree =
110  dynamic_cast<TTree *>(checkingYieldFile->Get("CollectionTree"));
111  if (collectionTree) {
112  usethisfile = filename;
113  break;
114  }
115  }
116 
117  // read FileMetaData using AsgMetadataTool
118  std::unique_ptr<TFile> testFile(TFile::Open(usethisfile.c_str()));
119  if (!top::readMetaData(testFile.get(), topConfig)) {
120  ATH_MSG_ERROR("Unable to access FileMetaData in this file : "
121  << usethisfile << "\nPlease report this message.");
122  return 1;
123  }
124 
125  // Pass the settings file to the TopConfig
126  topConfig->setConfigSettings(settings);
127 
128  if (topConfig->isMC() && !topConfig->isTruthDxAOD()) {
129  // now need to get and set the parton shower generator from TopDataPrep
130  SampleXsection tdp;
131  // Package/filename - XS file we want to use (can now be configured via
132  // cutfile)
133  const std::string tdp_filename = settings->value("TDPPath");
134  // Use the path resolver to find the first file in the list of possible
135  // paths ($CALIBPATH)
136  const std::string fullpath = PathResolverFindCalibFile(tdp_filename);
137  if (!tdp.readFromFile(fullpath.c_str())) {
138  ATH_MSG_ERROR("TopDataPreparation - could not read file\n" << tdp_filename);
139  return 1;
140  }
141  ATH_MSG_INFO("SampleXsection::Found " << fullpath);
142 
143  tdp.setTranslator(topConfig->GetMCMCTranslator());
144 
145  int ShowerIndex = tdp.getShoweringIndex(topConfig->getDSID());
146  ATH_MSG_INFO("DSID: " << topConfig->getDSID() << "\t"
147  << "ShowerIndex: " << ShowerIndex
148  << " PS generator: " << tdp.getShoweringString(topConfig->getDSID()));
149  topConfig->setMapIndex(ShowerIndex);
150  topConfig->setShoweringAlgorithm(tdp.getShowering(topConfig->getDSID()));
151  ANA_CHECK(algConfig.setProperty("FTAGMapIndex", ShowerIndex));
152  ANA_CHECK(algConfig.setProperty("ShoweringAlgorithm", topConfig->getShoweringAlgorithm()));
153  }
154  // check year
155  // TODO Replace this with different functionality, that does not need opening a file
156  {
158  top::check(xaodEvent.readFrom(testFile.get()), "Failed to read file in");
159  const unsigned int entries = xaodEvent.getEntries();
160  if (entries > 0) {
161  xaodEvent.getEntry(0);
162  const xAOD::EventInfo *eventInfo(nullptr);
163  top::check(xaodEvent.retrieve(eventInfo, topConfig->sgKeyEventInfo()),
164  "Failed to retrieve EventInfo");
165  const unsigned int runnumber = eventInfo->runNumber();
166  const std::string thisYear = topConfig->getYear(runnumber, topConfig->isMC());
167  topConfig->SetYear(thisYear);
168  } else {
169  topConfig->SetYear("UNKNOWN");
170  }
171  topConfig->SetTriggersToYear(topConfig->isMC());
172 
173  ANA_CHECK(algConfig.setProperty("DataTakingYear", topConfig->getYear()));
174  }
175 
176  } // close and delete the ptr to testFile
177 
178  EL::Job job;
179 
181  auto sample = std::make_unique<SH::SampleLocal>("sample");
182  for (const auto &file : filenames)
183  sample->add(file);
184  sh.add(sample.release());
185  job.sampleHandler(sh);
186  job.options()->setDouble(EL::Job::optMaxEvents, topConfig->numberOfEventsToRun());
187  job.options()->setDouble(EL::Job::optSkipEvents, topConfig->numberOfEventsToSkip());
188  job.options()->setString(EL::Job::optSubmitDirMode, "unique-link");
189 
190  EL::OutputStream output("output");
191  job.outputAdd(output);
192  ANA_CHECK(algConfig.setProperty("StreamName", "output"));
193 
194  job.algsAdd(algConfig);
195 
197  driver.submit(job, argv[3]);
198 
199  return 0;
200 }
EL::Job::optMaxEvents
static const std::string optMaxEvents
description: the name of the option used for setting the maximum number of events to process per samp...
Definition: Job.h:222
top::ConfigurationSettings::value
const std::string & value(const std::string &key) const
The user wants to know the value for the specified key.
Definition: ConfigurationSettings.cxx:970
top::loadLibraries
void loadLibraries(const std::string &libraryNames)
So that we can load external libraries with (1) extra event selection tools in, (2) user defined obje...
Definition: Tools.cxx:275
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
EL::OutputStream
Definition: OutputStream.h:34
xAOD::TFileAccessTracer::enableDataSubmission
static void enableDataSubmission(::Bool_t value)
Function for turning data submission on/off.
Definition: TFileAccessTracer.cxx:281
top::ConfigurationSettings::checkSettings
void checkSettings()
Validate that configured options make sense.
Definition: ConfigurationSettings.cxx:942
top::ConfigurationSettings::loadFromFile
void loadFromFile(const std::string &filename)
Read the settings from a text file given by.
Definition: ConfigurationSettings.cxx:723
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
top::readMetaData
bool readMetaData(TFile *inputFile, const std::shared_ptr< top::TopConfig > &config)
This function will be used to load the metadata object and pull information from it.
Definition: Tools.cxx:331
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
EL::AnaAlgorithmConfig
an object that can create a AnaAlgorithm
Definition: AnaAlgorithmConfig.h:29
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
top::TopConfig
Definition: TopConfig.h:41
FullCPAlgorithmsTest_eljob.driver
driver
Definition: FullCPAlgorithmsTest_eljob.py:157
top::fileList
std::vector< std::string > fileList(const std::string &filename)
Given a filename for a text file, parse it and extract a list of root files.
Definition: Tools.cxx:239
PathResolver::LocalSearch
@ LocalSearch
Definition: PathResolver.h:27
SampleXsection
Definition: SampleXsection.h:19
SampleXsection::setTranslator
void setTranslator(const std::unordered_map< std::string, std::string > &map)
Definition: SampleXsection.h:57
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FullCPAlgorithmsTest_eljob.sh
sh
Definition: FullCPAlgorithmsTest_eljob.py:98
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
SampleXsection::readFromFile
bool readFromFile(const char *fName)
Definition: SampleXsection.cxx:23
SampleXsection::getShoweringString
std::string getShoweringString(const int dsid) const
Definition: SampleXsection.cxx:145
Analysis::kError
@ kError
Definition: CalibrationDataVariables.h:60
RCU::Shell
Definition: ShellExec.cxx:28
top::ConfigurationSettings::get
static ConfigurationSettings * get(bool reset=false)
Design patterns 101.
Definition: ConfigurationSettings.cxx:714
top::xAODInit
void xAODInit(bool failOnUnchecked)
A little wrapper for the xAOD tools.
Definition: Tools.cxx:46
file
TFile * file
Definition: tile_monitor.h:29
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
SampleXsection::getShowering
showering getShowering(const int dsid) const
Definition: SampleXsection.cxx:131
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DeMoScan.runnumber
runnumber
Definition: DeMoScan.py:266
merge.output
output
Definition: merge.py:17
EL::DirectDriver
a Driver that runs directly inside the submission job itself
Definition: DirectDriver.h:25
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
grepfile.filenames
list filenames
Definition: grepfile.py:34
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:16
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
entries
double entries
Definition: listroot.cxx:49
SH::SampleHandler
A class that manages a list of Sample objects.
Definition: SampleHandler.h:60
EL::Job::optSubmitDirMode
static const std::string optSubmitDirMode
the submit-dir mode (allowed values: "no-clobber", "overwrite", "unique", "unique-link")
Definition: Job.h:195
EL::Job::optSkipEvents
static const std::string optSkipEvents
description: the name of the option used for skipping a certain number of events in the beginning rat...
Definition: Job.h:230
CscCalibQuery.testFile
testFile
Definition: CscCalibQuery.py:274
SampleXsection::getShoweringIndex
int getShoweringIndex(const int dsid) const
Definition: SampleXsection.cxx:150
EL::Job
Definition: Job.h:51
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
top::ConfigurationSettings
Hold the configuration information for the whole run.
Definition: ConfigurationSettings.h:21
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
beamspotman.fullpath
string fullpath
Definition: beamspotman.py:1039