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=default
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchLuminosityBlocks >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept 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 noexcept
 
bool wantsStreamRuns () const noexcept
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > 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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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::InputTag fileBlobInputTag_
 
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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 31 of file MillePedeFileExtractor.h.

Constructor & Destructor Documentation

◆ MillePedeFileExtractor()

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

Definition at line 16 of file MillePedeFileExtractor.cc.

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

17  : outputDir_(iConfig.getParameter<std::string>("fileDir")),
18  outputFileName_(iConfig.getParameter<std::string>("outputBinaryFile")),
19  maxNumberOfBinaries_(iConfig.getParameter<int>("maxNumberOfBinaries")) {
20  fileBlobInputTag_ = iConfig.getParameter<edm::InputTag>("fileBlobInputTag");
21  fileBlobToken_ = consumes<FileBlobCollection, edm::BranchType::InLumi>(fileBlobInputTag_);
22  if (hasBinaryNumberLimit()) {
23  edm::LogInfo("MillePedeFileActions") << "Limiting the number of extracted binary files to " << maxNumberOfBinaries_;
24  }
25 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< FileBlobCollection > fileBlobToken_
const std::string outputFileName_
Log< level::Info, false > LogInfo

◆ ~MillePedeFileExtractor()

MillePedeFileExtractor::~MillePedeFileExtractor ( )
overridedefault

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.

References mps_check::command, edm::InputTag::encode(), enoughBinaries(), edm::HandleBase::failedToGet(), fileBlobInputTag_, fileBlobToken_, Hcal_Conditions_forGlobalTag_cff::iLumi, edm::HandleBase::isValid(), nBinaries_, outputDir_, outputFileName_, FileBlobCollection::size(), AlCaHLTBitMon_QueryRunRegistry::string, and writeGzipped().

27  {
28  if (enoughBinaries())
29  return;
30 
31  // Create output directory if not available
32  if (!outputDir_.empty()) {
33  std::string command = "mkdir -p " + outputDir_;
34  int shellReturn = gSystem->Exec(command.c_str());
35  edm::LogInfo("MillePedeFileActions") << "@SUB=MillePedeFileExtractor::endLuminosityBlock"
36  << "Command returns " << shellReturn;
37  }
38 
39  // Getting our hands on the vector of FileBlobs
40  edm::Handle<FileBlobCollection> fileBlobCollection;
41  iLumi.getByToken(fileBlobToken_, fileBlobCollection);
42 
43  if (fileBlobCollection.failedToGet()) {
44  edm::LogError("MillePedeFileActions") << "Failed to get collection from input tag: " << fileBlobInputTag_.encode();
45  return;
46  }
47 
48  if (fileBlobCollection.isValid()) {
49  // Logging the amount of FileBlobs in the vector
50  edm::LogInfo("MillePedeFileActions") << "Root file contains " << fileBlobCollection->size() << " FileBlob(s).";
51  // Loop over the FileBlobs in the vector, and write them to files:
52  for (const auto& blob : *fileBlobCollection) {
53  if (enoughBinaries())
54  break;
55  // We format the filename with a number, starting from 0 to the size of
56  // our vector.
57  // For this to work, the outputBinaryFile config parameter must contain a
58  // formatting directive for a number, like %04d.
59  char theNumberedOutputFileName[200];
60  sprintf(theNumberedOutputFileName, outputFileName_.c_str(), nBinaries_);
61 
62  // Log the filename to which we will write...
63  edm::LogInfo("MillePedeFileActions")
64  << "Writing FileBlob file to file " << outputDir_ + theNumberedOutputFileName << ".";
65 
66  // ...and perform the writing operation.
67  writeGzipped(blob, outputDir_ + theNumberedOutputFileName);
68 
69  ++nBinaries_;
70  }
71  } else {
72  edm::LogError("MillePedeFileActions")
73  << "Error: The root file does not contain any vector of FileBlob under the label " << fileBlobInputTag_.encode()
74  << ".";
75  }
76 }
edm::EDGetTokenT< FileBlobCollection > fileBlobToken_
const std::string outputFileName_
std::string encode() const
Definition: InputTag.cc:159
Log< level::Error, false > LogError
bool failedToGet() const
Definition: HandleBase.h:72
Log< level::Info, false > LogInfo
bool isValid() const
Definition: HandleBase.h:70
list command
Definition: mps_check.py:25
static void writeGzipped(const FileBlob &, const std::string &)

◆ enoughBinaries()

bool MillePedeFileExtractor::enoughBinaries ( )
inlineprivate

◆ fillDescriptions()

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

Definition at line 98 of file MillePedeFileExtractor.cc.

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

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

◆ hasBinaryNumberLimit()

bool MillePedeFileExtractor::hasBinaryNumberLimit ( )
inlineprivate

Definition at line 43 of file MillePedeFileExtractor.h.

References maxNumberOfBinaries_.

Referenced by enoughBinaries(), and MillePedeFileExtractor().

43 { return maxNumberOfBinaries_ > -1; }

◆ writeGzipped()

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

Definition at line 78 of file MillePedeFileExtractor.cc.

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

Referenced by endLuminosityBlock().

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

Member Data Documentation

◆ fileBlobInputTag_

edm::InputTag MillePedeFileExtractor::fileBlobInputTag_
private

Definition at line 50 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and MillePedeFileExtractor().

◆ fileBlobToken_

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

Definition at line 51 of file MillePedeFileExtractor.h.

Referenced by endLuminosityBlock(), and MillePedeFileExtractor().

◆ maxNumberOfBinaries_

const int MillePedeFileExtractor::maxNumberOfBinaries_
private

◆ nBinaries_

int MillePedeFileExtractor::nBinaries_ {0}
private

Definition at line 54 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().