--- UserCode/MitProd/TreeFiller/interface/BaseFiller.h 2008/07/07 16:14:01 1.7 +++ UserCode/MitProd/TreeFiller/interface/BaseFiller.h 2008/07/30 08:39:50 1.10 @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// $Id: BaseFiller.h,v 1.7 2008/07/07 16:14:01 loizides Exp $ +// $Id: BaseFiller.h,v 1.10 2008/07/30 08:39:50 loizides Exp $ // // BaseFiller // @@ -12,9 +12,12 @@ #define TREEFILLER_BASEFILLER_H #include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DataFormats/Common/interface/Handle.h" #include "MitAna/DataUtil/interface/TreeWriter.h" +#include namespace mithep { @@ -32,10 +35,34 @@ namespace mithep protected: const edm::ParameterSet &Conf() const { return config_; } - - const std::string name_; //name of this filler - const edm::ParameterSet config_; //parameter set for this filler - const bool active_; //=1 if active + void PrintErrorAndExit(const char *msg) const; + template + void GetProduct(const std::string name, edm::Handle &product, + const edm::Event &event) const; + + const std::string name_; // name of this filler + const edm::ParameterSet config_; // parameter set for this filler + const bool active_; // =1 if active }; } + +//-------------------------------------------------------------------------------------------------- +template +inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle &product, + const edm::Event &event) const +{ + // Try to access data collection from EDM file. We check if we really get just one + // product with the given name. If not we print an error and exit. + + try { + event.getByLabel(edm::InputTag(edmname),product); + if (!product.isValid()) + throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") + << "Cannot get collection with label " << edmname << std::endl; + } catch (...) { + edm::LogError("BaseFiller") << "Cannot get collection with label " + << edmname << std::endl; + PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str())); + } +} #endif