17 #include "Compression.h"
19 #include "TObjString.h"
48 #include "tbb/task_arena.h"
83 tree.Branch(
"run", &
m_run,
"run/i");
85 tree.Branch(
"event", &
m_event,
"event/l");
102 tree.Branch(
"run", &
m_run,
"run/i");
149 edm::
one::OutputModule<>(pset),
150 m_fileName(pset.getUntrackedParameter<std::
string>(
"fileName")),
151 m_logicalFileName(pset.getUntrackedParameter<std::
string>(
"logicalFileName")),
152 m_compressionLevel(pset.getUntrackedParameter<int>(
"compressionLevel")),
153 m_compressionAlgorithm(pset.getUntrackedParameter<std::
string>(
"compressionAlgorithm")),
154 m_writeProvenance(pset.getUntrackedParameter<bool>(
"saveProvenance",
true)),
155 m_fakeName(pset.getUntrackedParameter<bool>(
"fakeNameForCrab",
false)),
156 m_autoFlush(pset.getUntrackedParameter<int>(
"autoFlush", -10000000)),
157 m_processHistoryRegistry() {}
175 maxMemory =
static_cast<float>(
m_tree->GetTotBytes()) / percentClusterDone;
176 }
else if (
m_tree->GetZipBytes() == 0) {
177 maxMemory = 100 * 1024 * 1024;
180 float cxnRatio =
m_tree->GetTotBytes() /
static_cast<float>(
m_tree->GetZipBytes());
182 float percentBytesDone = -
m_tree->GetZipBytes() /
static_cast<float>(
m_autoFlush);
190 m_tree->OptimizeBaskets(static_cast<uint32_t>(maxMemory), 1,
"");
201 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
203 t.fill(iEvent, *
m_tree, extensions);
206 std::vector<std::string> pnames;
208 pnames.push_back(
p.processName());
211 (
std::find(pnames.begin(), pnames.end(),
b.processName()) - pnames.begin()));
221 tbb::this_task_arena::isolate([&] {
m_tree->Fill(); });
235 tbb::this_task_arena::isolate([&] {
m_lumiTree->Fill(); });
249 for (
unsigned int extensions = 0; extensions <= 1; ++extensions) {
257 TObjString* tos =
dynamic_cast<TObjString*
>(
m_file->Get(
p.first.c_str()));
259 if (hstring->str() != tos->GetString())
260 throw cms::Exception(
"LogicError",
"Inconsistent nanoMetadata " +
p.first +
" (" + hstring->str() +
")");
262 auto ostr = std::make_unique<TObjString>(hstring->str().c_str());
263 m_file->WriteTObject(ostr.release(),
p.first.c_str());
267 tbb::this_task_arena::isolate([&] {
m_runTree->Fill(); });
281 m_fakeName ?
"PoolOutputModule" :
"NanoAODOutputModule",
286 std::vector<std::string>());
289 m_file->SetCompressionAlgorithm(ROOT::kZLIB);
291 m_file->SetCompressionAlgorithm(ROOT::kLZMA);
294 <<
"NanoAODOutputModule configured with unknown compression algorithm '" <<
m_compressionAlgorithm <<
"'\n"
295 <<
"Allowed compression algorithms are ZLIB and LZMA\n";
307 if (
keep.first->className() ==
"nanoaod::FlatTable")
309 else if (
keep.first->className() ==
"edm::TriggerResults") {
311 }
else if (
keep.first->className() ==
"std::basic_string<char,std::char_traits<char> >" &&
312 keep.first->productInstanceName() ==
"genModel") {
315 throw cms::Exception(
"Configuration",
"NanoAODOutputModule cannot handle class " +
keep.first->className());
319 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
321 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
326 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in LuminosityBlock branch");
330 if (
keep.first->className() ==
"nanoaod::MergeableCounterTable")
332 else if (
keep.first->className() ==
"nanoaod::UniqueString" &&
keep.first->moduleLabel() ==
"nanoMetadata")
334 else if (
keep.first->className() ==
"nanoaod::FlatTable")
338 "NanoAODOutputModule cannot handle class " +
keep.first->className() +
" in Run branch");
342 m_tree = std::make_unique<TTree>(
"Events",
"Events");
347 m_lumiTree = std::make_unique<TTree>(
"LuminosityBlocks",
"LuminosityBlocks");
351 m_runTree = std::make_unique<TTree>(
"Runs",
"Runs");
364 int basketSize = 16384;
392 desc.
addUntracked<
int>(
"compressionLevel", 9)->setComment(
"ROOT compression level of output file.");
394 ->setComment(
"Algorithm used to compress data in the ROOT output file, allowed values are ZLIB and LZMA");
396 ->setComment(
"Save process provenance information, e.g. for edmProvDump");
399 "Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran "
400 "(and publish) till crab is fixed");
401 desc.
addUntracked<
int>(
"autoFlush", -10000000)->setComment(
"Autoflush parameter for ROOT file");
404 const std::vector<std::string>
keep = {
"drop *",
405 "keep nanoaodFlatTable_*Table_*_*",
406 "keep edmTriggerResults_*_*_*",
407 "keep String_*_genModel_*",
408 "keep nanoaodMergeableCounterTable_*Table_*_*",
409 "keep nanoaodUniqueString_nanoMetadata_*_*"};
416 ->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
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