17 #include "Compression.h"
19 #include "TObjString.h"
49 #include "oneapi/tbb/task_arena.h"
84 tree.Branch(
"run", &
m_run,
"run/i");
86 tree.Branch(
"event", &
m_event,
"event/l");
103 tree.Branch(
"run", &
m_run,
"run/i");
151 edm::
one::OutputModule<>(pset),
152 m_fileName(pset.getUntrackedParameter<std::
string>(
"fileName")),
153 m_logicalFileName(pset.getUntrackedParameter<std::
string>(
"logicalFileName")),
154 m_compressionLevel(pset.getUntrackedParameter<int>(
"compressionLevel")),
155 m_compressionAlgorithm(pset.getUntrackedParameter<std::
string>(
"compressionAlgorithm")),
156 m_writeProvenance(pset.getUntrackedParameter<bool>(
"saveProvenance",
true)),
157 m_fakeName(pset.getUntrackedParameter<bool>(
"fakeNameForCrab",
false)),
158 m_autoFlush(pset.getUntrackedParameter<int>(
"autoFlush", -10000000)),
159 m_processHistoryRegistry() {}
177 maxMemory =
static_cast<float>(
m_tree->GetTotBytes()) / percentClusterDone;
178 }
else if (
m_tree->GetZipBytes() == 0) {
179 maxMemory = 100 * 1024 * 1024;
182 float cxnRatio =
m_tree->GetTotBytes() /
static_cast<float>(
m_tree->GetZipBytes());
184 float percentBytesDone = -
m_tree->GetZipBytes() /
static_cast<float>(
m_autoFlush);
192 m_tree->OptimizeBaskets(static_cast<uint32_t>(maxMemory), 1,
"");
203 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
205 t.fill(iEvent, *
m_tree, extensions);
208 std::vector<std::string> pnames;
210 pnames.push_back(
p.processName());
213 (
std::find(pnames.begin(), pnames.end(),
b.processName()) - pnames.begin()));
223 tbb::this_task_arena::isolate([&] {
m_tree->Fill(); });
237 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
242 tbb::this_task_arena::isolate([&] {
m_lumiTree->Fill(); });
256 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
264 TObjString* tos =
dynamic_cast<TObjString*
>(
m_file->Get(
p.first.c_str()));
266 if (hstring->str() != tos->GetString())
267 throw cms::Exception(
"LogicError",
"Inconsistent nanoMetadata " +
p.first +
" (" + hstring->str() +
")");
269 auto ostr = std::make_unique<TObjString>(hstring->str().c_str());
270 m_file->WriteTObject(ostr.release(),
p.first.c_str());
274 tbb::this_task_arena::isolate([&] {
m_runTree->Fill(); });
288 m_fakeName ?
"PoolOutputModule" :
"NanoAODOutputModule",
293 std::vector<std::string>());
296 m_file->SetCompressionAlgorithm(ROOT::kZLIB);
298 m_file->SetCompressionAlgorithm(ROOT::kLZMA);
301 <<
"NanoAODOutputModule configured with unknown compression algorithm '" <<
m_compressionAlgorithm <<
"'\n"
302 <<
"Allowed compression algorithms are ZLIB and LZMA\n";
315 if (
keep.first->className() ==
"nanoaod::FlatTable")
317 else if (
keep.first->className() ==
"edm::TriggerResults") {
319 }
else if (
keep.first->className() ==
"std::basic_string<char,std::char_traits<char> >" &&
320 keep.first->productInstanceName() ==
"genModel") {
323 throw cms::Exception(
"Configuration",
"NanoAODOutputModule cannot handle class " +
keep.first->className());
327 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
329 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
331 else if (
keep.first->className() ==
"nanoaod::FlatTable")
336 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in LuminosityBlock branch");
340 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
342 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
344 else if (
keep.first->className() ==
"nanoaod::FlatTable")
348 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in Run branch");
352 m_tree = std::make_unique<TTree>(
"Events",
"Events");
357 m_lumiTree = std::make_unique<TTree>(
"LuminosityBlocks",
"LuminosityBlocks");
361 m_runTree = std::make_unique<TTree>(
"Runs",
"Runs");
374 int basketSize = 16384;
402 desc.
addUntracked<
int>(
"compressionLevel", 9)->setComment(
"ROOT compression level of output file.");
404 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
406 ->setComment(
"Save process provenance information, e.g. for edmProvDump");
409 "Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran "
410 "(and publish) till crab is fixed");
411 desc.
addUntracked<
int>(
"autoFlush", -10000000)->setComment(
"Autoflush parameter for ROOT file");
414 const std::vector<std::string>
keep = {
"drop *",
415 "keep nanoaodFlatTable_*Table_*_*",
416 "keep edmTriggerResults_*_*_*",
417 "keep String_*_genModel_*",
418 "keep nanoaodMergeableCounterTable_*Table_*_*",
419 "keep nanoaodUniqueString_nanoMetadata_*_*"};
426 ->setComment(
"PSet is only used by Data Operations and not by this module.");
std::unique_ptr< TTree > m_runTree
EventNumber_t event() const
std::vector< TableOutputBranches > m_runFlatTables
std::string processName()
std::unique_ptr< TTree > m_lumiTree
EventID const & id() const
std::vector< SummaryTableOutputBranches > m_lumiTables
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::unique_ptr< TTree > m_tree
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
void fillParameterSetBranch(TTree *parameterSetsTree, int basketSize)
bool registerProcessHistory(ProcessHistory const &processHistory)
void fillProcessHistoryBranch(TTree *metaDataTree, int basketSize, ProcessHistoryRegistry const &processHistoryRegistry)
NanoAODOutputModule(edm::ParameterSet const &pset)
bool isFileOpen() const override
void fill(const edm::LuminosityBlockID &id)
void reportRunNumber(JobReport::Token token, unsigned int run)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string const & parameterSetsTreeName()
std::unique_ptr< TTree > m_parameterSetsTree
void writeRun(edm::RunForOutput const &) override
class NanoAODOutputModule::CommonLumiBranches m_commonLumiBranches
std::unique_ptr< TTree > m_metaDataTree
std::unique_ptr< TFile > m_file
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual ProcessHistory const & processHistory() const
std::vector< EventStringOutputBranches > m_evstrings
void fill(const edm::RunID &id)
ModuleDescription const & description() const
std::vector< SummaryTableOutputBranches > m_runTables
std::vector< TableOutputBranches > m_tables
static constexpr int m_firstFlush
std::vector< TriggerOutputBranches > m_triggers
std::vector< std::pair< std::string, edm::EDGetToken > > m_nanoMetadata
std::string const & metaDataTreeName()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool m_triggers_areSorted
std::vector< LumiOutputBranches > m_lumiTables2
void openFile(edm::FileBlock const &) override
std::string createGlobalIdentifier(bool binary=false)
void reallyCloseFile() override
void fill(const edm::EventID &id)
std::string m_logicalFileName
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
std::string toString() const
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
void outputFileClosed(Token fileToken)
void write(edm::EventForOutput const &e) override
class NanoAODOutputModule::CommonRunBranches m_commonRunBranches
SelectedProductsForBranchType const & keptProducts() const
~NanoAODOutputModule() override
edm::JobReport::Token m_jrToken
class NanoAODOutputModule::CommonEventBranches m_commonBranches
edm::ProcessHistoryRegistry m_processHistoryRegistry
LuminosityBlockID const & id() const
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
std::string m_compressionAlgorithm
void reportLumiSection(JobReport::Token token, unsigned int run, unsigned int lumiSectId, unsigned long nEvents=0)
void writeLuminosityBlock(edm::LuminosityBlockForOutput const &) override