19 #include "TObjString.h" 49 #include "oneapi/tbb/task_arena.h" 158 m_fileName(
pset.getUntrackedParameter<
std::
string>(
"fileName")),
159 m_logicalFileName(
pset.getUntrackedParameter<
std::
string>(
"logicalFileName")),
160 m_compressionLevel(
pset.getUntrackedParameter<
int>(
"compressionLevel")),
161 m_compressionAlgorithm(
pset.getUntrackedParameter<
std::
string>(
"compressionAlgorithm")),
162 m_writeProvenance(
pset.getUntrackedParameter<
bool>(
"saveProvenance",
true)),
163 m_fakeName(
pset.getUntrackedParameter<
bool>(
"fakeNameForCrab",
false)),
164 m_autoFlush(
pset.getUntrackedParameter<
int>(
"autoFlush", -10000000)),
165 m_processHistoryRegistry() {}
183 maxMemory =
static_cast<float>(
m_tree->GetTotBytes()) / percentClusterDone;
184 }
else if (
m_tree->GetZipBytes() == 0) {
185 maxMemory = 100 * 1024 * 1024;
188 float cxnRatio =
m_tree->GetTotBytes() /
static_cast<float>(
m_tree->GetZipBytes());
190 float percentBytesDone = -
m_tree->GetZipBytes() /
static_cast<float>(
m_autoFlush);
198 m_tree->OptimizeBaskets(static_cast<uint32_t>(maxMemory), 1,
"");
209 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
214 std::vector<std::string> pnames;
215 for (
auto&
p :
iEvent.processHistory())
216 pnames.push_back(
p.processName());
218 return ((
std::find(pnames.begin(), pnames.end(),
a.processName()) - pnames.begin()) >
219 (
std::find(pnames.begin(), pnames.end(),
b.processName()) - pnames.begin()));
229 tbb::this_task_arena::isolate([&] {
m_tree->Fill(); });
243 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
248 tbb::this_task_arena::isolate([&] {
m_lumiTree->Fill(); });
262 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
270 TObjString* tos =
dynamic_cast<TObjString*
>(
m_file->Get(
p.first.c_str()));
272 if (hstring->
str() != tos->GetString())
273 throw cms::Exception(
"LogicError",
"Inconsistent nanoMetadata " +
p.first +
" (" + hstring->
str() +
")");
275 auto ostr = std::make_unique<TObjString>(hstring->
str().c_str());
276 m_file->WriteTObject(ostr.release(),
p.first.c_str());
280 tbb::this_task_arena::isolate([&] {
m_runTree->Fill(); });
294 m_fakeName ?
"PoolOutputModule" :
"NanoAODOutputModule",
299 std::vector<std::string>());
302 m_file->SetCompressionAlgorithm(ROOT::kZLIB);
304 m_file->SetCompressionAlgorithm(ROOT::kLZMA);
306 m_file->SetCompressionAlgorithm(ROOT::kZSTD);
308 m_file->SetCompressionAlgorithm(ROOT::kLZ4);
311 <<
"NanoAODOutputModule configured with unknown compression algorithm '" <<
m_compressionAlgorithm <<
"'\n" 312 <<
"Allowed compression algorithms are ZLIB, LZMA, ZSTD, and LZ4\n";
325 if (
keep.first->className() ==
"nanoaod::FlatTable")
327 else if (
keep.first->className() ==
"edm::TriggerResults") {
329 }
else if (
keep.first->className() ==
"std::basic_string<char,std::char_traits<char> >" &&
330 keep.first->productInstanceName() ==
"genModel") {
333 throw cms::Exception(
"Configuration",
"NanoAODOutputModule cannot handle class " +
keep.first->className());
337 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
339 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
341 else if (
keep.first->className() ==
"nanoaod::FlatTable")
346 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in LuminosityBlock branch");
350 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
352 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
354 else if (
keep.first->className() ==
"nanoaod::FlatTable")
358 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in Run branch");
362 m_tree = std::make_unique<TTree>(
"Events",
"Events");
367 m_lumiTree = std::make_unique<TTree>(
"LuminosityBlocks",
"LuminosityBlocks");
371 m_runTree = std::make_unique<TTree>(
"Runs",
"Runs");
384 int basketSize = 16384;
412 desc.addUntracked<
int>(
"compressionLevel", 9)->setComment(
"ROOT compression level of output file.");
414 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
415 desc.addUntracked<
bool>(
"saveProvenance",
true)
416 ->setComment(
"Save process provenance information, e.g. for edmProvDump");
417 desc.addUntracked<
bool>(
"fakeNameForCrab",
false)
419 "Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran " 420 "(and publish) till crab is fixed");
421 desc.addUntracked<
int>(
"autoFlush", -10000000)->setComment(
"Autoflush parameter for ROOT file");
424 const std::vector<std::string>
keep = {
"drop *",
425 "keep nanoaodFlatTable_*Table_*_*",
426 "keep edmTriggerResults_*_*_*",
427 "keep String_*_genModel_*",
428 "keep nanoaodMergeableCounterTable_*Table_*_*",
429 "keep nanoaodUniqueString_nanoMetadata_*_*"};
436 ->setComment(
"PSet is only used by Data Operations and not by this module.");
std::unique_ptr< TTree > m_runTree
std::vector< TableOutputBranches > m_runFlatTables
std::string const & metaDataTreeName()
std::unique_ptr< TTree > m_lumiTree
std::vector< SummaryTableOutputBranches > m_lumiTables
std::unique_ptr< TTree > m_tree
void setAllowAnything()
allow any parameter label/value pairs
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)
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
ModuleDescription const & description() const
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)
std::vector< EventStringOutputBranches > m_evstrings
void fill(const edm::RunID &id)
std::vector< SummaryTableOutputBranches > m_runTables
std::string const & parameterSetsTreeName()
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
#define DEFINE_FWK_MODULE(type)
bool m_triggers_areSorted
std::vector< LumiOutputBranches > m_lumiTables2
void openFile(edm::FileBlock const &) override
std::string createGlobalIdentifier(bool binary=false)
void reallyCloseFile() override
std::string m_logicalFileName
SelectedProductsForBranchType const & keptProducts() const
void eventWrittenToFile(Token fileToken, RunNumber_t run, EventNumber_t event)
LuminosityBlockID const & id() const
const std::string & str() const
virtual ProcessHistory const & processHistory() const
void outputFileClosed(Token fileToken)
void write(edm::EventForOutput const &e) override
class NanoAODOutputModule::CommonRunBranches m_commonRunBranches
void fill(const edm::EventAuxiliary &aux)
~NanoAODOutputModule() override
edm::JobReport::Token m_jrToken
class NanoAODOutputModule::CommonEventBranches m_commonBranches
edm::ProcessHistoryRegistry m_processHistoryRegistry
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
std::string toString() const
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