-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41186 from smorovic/13_0_X-streamer-padding-backp…
…ort-41155 (13_0_X) streamer format padding backport
- Loading branch information
Showing
20 changed files
with
387 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
CalibCalorimetry/EcalLaserSorting/test/streamOutPadding_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
import FWCore.ParameterSet.VarParsing as VarParsing | ||
|
||
options = VarParsing.VarParsing('analysis') | ||
|
||
options.register ('compAlgo', | ||
'ZLIB', # default value | ||
VarParsing.VarParsing.multiplicity.singleton, | ||
VarParsing.VarParsing.varType.string, | ||
"Compression Algorithm") | ||
|
||
options.parseArguments() | ||
|
||
|
||
process = cms.Process("HLT") | ||
|
||
import FWCore.Framework.test.cmsExceptionsFatal_cff | ||
process.options = FWCore.Framework.test.cmsExceptionsFatal_cff.options | ||
|
||
process.load("FWCore.MessageLogger.MessageLogger_cfi") | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(50) | ||
) | ||
|
||
process.source = cms.Source("EmptySource", | ||
firstEvent = cms.untracked.uint64(10123456789) | ||
) | ||
|
||
process.m1 = cms.EDProducer("StreamThingProducer", | ||
instance_count = cms.int32(5), | ||
array_size = cms.int32(2) | ||
) | ||
|
||
process.m2 = cms.EDProducer("NonProducer") | ||
|
||
process.a1 = cms.EDAnalyzer("StreamThingAnalyzer", | ||
product_to_get = cms.string('m1') | ||
) | ||
|
||
process.out = cms.OutputModule("EventStreamFileWriter", | ||
fileName = cms.untracked.string('teststreamfile.dat'), | ||
padding = cms.untracked.uint32(4096), | ||
compression_level = cms.untracked.int32(1), | ||
use_compression = cms.untracked.bool(True), | ||
compression_algorithm = cms.untracked.string(options.compAlgo), | ||
max_event_size = cms.untracked.int32(7000000) | ||
) | ||
|
||
process.p1 = cms.Path(process.m1*process.a1*process.m2) | ||
process.end = cms.EndPath(process.out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
import FWCore.ParameterSet.VarParsing as VarParsing | ||
|
||
options = VarParsing.VarParsing('analysis') | ||
|
||
options.register ('compAlgo', | ||
'ZLIB', # default value | ||
VarParsing.VarParsing.multiplicity.singleton, | ||
VarParsing.VarParsing.varType.string, | ||
"Compression Algorithm") | ||
|
||
options.parseArguments() | ||
|
||
|
||
process = cms.Process("HLT") | ||
|
||
import FWCore.Framework.test.cmsExceptionsFatal_cff | ||
process.options = FWCore.Framework.test.cmsExceptionsFatal_cff.options | ||
|
||
process.load("FWCore.MessageLogger.MessageLogger_cfi") | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(50) | ||
) | ||
|
||
process.source = cms.Source("EmptySource", | ||
firstEvent = cms.untracked.uint64(10123456789) | ||
) | ||
|
||
process.m1 = cms.EDProducer("StreamThingProducer", | ||
instance_count = cms.int32(5), | ||
array_size = cms.int32(2) | ||
) | ||
|
||
process.m2 = cms.EDProducer("NonProducer") | ||
|
||
process.a1 = cms.EDAnalyzer("StreamThingAnalyzer", | ||
product_to_get = cms.string('m1') | ||
) | ||
|
||
process.out = cms.OutputModule("EventStreamFileWriter", | ||
fileName = cms.untracked.string('teststreamfile.dat'), | ||
padding = cms.untracked.uint32(4096), | ||
compression_level = cms.untracked.int32(1), | ||
use_compression = cms.untracked.bool(True), | ||
compression_algorithm = cms.untracked.string(options.compAlgo), | ||
max_event_size = cms.untracked.int32(7000000) | ||
) | ||
|
||
process.p1 = cms.Path(process.m1*process.a1*process.m2) | ||
process.end = cms.EndPath(process.out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,61 @@ | ||
#include "IOPool/Streamer/interface/StreamerFileIO.h" | ||
#include <fstream> | ||
#include <iostream> | ||
#include <cstring> | ||
#include "FWCore/Utilities/interface/Adler32Calculator.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
#include "IOPool/Streamer/interface/MsgHeader.h" | ||
|
||
namespace edm::streamer { | ||
OutputFile::OutputFile(const std::string& name) | ||
OutputFile::OutputFile(const std::string& name, uint32 padding) | ||
: current_offset_(1), | ||
do_adler_(false), | ||
adlera_(1), | ||
adlerb_(0), | ||
padding_(padding), | ||
ost_(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out)), | ||
filename_(name) { | ||
if (!ost_->is_open()) { | ||
throw cms::Exception("OutputFile", "OutputFile") << "Error Opening Output File: " << name << "\n"; | ||
} | ||
ost_->rdbuf()->pubsetbuf(nullptr, 0); | ||
if (padding_) { | ||
paddingBuf_ = std::make_unique<char[]>(padding_); | ||
memset(paddingBuf_.get(), Header::PADDING, padding_); | ||
} | ||
} | ||
|
||
OutputFile::~OutputFile() { ost_->close(); } | ||
|
||
bool OutputFile::write(const char* ptr, size_t n) { | ||
bool OutputFile::write(const char* ptr, size_t n, bool doPadding) { | ||
ost_->write(ptr, n); | ||
if (!ost_->fail()) { | ||
current_offset_ += (uint64)(n); | ||
if (do_adler_) | ||
cms::Adler32(ptr, n, adlera_, adlerb_); | ||
if (doPadding && padding_) { | ||
return writePadding(); | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void OutputFile::close() { ost_->close(); } | ||
bool OutputFile::writePadding() { | ||
uint64 mod = ost_->tellp() % padding_; | ||
if (mod) { | ||
uint32 rem = padding_ - (uint32)(mod % padding_); | ||
bool ret = write(paddingBuf_.get(), rem, false); | ||
return ret; | ||
} | ||
return false; | ||
} | ||
|
||
void OutputFile::close() { | ||
if (padding_) | ||
if (writePadding()) | ||
throw cms::Exception("OutputFile", "OutputFile") | ||
<< "Error writing padding to the output file: " << filename_ << ": " << std::strerror(errno); | ||
ost_->close(); | ||
} | ||
} // namespace edm::streamer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.