19 #include "TObjString.h" 49 #include "oneapi/tbb/task_arena.h" 155 m_fileName(
pset.getUntrackedParameter<
std::
string>(
"fileName")),
156 m_logicalFileName(
pset.getUntrackedParameter<
std::
string>(
"logicalFileName")),
157 m_compressionLevel(
pset.getUntrackedParameter<
int>(
"compressionLevel")),
158 m_compressionAlgorithm(
pset.getUntrackedParameter<
std::
string>(
"compressionAlgorithm")),
159 m_writeProvenance(
pset.getUntrackedParameter<
bool>(
"saveProvenance",
true)),
160 m_fakeName(
pset.getUntrackedParameter<
bool>(
"fakeNameForCrab",
false)),
161 m_autoFlush(
pset.getUntrackedParameter<
int>(
"autoFlush", -10000000)),
162 m_processHistoryRegistry() {}
180 maxMemory =
static_cast<float>(
m_tree->GetTotBytes()) / percentClusterDone;
181 }
else if (
m_tree->GetZipBytes() == 0) {
182 maxMemory = 100 * 1024 * 1024;
185 float cxnRatio =
m_tree->GetTotBytes() /
static_cast<float>(
m_tree->GetZipBytes());
187 float percentBytesDone = -
m_tree->GetZipBytes() /
static_cast<float>(
m_autoFlush);
195 m_tree->OptimizeBaskets(static_cast<uint32_t>(maxMemory), 1,
"");
206 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
211 std::vector<std::string> pnames;
212 for (
auto&
p :
iEvent.processHistory())
213 pnames.push_back(
p.processName());
215 return ((
std::find(pnames.begin(), pnames.end(),
a.processName()) - pnames.begin()) >
216 (
std::find(pnames.begin(), pnames.end(),
b.processName()) - pnames.begin()));
226 tbb::this_task_arena::isolate([&] {
m_tree->Fill(); });
240 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
245 tbb::this_task_arena::isolate([&] {
m_lumiTree->Fill(); });
259 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
267 TObjString* tos =
dynamic_cast<TObjString*
>(
m_file->Get(
p.first.c_str()));
269 if (hstring->
str() != tos->GetString())
270 throw cms::Exception(
"LogicError",
"Inconsistent nanoMetadata " +
p.first +
" (" + hstring->
str() +
")");
272 auto ostr = std::make_unique<TObjString>(hstring->
str().c_str());
273 m_file->WriteTObject(ostr.release(),
p.first.c_str());
277 tbb::this_task_arena::isolate([&] {
m_runTree->Fill(); });
291 m_fakeName ?
"PoolOutputModule" :
"NanoAODOutputModule",
296 std::vector<std::string>());
299 m_file->SetCompressionAlgorithm(ROOT::kZLIB);
301 m_file->SetCompressionAlgorithm(ROOT::kLZMA);
303 m_file->SetCompressionAlgorithm(ROOT::kZSTD);
305 m_file->SetCompressionAlgorithm(ROOT::kLZ4);
308 <<
"NanoAODOutputModule configured with unknown compression algorithm '" <<
m_compressionAlgorithm <<
"'\n" 309 <<
"Allowed compression algorithms are ZLIB, LZMA, ZSTD, and LZ4\n";
322 if (
keep.first->className() ==
"nanoaod::FlatTable")
324 else if (
keep.first->className() ==
"edm::TriggerResults") {
326 }
else if (
keep.first->className() ==
"std::basic_string<char,std::char_traits<char> >" &&
327 keep.first->productInstanceName() ==
"genModel") {
330 throw cms::Exception(
"Configuration",
"NanoAODOutputModule cannot handle class " +
keep.first->className());
334 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
336 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
338 else if (
keep.first->className() ==
"nanoaod::FlatTable")
343 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in LuminosityBlock branch");
347 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
349 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
351 else if (
keep.first->className() ==
"nanoaod::FlatTable")
355 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in Run branch");
359 m_tree = std::make_unique<TTree>(
"Events",
"Events");
364 m_lumiTree = std::make_unique<TTree>(
"LuminosityBlocks",
"LuminosityBlocks");
368 m_runTree = std::make_unique<TTree>(
"Runs",
"Runs");
381 int basketSize = 16384;
409 desc.addUntracked<
int>(
"compressionLevel", 9)->setComment(
"ROOT compression level of output file.");
411 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
412 desc.addUntracked<
bool>(
"saveProvenance",
true)
413 ->setComment(
"Save process provenance information, e.g. for edmProvDump");
414 desc.addUntracked<
bool>(
"fakeNameForCrab",
false)
416 "Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran " 417 "(and publish) till crab is fixed");
418 desc.addUntracked<
int>(
"autoFlush", -10000000)->setComment(
"Autoflush parameter for ROOT file");
421 const std::vector<std::string>
keep = {
"drop *",
422 "keep nanoaodFlatTable_*Table_*_*",
423 "keep edmTriggerResults_*_*_*",
424 "keep String_*_genModel_*",
425 "keep nanoaodMergeableCounterTable_*Table_*_*",
426 "keep nanoaodUniqueString_nanoMetadata_*_*"};
433 ->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