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 
4 #include <memory>
5 
7 
11 
13  : theOutputDir(iConfig.getParameter<std::string>("fileDir")),
14  theOutputFileName(iConfig.getParameter<std::string>("outputBinaryFile")),
15  theFileBlobModule(iConfig.getParameter<std::string>("fileBlobModule")),
16  theFileBlobLabel(iConfig.getParameter<std::string>("fileBlobLabel")) {
17  // nothing else in the constructor
18 }
19 
21 
23  edm::EventSetup const&) {
24  // Getting our hands on the vector of FileBlobs
25  edm::Handle<FileBlobCollection> theFileBlobCollection;
26  iRun.getByLabel(theFileBlobModule, theFileBlobLabel, theFileBlobCollection);
27  if (theFileBlobCollection.isValid()) {
28  // Logging the amount of FileBlobs in the vector
29  int theVectorSize = theFileBlobCollection->size();
30  edm::LogInfo("MillePedeFileActions") << "Root file contains "
31  << theVectorSize << " FileBlob(s).";
32  // Loop over the FileBlobs in the vector, and write them to files:
33  for (std::vector<FileBlob>::const_iterator it =
34  theFileBlobCollection->begin();
35  it != theFileBlobCollection->end(); ++it) {
36  // We format the filename with a number, starting from 0 to the size of
37  // our vector.
38  // For this to work, the outputBinaryFile config parameter must contain a
39  // formatting directive for a number, like %04d.
40  char theNumberedOutputFileName[200];
41  int theNumber = it - theFileBlobCollection->begin();
42  sprintf(theNumberedOutputFileName, theOutputFileName.c_str(), theNumber);
43  // Log the filename to which we will write...
44  edm::LogInfo("MillePedeFileActions")
45  << "Writing FileBlob file to file "
46  << theOutputDir + theNumberedOutputFileName << ".";
47  // ...and perform the writing operation.
48  it->write(theOutputDir + theNumberedOutputFileName);
49  // Carefull, it seems that when writing to an impossible file, this is
50  // swallowed by the FileBlob->write operation and no error is thrown.
51  }
52  } else {
53  edm::LogError("MillePedeFileActions")
54  << "Error: The root file does not contain any vector of FileBlob "
55  "created by module \"" << theFileBlobModule << "\", with label \""
56  << theFileBlobLabel << "\".";
57  }
58 }
59 
60 // Manage the parameters for the module:
61 // (Note that this will autogenerate the _cfi.py file.)
63  edm::ConfigurationDescriptions& descriptions) {
65 
66  desc.add<std::string>("fileDir", "")->setComment(
67  "Keep the fileDir empty if you want to write to the current "
68  "directory.");
69 
70  desc.add<std::string>("outputBinaryFile", "milleBinary%04d.dat")->setComment(
71  "Base filename of the files that will be created. This must "
72  "contain "
73  "a placeholder for an index number in the standard C formatting "
74  "style, like %04d.");
75 
76  desc.add<std::string>("fileBlobModule", "millePedeFileConverter")->setComment(
77  "Name of the module that should have generated the blob in the "
78  "root file. Make sure you overwrite this, if you have changed "
79  "this is the configuration of the MillePedeFileConverter.");
80 
81  desc.add<std::string>("fileBlobLabel", "milleBinary.dat")->setComment(
82  "It's probably a good idea to keep the label the same as the "
83  "original filename(s). See configuration of "
84  "MillePedeFileConverter, it should be the same there.");
85 
86  descriptions.add("millePedeFileExtractor", desc);
87  descriptions.setComment(
88  "This is the generic cfi file for the "
89  "MillePedeFileExtractor");
90 }
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:216
MillePedeFileExtractor(const edm::ParameterSet &)
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)
Definition: Run.h:41