CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
LumiProducerFromBrilcalc Class Reference

#include <RecoLuminosity/LumiProducer/plugins/LumiProducerFromBrilcalc.cc>

Inheritance diagram for LumiProducerFromBrilcalc:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 LumiProducerFromBrilcalc (const edm::ParameterSet &)
 
 ~LumiProducerFromBrilcalc () override=default
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

const bool doBunchByBunch_
 
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_
 
const std::string lumiFile_
 
const bool throwIfNotFound_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Description: Takes a csv file with luminosity information produced by brilcalc and reads it into the event.

Implementation: [Notes on implementation]

Definition at line 42 of file LumiProducerFromBrilcalc.cc.

Constructor & Destructor Documentation

◆ LumiProducerFromBrilcalc()

LumiProducerFromBrilcalc::LumiProducerFromBrilcalc ( const edm::ParameterSet iConfig)
explicit

Definition at line 63 of file LumiProducerFromBrilcalc.cc.

References doBunchByBunch_, Exception, l1GtPatternGenerator_cfi::fields, mps_splice::line, eostools::ls(), lumiData_, lumiFile_, writedatasetfile::run, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

64  : lumiFile_(iConfig.getParameter<std::string>("lumiFile")),
65  throwIfNotFound_(iConfig.getParameter<bool>("throwIfNotFound")),
66  doBunchByBunch_(iConfig.getParameter<bool>("doBunchByBunch")) {
67  //register your products
68  produces<LumiInfo>("brilcalc");
69 
70  //now do what ever other initialization is needed
71  if (doBunchByBunch_) {
72  throw cms::Exception("LumiProducerFromBrilcalc")
73  << "Sorry, bunch-by-bunch luminosity is not yet supported. Please bug your friendly lumi expert!";
74  }
75 
76  // Read luminosity data and store it in lumiData_.
77  edm::LogInfo("LumiProducerFromBrilcalc") << "Reading luminosity data from " << lumiFile_ << "...one moment...";
78  std::ifstream lumiFile(lumiFile_);
79  if (!lumiFile.is_open()) {
80  throw cms::Exception("LumiProducerFromBrilcalc") << "Failed to open input luminosity file " << lumiFile_;
81  }
82 
83  int nLS = 0;
85  while (true) {
86  std::getline(lumiFile, line);
87  if (lumiFile.eof() || lumiFile.fail())
88  break;
89  if (line.empty())
90  continue; // skip blank lines
91  if (line.at(0) == '#')
92  continue; // skip comment lines
93 
94  // Break into fields. These should be, in order: run:fill, brills:cmsls, time, beam status, beam energy,
95  // delivered lumi, recorded lumi, average pileup, source.
96  std::stringstream ss(line);
97  std::string field;
98  std::vector<std::string> fields;
99 
100  while (std::getline(ss, field, ','))
101  fields.push_back(field);
102 
103  if (fields.size() != 9) {
104  edm::LogWarning("LumiProducerFromBrilcalc") << "Malformed line in csv file: " << line;
105  continue;
106  }
107 
108  // Extract the run number from fields[0] and the lumisection number from fields[1]. Fortunately since the
109  // thing we want is before the colon, we don't have to split them again.
110  int run, ls;
111  std::stringstream runfill(fields[0]);
112  runfill >> run;
113  std::stringstream lsls(fields[1]);
114  lsls >> ls;
115 
116  // Extract the delivered and recorded lumi from fields[5] and fields[6].
117  float lumiDel, lumiRec, dtFrac;
118  std::stringstream lumiDelString(fields[5]);
119  lumiDelString >> lumiDel;
120  std::stringstream lumiRecString(fields[6]);
121  lumiRecString >> lumiRec;
122 
123  // Calculate the deadtime fraction
124  dtFrac = 1.0 - lumiRec / lumiDel;
125 
126  // Finally, store it all.
127  lumiData_[std::make_pair(run, ls)] = std::make_pair(lumiDel, dtFrac);
128  nLS++;
129  }
130  edm::LogInfo("LumiProducerFromBrilcalc") << "Read " << nLS << " lumisections from " << lumiFile_;
131  lumiFile.close();
132 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_
Log< level::Info, false > LogInfo
def ls(path, rec=False)
Definition: eostools.py:349
Log< level::Warning, false > LogWarning

◆ ~LumiProducerFromBrilcalc()

LumiProducerFromBrilcalc::~LumiProducerFromBrilcalc ( )
overridedefault

Member Function Documentation

◆ fillDescriptions()

void LumiProducerFromBrilcalc::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 164 of file LumiProducerFromBrilcalc.cc.

References edm::ConfigurationDescriptions::addDefault(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

164  {
165  // Allowed parameters
167  desc.add<std::string>("lumiFile");
168  desc.add<bool>("throwIfNotFound", false);
169  desc.add<bool>("doBunchByBunch", false);
170  descriptions.addDefault(desc);
171 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ produce()

void LumiProducerFromBrilcalc::produce ( edm::StreamID  iStreamID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 139 of file LumiProducerFromBrilcalc.cc.

References Exception, iEvent, LogDebug, lumiData_, and throwIfNotFound_.

141  {
142  std::vector<float> bxlumi(3564, 0);
143  std::pair<int, int> runls = std::make_pair(iEvent.run(), iEvent.luminosityBlock());
144  if (lumiData_.count(runls) == 1) {
145  // if we have data for this run/LS, put it in the event
146  LogDebug("LumiProducerFromBrilcalc") << "Filling for run " << runls.first << " ls " << runls.second
147  << " with delivered " << lumiData_.at(runls).first << " dt "
148  << lumiData_.at(runls).second;
149  iEvent.put(std::make_unique<LumiInfo>(lumiData_.at(runls).second, bxlumi, lumiData_.at(runls).first), "brilcalc");
150  } else {
151  if (throwIfNotFound_) {
152  throw cms::Exception("LumiProducerFromBrilcalc")
153  << "Failed to find luminosity for run " << runls.first << " LS " << runls.second;
154  } else {
155  // just put in zeroes
156  edm::LogWarning("LumiProducerFromBrilcalc")
157  << "Failed to find luminosity for run " << runls.first << " ls " << runls.second;
158  iEvent.put(std::make_unique<LumiInfo>(0, bxlumi, 0), "brilcalc");
159  }
160  }
161 }
int iEvent
Definition: GenABIO.cc:224
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_
Log< level::Warning, false > LogWarning
#define LogDebug(id)

Member Data Documentation

◆ doBunchByBunch_

const bool LumiProducerFromBrilcalc::doBunchByBunch_
private

Definition at line 55 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc().

◆ lumiData_

std::map<std::pair<int, int>, std::pair<float, float> > LumiProducerFromBrilcalc::lumiData_
private

Definition at line 56 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc(), and produce().

◆ lumiFile_

const std::string LumiProducerFromBrilcalc::lumiFile_
private

Definition at line 53 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc().

◆ throwIfNotFound_

const bool LumiProducerFromBrilcalc::throwIfNotFound_
private

Definition at line 54 of file LumiProducerFromBrilcalc.cc.

Referenced by produce().