--- UserCode/MitProd/TreeFiller/interface/BaseFiller.h 2008/07/30 08:39:50 1.10 +++ UserCode/MitProd/TreeFiller/interface/BaseFiller.h 2010/03/18 20:20:59 1.19 @@ -1,5 +1,5 @@ //-------------------------------------------------------------------------------------------------- -// $Id: BaseFiller.h,v 1.10 2008/07/30 08:39:50 loizides Exp $ +// $Id: BaseFiller.h,v 1.19 2010/03/18 20:20:59 bendavid Exp $ // // BaseFiller // @@ -8,61 +8,99 @@ // Authors: C.Paus //-------------------------------------------------------------------------------------------------- -#ifndef TREEFILLER_BASEFILLER_H -#define TREEFILLER_BASEFILLER_H +#ifndef MITPROD_TREEFILLER_BASEFILLER_H +#define MITPROD_TREEFILLER_BASEFILLER_H +#include "DataFormats/Common/interface/Handle.h" #include "FWCore/Framework/interface/Event.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 { + class BranchTable; + class ObjectService; + class BaseFiller { public: BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true); virtual ~BaseFiller() {} - bool Active() const { return active_; } - virtual void BookDataBlock(TreeWriter &tws) = 0; + bool Active() const { return active_; } + void AddBranchDep(const char *n, const char *d); + void AddBranchDep(const std::string &n, const char *d) + { AddBranchDep(n.c_str(), d); } + void AddBranchDep(const std::string &n, const std::string &d) + { AddBranchDep(n.c_str(), d.c_str()); } + virtual void BookDataBlock(TreeWriter &tws) = 0; virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0; - const std::string &Name() const { return name_; } + virtual void FillRunBlock(edm::Run const &r, edm::EventSetup const &es) {} + const std::string &Name() const { return name_; } virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {} + int Verbose() const { return verbose_; } + bool Verify() const { return verify_; } protected: - const edm::ParameterSet &Conf() const { return config_; } + const edm::ParameterSet &Conf() const { return config_; } void PrintErrorAndExit(const char *msg) const; template - void GetProduct(const std::string name, edm::Handle &product, + void GetProduct(const std::string name, edm::Handle &prod, 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 + bool GetProductSafe(const std::string name, edm::Handle &prod, + const edm::Event &event) const; + ObjectService *OS(); + + const std::string name_; //name of this filler + const std::string brtname_; //name of branch table (def = BranchTable) + const edm::ParameterSet config_; //parameter set for this filler + const bool active_; //=1 if active + const bool verify_; //=1 if verificatin code is active + const int verbose_; //verbosity level (do not introduce more than 0-4 levels) + BranchTable *brtable_; //branch dependency table }; } //-------------------------------------------------------------------------------------------------- template -inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle &product, +inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle &prod, 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()) + event.getByLabel(edm::InputTag(edmname),prod); + if (!prod.isValid()) throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") - << "Cannot get collection with label " << edmname << std::endl; + << "Cannot get collection with label " << edmname << " for " << Name() << 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())); + << edmname << " for " << Name() << std::endl; + PrintErrorAndExit(Form("Cannot get collection with label %s for %s", + edmname.c_str(), name_.c_str())); + } +} + +//-------------------------------------------------------------------------------------------------- +template +inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle &prod, + const edm::Event &event) const +{ + // Try to safely access data collection from EDM file. We check if we really get just one + // product with the given name. If not, we return false. + + try { + event.getByLabel(edm::InputTag(edmname),prod); + if (!prod.isValid()) + return false; + } catch (...) { + return false; } + return true; } #endif