CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
MillePedeFileExtractor Class Reference

#include <MillePedeFileExtractor.h>

Inheritance diagram for MillePedeFileExtractor:
edm::one::EDAnalyzer< edm::one::WatchLuminosityBlocks > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 MillePedeFileExtractor (const edm::ParameterSet &)
 
 ~MillePedeFileExtractor () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchLuminosityBlocks >
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) override
 
void endLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) override
 
bool enoughBinaries ()
 
bool hasBinaryNumberLimit ()
 

Static Private Member Functions

static void writeGzipped (const FileBlob &, const std::string &)
 

Private Attributes

edm::EDGetTokenT< FileBlobCollectionfileBlobToken_
 
const int maxNumberOfBinaries_
 
int nBinaries_ {0}
 
const std::string outputDir_
 
const std::string outputFileName_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 31 of file MillePedeFileExtractor.h.

Constructor & Destructor Documentation

◆ MillePedeFileExtractor()

MillePedeFileExtractor::MillePedeFileExtractor ( const edm::ParameterSet iConfig)
explicit

Definition at line 14 of file MillePedeFileExtractor.cc.

15  : outputDir_(iConfig.getParameter<std::string>("fileDir")),
16  outputFileName_(iConfig.getParameter<std::string>("outputBinaryFile")),
17  maxNumberOfBinaries_(iConfig.getParameter<int>("maxNumberOfBinaries")) {
18  auto fileBlobInputTag = iConfig.getParameter<edm::InputTag>("fileBlobInputTag");
19  fileBlobToken_ = consumes<FileBlobCollection, edm::BranchType::InLumi>(fileBlobInputTag);
20  if (hasBinaryNumberLimit()) {
21  edm::LogInfo("MillePedeFileActions") << "Limiting the number of extracted binary files to " << maxNumberOfBinaries_;
22  }
23 }

References MillePedeFileExtractor_cfg::fileBlobInputTag, fileBlobToken_, edm::ParameterSet::getParameter(), hasBinaryNumberLimit(), and maxNumberOfBinaries_.

◆ ~MillePedeFileExtractor()

MillePedeFileExtractor::~MillePedeFileExtractor ( )
override

Definition at line 25 of file MillePedeFileExtractor.cc.

25 {}

Member Function Documentation

◆ analyze()

void MillePedeFileExtractor::analyze ( const edm::Event ,
const edm::EventSetup  
)
inlineoverrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 40 of file MillePedeFileExtractor.h.

40 {}

◆ beginLuminosityBlock()

void MillePedeFileExtractor::beginLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup  
)
inlineoverrideprivate

Definition at line 38 of file MillePedeFileExtractor.h.

38 {}

◆ endLuminosityBlock()

void MillePedeFileExtractor::endLuminosityBlock ( const edm::LuminosityBlock iLumi,
const edm::EventSetup  
)
overrideprivate

Definition at line 27 of file MillePedeFileExtractor.cc.

27  {
28  if (enoughBinaries())
29  return;
30 
31  // Getting our hands on the vector of FileBlobs
32  edm::Handle<FileBlobCollection> fileBlobCollection;
33  iLumi.getByToken(fileBlobToken_, fileBlobCollection);
34  if (fileBlobCollection.isValid()) {
35  // Logging the amount of FileBlobs in the vector
36  edm::LogInfo("MillePedeFileActions") << "Root file contains " << fileBlobCollection->size() << " FileBlob(s).";
37  // Loop over the FileBlobs in the vector, and write them to files:
38  for (const auto& blob : *fileBlobCollection) {
39  if (enoughBinaries())
40  break;
41  // We format the filename with a number, starting from 0 to the size of
42  // our vector.
43  // For this to work, the outputBinaryFile config parameter must contain a
44  // formatting directive for a number, like %04d.
45  char theNumberedOutputFileName[200];
46  sprintf(theNumberedOutputFileName, outputFileName_.c_str(), nBinaries_);
47 
48  // Log the filename to which we will write...
49  edm::LogInfo("MillePedeFileActions")
50  << "Writing FileBlob file to file " << outputDir_ + theNumberedOutputFileName << ".";
51 
52  // ...and perform the writing operation.
53  writeGzipped(blob, outputDir_ + theNumberedOutputFileName);
54 
55  ++nBinaries_;
56  }
57  } else {
58  edm::LogError("MillePedeFileActions") << "Error: The root file does not contain any vector of FileBlob.";
59  }
60 }

References enoughBinaries(), fileBlobToken_, edm::LuminosityBlock::getByToken(), edm::HandleBase::isValid(), nBinaries_, outputDir_, outputFileName_, FileBlobCollection::size(), and writeGzipped().

◆ enoughBinaries()

bool MillePedeFileExtractor::enoughBinaries ( )
inlineprivate

◆ fillDescriptions()

void MillePedeFileExtractor::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 82 of file MillePedeFileExtractor.cc.

