CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MillePedeFileExtractor.cc
Go to the documentation of this file.
1 // Original Author: Broen van Besien
2 // Created: Mon, 23 Mar 2015 14:56:15 GMT
3 
5 
10 
12  : outputDir_(iConfig.getParameter<std::string>("fileDir")),
13  outputFileName_(iConfig.getParameter<std::string>("outputBinaryFile")),
14  maxNumberOfBinaries_(iConfig.getParameter<int>("maxNumberOfBinaries")) {
15 
16  auto fileBlobInputTag = iConfig.getParameter<edm::InputTag>("fileBlobInputTag");
17  fileBlobToken_ = consumes<FileBlobCollection, edm::BranchType::InLumi>(fileBlobInputTag);
18  if (hasBinaryNumberLimit()) {
19  edm::LogInfo("MillePedeFileActions")
20  << "Limiting the number of extracted binary files to "
22  }
23 }
24 
26 
28  const edm::EventSetup&)
29 {
30  if (enoughBinaries()) return;
31 
32  // Getting our hands on the vector of FileBlobs
33  edm::Handle<FileBlobCollection> fileBlobCollection;
34  iLumi.getByToken(fileBlobToken_, fileBlobCollection);
35  if (fileBlobCollection.isValid()) {
36  // Logging the amount of FileBlobs in the vector
37  edm::LogInfo("MillePedeFileActions")
38  << "Root file contains " << fileBlobCollection->size() << " FileBlob(s).";
39  // Loop over the FileBlobs in the vector, and write them to files:
40  for (const auto& blob: *fileBlobCollection) {
41  if (enoughBinaries()) break;
42  // We format the filename with a number, starting from 0 to the size of
43  // our vector.
44  // For this to work, the outputBinaryFile config parameter must contain a
45  // formatting directive for a number, like %04d.
46  char theNumberedOutputFileName[200];
47  sprintf(theNumberedOutputFileName, outputFileName_.c_str(), nBinaries_);
48  // Log the filename to which we will write...
49  edm::LogInfo("MillePedeFileActions")
50  << "Writing FileBlob file to file "
51  << outputDir_ + theNumberedOutputFileName << ".";
52  // ...and perform the writing operation.
53  blob.write(outputDir_ + theNumberedOutputFileName);
54  // Careful, it seems that when writing to an impossible file, this is
55  // swallowed by the FileBlob.write operation and no error is thrown.
56  ++nBinaries_;
57  }
58  } else {
59  edm::LogError("MillePedeFileActions")
60  << "Error: The root file does not contain any vector of FileBlob.";
61  }
62 }
63 
64 
65 // Manage the parameters for the module:
66 // (Note that this will autogenerate the _cfi.py file.)
68  edm::ConfigurationDescriptions& descriptions) {
70 
71  desc.add<std::string>("fileDir", "")->setComment(
72  "Keep the fileDir empty if you want to write to the current "
73  "directory.");
74 
75  desc.add<std::string>("outputBinaryFile", "milleBinary%04d.dat")->setComment(
76  "Base filename of the files that will be created. This must "
77  "contain "
78  "a placeholder for an index number in the standard C formatting "
79  "style, like %04d.");
80 
81  desc.add<edm::InputTag>("fileBlobInputTag", edm::InputTag("millePedeFileConverter",""))->setComment(
82  "Name of the module that should have generated the blob in the "
83  "root file. Make sure you overwrite this, if you have changed "
84  "this is the configuration of the MillePedeFileConverter.");
85 
86  desc.add<int>("maxNumberOfBinaries", 1000)->setComment(
87  "Number of binaries to be extracted from the input files. "
88  "Use a negative value to apply no limit.");
89 
90  descriptions.add("millePedeFileExtractor", desc);
91  descriptions.setComment(
92  "This is the generic cfi file for the "
93  "MillePedeFileExtractor");
94 }
T getParameter(std::string const &) const
edm::EDGetTokenT< FileBlobCollection > fileBlobToken_
const std::string outputFileName_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
MillePedeFileExtractor(const edm::ParameterSet &)
virtual void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:75
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)