CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/IOPool/Streamer/src/StreamerFileReader.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/MsgTools.h"
00002 #include "IOPool/Streamer/interface/StreamerInputFile.h"
00003 #include "IOPool/Streamer/src/StreamerFileReader.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006 #include "FWCore/Catalog/interface/InputFileCatalog.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00010 #include "FWCore/Sources/interface/EventSkipperByID.h"
00011 
00012 namespace edm {
00013   StreamerFileReader::StreamerFileReader(ParameterSet const& pset, InputSourceDescription const& desc) :
00014       StreamerInputSource(pset, desc),
00015       streamerNames_(pset.getUntrackedParameter<std::vector<std::string> >("fileNames")),
00016       streamReader_(),
00017       eventSkipperByID_(EventSkipperByID::create(pset).release()),
00018       numberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")) {
00019     InputFileCatalog catalog(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"), pset.getUntrackedParameter<std::string>("overrideCatalog"));
00020     streamerNames_ = catalog.fileNames();
00021 
00022     if (streamerNames_.size() > 1) {
00023       streamReader_ = std::auto_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_, &numberOfEventsToSkip_, eventSkipperByID_));
00024     } else if (streamerNames_.size() == 1) {
00025       streamReader_ = std::auto_ptr<StreamerInputFile>(new StreamerInputFile(streamerNames_.at(0), &numberOfEventsToSkip_, eventSkipperByID_));
00026     } else {
00027       throw Exception(errors::FileReadError, "StreamerFileReader::StreamerFileReader")
00028          << "No fileNames were specified\n";
00029     }
00030     InitMsgView const* header = getHeader();
00031     deserializeAndMergeWithRegistry(*header, false);
00032   }
00033 
00034   StreamerFileReader::~StreamerFileReader() {
00035   }
00036 
00037   EventPrincipal*
00038   StreamerFileReader::read() {
00039 
00040     EventMsgView const* eview = getNextEvent();
00041 
00042     if (newHeader()) {
00043       // FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
00044       // A new file has been opened and we must compare Heraders here !!
00045       //Get header/init from reader
00046       InitMsgView const* header = getHeader();
00047       deserializeAndMergeWithRegistry(*header, true);
00048     }
00049     if (eview == 0) {
00050       return  0;
00051     }
00052     return(deserializeEvent(*eview));
00053   }
00054 
00055   bool const
00056   StreamerFileReader::newHeader() {
00057     return streamReader_->newHeader();
00058   }
00059 
00060   InitMsgView const*
00061   StreamerFileReader::getHeader() {
00062 
00063     InitMsgView const* header = streamReader_->startMessage();
00064 
00065     if(header->code() != Header::INIT) { //INIT Msg
00066       throw Exception(errors::FileReadError, "StreamerFileReader::readHeader")
00067         << "received wrong message type: expected INIT, got "
00068         << header->code() << "\n";
00069     }
00070     return header;
00071   }
00072 
00073   EventMsgView const*
00074   StreamerFileReader::getNextEvent() {
00075     if (!streamReader_->next()) {
00076       return 0;
00077     }
00078     return streamReader_->currentRecord();
00079   }
00080 
00081   void
00082   StreamerFileReader::fillDescriptions(ConfigurationDescriptions& descriptions) {
00083     ParameterSetDescription desc;
00084     desc.setComment("Reads events from streamer files.");
00085     desc.addUntracked<std::vector<std::string> >("fileNames")
00086         ->setComment("Names of files to be processed.");
00087     desc.addUntracked<unsigned int>("skipEvents", 0U)
00088         ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
00089     desc.addUntracked<std::string>("overrideCatalog", std::string());
00090     //This next parameter is read in the base class, but its default value depends on the derived class, so it is set here.
00091     desc.addUntracked<bool>("inputFileTransitionsEachEvent", false);
00092     StreamerInputSource::fillDescription(desc);
00093     EventSkipperByID::fillDescription(desc);
00094     descriptions.add("source", desc);
00095   }
00096 } //end-of-namespace
00097