82  {
84 
85  desc.add<std::string>("fileDir", "")
86  ->setComment(
87  "Keep the fileDir empty if you want to write to the current "
88  "directory.");
89 
90  desc.add<std::string>("outputBinaryFile", "milleBinary%04d.dat")
91  ->setComment(
92  "Base filename of the files that will be created. This must "
93  "contain "
94  "a placeholder for an index number in the standard C formatting "
95  "style, like %04d.");
96 
97  desc.add<edm::InputTag>("fileBlobInputTag", edm::InputTag("millePedeFileConverter", ""))
98  ->setComment(
99  "Name of the module that should have generated the blob in the "
100  "root file. Make sure you overwrite this, if you have changed "
101  "this is the configuration of the MillePedeFileConverter.");
102 
103  desc.add<int>("maxNumberOfBinaries", 1000)
104  ->setComment(
105  "Number of binaries to be extracted from the input files. "
106  "Use a negative value to apply no limit.");
107 
108  descriptions.add("millePedeFileExtractor", desc);
109  descriptions.setComment(
110  "This is the generic cfi file for the "
111  "MillePedeFileExtractor");
112 }

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, HLT_FULL_cff::InputTag, edm::ConfigurationDescriptions::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ hasBinaryNumberLimit()

bool MillePedeFileExtractor::hasBinaryNumberLimit ( )
inlineprivate

Definition at line 43 of file MillePedeFileExtractor.h.

43 { return maxNumberOfBinaries_ > -1; }

References maxNumberOfBinaries_.

Referenced by enoughBinaries(), and MillePedeFileExtractor().

◆ writeGzipped()

void MillePedeFileExtractor::writeGzipped ( const FileBlob blob,
const std::string &  fileName 
)
staticprivate

Definition at line 62 of file MillePedeFileExtractor.cc.

62  {
63  // - use zlib directly to avoid boost dependencies for this simple task
64  // - zlib and gzip compression differ -> get uncompressed blob first
65  auto uncompressedBlob = blob.getUncompressedBlob();
66  gzFile fp = gzopen(fileName.c_str(), "wb");
67  if (fp == nullptr) {
68  edm::LogError("MillePedeFileActions") << "Problem while opening gzipped file '" << fileName << "'.";
69  }
70  auto nBytes = gzwrite(fp, &uncompressedBlob->front(), uncompressedBlob->size());
71  if (nBytes == 0 || nBytes != static_cast<decltype(nBytes)>(uncompressedBlob->size())) {
72  edm::LogError("MillePedeFileActions") << "Problem while writing FileBlob to gzipped file '" << fileName << "'.";
73  }
74  auto zerr = gzclose(fp);
75  if (zerr != 0) {
76  edm::LogError("MillePedeFileActions") << "Problem while closing gzipped file '" << fileName << "'.";
77  }
78 }

References MillePedeFileConverter_cfg::fileName, personalPlayback::fp, FileBlob::getUncompressedBlob(), and spu::zerr().

Referenced by endLuminosityBlock().

Member Data Documentation

◆ fileBlobToken_

edm::EDGetTokenT<FileBlobCollection> MillePedeFileExtractor::fileBlobToken_
private

Definition at line 50 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and MillePedeFileExtractor().

◆ maxNumberOfBinaries_

const int MillePedeFileExtractor::maxNumberOfBinaries_
private

◆ nBinaries_

int MillePedeFileExtractor::nBinaries_ {0}
private

Definition at line 53 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and enoughBinaries().

◆ outputDir_

const std::string MillePedeFileExtractor::outputDir_
private

◆ outputFileName_

const std::string MillePedeFileExtractor::outputFileName_
private

Definition at line 48 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock().

MillePedeFileExtractor_cfg.fileBlobInputTag
fileBlobInputTag
Definition: MillePedeFileExtractor_cfg.py:36
MillePedeFileExtractor::hasBinaryNumberLimit
bool hasBinaryNumberLimit()
Definition: MillePedeFileExtractor.h:43
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
personalPlayback.fp
fp
Definition: personalPlayback.py:523
MillePedeFileExtractor::writeGzipped
static void writeGzipped(const FileBlob &, const std::string &)
Definition: MillePedeFileExtractor.cc:62
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
edm::Handle
Definition: AssociativeIterator.h:50
FileBlob::getUncompressedBlob
std::unique_ptr< std::vector< unsigned char > > getUncompressedBlob() const
i didn't want to do two copies ... hope this works.
Definition: FileBlob.cc:75
edm::LuminosityBlock::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: LuminosityBlock.h:321
MillePedeFileExtractor::nBinaries_
int nBinaries_
Definition: MillePedeFileExtractor.h:53
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
MillePedeFileExtractor::outputDir_
const std::string outputDir_
Definition: MillePedeFileExtractor.h:47
MillePedeFileExtractor::fileBlobToken_
edm::EDGetTokenT< FileBlobCollection > fileBlobToken_
Definition: MillePedeFileExtractor.h:50
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MillePedeFileExtractor::maxNumberOfBinaries_
const int maxNumberOfBinaries_
Definition: MillePedeFileExtractor.h:52
MillePedeFileExtractor::enoughBinaries
bool enoughBinaries()
Definition: MillePedeFileExtractor.h:42
edm::ConfigurationDescriptions::setComment
void setComment(std::string const &value)
Definition: ConfigurationDescriptions.cc:48
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
spu::zerr
void zerr(int)
Definition: SherpackUtilities.cc:129
edm::InputTag
Definition: InputTag.h:15
FileBlobCollection::size
int size() const
Definition: FileBlobCollection.cc:5
MillePedeFileExtractor::outputFileName_
const std::string outputFileName_
Definition: MillePedeFileExtractor.h:48