Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
// Original Author:  Broen van Besien
//         Created:  Thu, 19 Mar 2015 18:12:35 GMT

#include "Alignment/MillePedeAlignmentAlgorithm/plugins/MillePedeFileConverter.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondFormats/Common/interface/FileBlobCollection.h"

#include <memory>
#include <fstream>

MillePedeFileConverter::MillePedeFileConverter(const edm::ParameterSet& iConfig)
    : inputDir_(iConfig.getParameter<std::string>("fileDir")),
      inputFileName_(iConfig.getParameter<std::string>("inputBinaryFile")),
      fileBlobLabel_(iConfig.getParameter<std::string>("fileBlobLabel")) {
  // We define what this producer produces: A FileBlobCollection
  produces<FileBlobCollection, edm::Transition::EndLuminosityBlock>(fileBlobLabel_);
}

void MillePedeFileConverter::endLuminosityBlockProduce(edm::LuminosityBlock& iLumi, const edm::EventSetup& iSetup) {
  auto const& moduleType = moduleDescription().moduleName();
  auto const& moduleLabel = moduleDescription().moduleLabel();

  edm::LogInfo("MillePedeFileActions") << "Inserting all data from file " << inputDir_ + inputFileName_
                                       << " as a FileBlob to the lumi, using label \"" << fileBlobLabel_ << "\".";
  // Preparing the FileBlobCollection:
  auto fileBlobCollection = std::make_unique<FileBlobCollection>();

  // Creating the FileBlob:
  // (The FileBlob will signal problems with the file itself.)
  FileBlob fileBlob{inputDir_ + inputFileName_, true};

  if (fileBlob.size() > 0) {  // skip if no data or FileBlob file not found
    // Adding the FileBlob to the lumi:
    fileBlobCollection->addFileBlob(fileBlob);
    edm::LogInfo(moduleType) << "[" << moduleLabel << "] fileBlob size was not empty, putting file blob with size "
                             << fileBlob.size() << std::endl;
  }

  edm::LogInfo(moduleType) << "[" << moduleLabel << "]"
                           << " Root file contains " << fileBlobCollection->size() << " FileBlob(s).";
  iLumi.put(std::move(fileBlobCollection), fileBlobLabel_);
}

// Manage the parameters for the module:
// (Note that this will autogenerate the _cfi.py file.)
void MillePedeFileConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  edm::ParameterSetDescription desc;

  desc.add<std::string>("fileDir", "")
      ->setComment(
          "Keep the fileDir empty if you want to write to the current "
          "directory. If you use it, it should end with a slash.");

  desc.add<std::string>("inputBinaryFile", "milleBinary.dat")
      ->setComment("Filename of the file created by Mille in the AlignmentProducer");

  desc.add<std::string>("fileBlobLabel", "milleBinary.dat")
      ->setComment(
          "It's probably a good idea to keep the label the same as the "
          "original filename(s). See configuration of "
          "MillePedeFileExtractor, it should be the same there.");

  descriptions.add("millePedeFileConverter", desc);
  descriptions.setComment(
      "This is the generic cfi file for the "
      "MillePedeFileConverter");
}