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
 
- 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
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<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ESProduct , Transition Tr = Transition::Event>
auto esConsumes (eventsetup::EventSetupRecordKey const &, ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 31 of file MillePedeFileExtractor.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file MillePedeFileExtractor.cc.

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

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

Definition at line 28 of file MillePedeFileExtractor.cc.

28 {}

Member Function Documentation

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

Definition at line 43 of file MillePedeFileExtractor.h.

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

Definition at line 39 of file MillePedeFileExtractor.h.

References endLuminosityBlock().

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

Definition at line 30 of file MillePedeFileExtractor.cc.

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

Referenced by beginLuminosityBlock().

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

Definition at line 95 of file MillePedeFileExtractor.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

96  {
98 
99  desc.add<std::string>("fileDir", "")->setComment(
100  "Keep the fileDir empty if you want to write to the current "
101  "directory.");
102 
103  desc.add<std::string>("outputBinaryFile", "milleBinary%04d.dat")->setComment(
104  "Base filename of the files that will be created. This must "
105  "contain "
106  "a placeholder for an index number in the standard C formatting "
107  "style, like %04d.");
108 
109  desc.add<edm::InputTag>("fileBlobInputTag", edm::InputTag("millePedeFileConverter",""))->setComment(
110  "Name of the module that should have generated the blob in the "
111  "root file. Make sure you overwrite this, if you have changed "
112  "this is the configuration of the MillePedeFileConverter.");
113 
114  desc.add<int>("maxNumberOfBinaries", 1000)->setComment(
115  "Number of binaries to be extracted from the input files. "
116  "Use a negative value to apply no limit.");
117 
118  descriptions.add("millePedeFileExtractor", desc);
119  descriptions.setComment(
120  "This is the generic cfi file for the "
121  "MillePedeFileExtractor");
122 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool MillePedeFileExtractor::hasBinaryNumberLimit ( )
inlineprivate
void MillePedeFileExtractor::writeGzipped ( const FileBlob blob,
const std::string &  fileName 
)
staticprivate

Definition at line 69 of file MillePedeFileExtractor.cc.

References FileBlob::getUncompressedBlob(), and spu::zerr().

Referenced by endLuminosityBlock(), and hasBinaryNumberLimit().

70  {
71  // - use zlib directly to avoid boost dependencies for this simple task
72  // - zlib and gzip compression differ -> get uncompressed blob first
73  auto uncompressedBlob = blob.getUncompressedBlob();
74  gzFile fp = gzopen(fileName.c_str(), "wb");
75  if (fp == nullptr) {
76  edm::LogError("MillePedeFileActions")
77  << "Problem while opening gzipped file '" << fileName << "'.";
78  }
79  auto nBytes = gzwrite(fp, &uncompressedBlob->front(), uncompressedBlob->size());
80  if (nBytes == 0 ||
81  nBytes != static_cast<decltype(nBytes)>(uncompressedBlob->size())) {
82  edm::LogError("MillePedeFileActions")
83  << "Problem while writing FileBlob to gzipped file '" << fileName << "'.";
84  }
85  auto zerr = gzclose(fp);
86  if (zerr != 0) {
87  edm::LogError("MillePedeFileActions")
88  << "Problem while closing gzipped file '" << fileName << "'.";
89  }
90 }
void zerr(int)
std::unique_ptr< std::vector< unsigned char > > getUncompressedBlob() const
i didn&#39;t want to do two copies ... hope this works.
Definition: FileBlob.cc:74

Member Data Documentation

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

Definition at line 54 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and MillePedeFileExtractor().

const int MillePedeFileExtractor::maxNumberOfBinaries_
private
int MillePedeFileExtractor::nBinaries_ {0}
private

Definition at line 57 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and enoughBinaries().

const std::string MillePedeFileExtractor::outputDir_
private
const std::string MillePedeFileExtractor::outputFileName_
private

Definition at line 52 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock().