CMS 3D CMS Logo

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

#include <CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc>

Inheritance diagram for BeamProfile2DBReader:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  TheBSfromDB
 

Public Member Functions

 BeamProfile2DBReader (const edm::ParameterSet &)
 
 ~BeamProfile2DBReader () override=default
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 

Private Attributes

const edm::ESGetToken< SimBeamSpotObjects, SimBeamSpotObjectsRcdbeamSpotToken_
 
TTree * bstree_
 
std::unique_ptr< std::ofstream > output_
 
edm::Service< TFileServicetFileService
 
struct BeamProfile2DBReader::TheBSfromDB theBSfromDB_
 
edm::ESWatcher< SimBeamSpotObjectsRcdwatcher_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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: simple emd::one::EDAnalyzer to retrieve and ntuplize SimBeamSpot data from the conditions database

Implementation: [Notes on implementation]

Definition at line 44 of file BeamProfile2DBReader.cc.

Constructor & Destructor Documentation

◆ BeamProfile2DBReader()

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

Definition at line 78 of file BeamProfile2DBReader.cc.

References MillePedeFileConverter_cfg::fileName, edm::ParameterSet::getUntrackedParameter(), output_, and AlCaHLTBitMon_QueryRunRegistry::string.

79  : beamSpotToken_(esConsumes()), bstree_(nullptr) {
80  //now do what ever initialization is needed
81  usesResource("TFileService");
82  std::string fileName(iConfig.getUntrackedParameter<std::string>("rawFileName"));
83  if (!fileName.empty()) {
84  output_ = std::make_unique<std::ofstream>(fileName.c_str());
85  if (!output_->good()) {
86  edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
87  output_.reset();
88  }
89  }
90 }
Log< level::Error, false > LogError
std::unique_ptr< std::ofstream > output_
T getUntrackedParameter(std::string const &, T const &) const
const edm::ESGetToken< SimBeamSpotObjects, SimBeamSpotObjectsRcd > beamSpotToken_

◆ ~BeamProfile2DBReader()

BeamProfile2DBReader::~BeamProfile2DBReader ( )
overridedefault

Member Function Documentation

◆ analyze()

void BeamProfile2DBReader::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 114 of file BeamProfile2DBReader.cc.

References SimBeamSpotObjects::alpha(), beamSpotToken_, SimBeamSpotObjects::betaStar(), bstree_, edm::ESWatcher< T >::check(), SimBeamSpotObjects::emittance(), BeamProfile2DBReader::TheBSfromDB::fAlpha, BeamProfile2DBReader::TheBSfromDB::fbetastar, BeamProfile2DBReader::TheBSfromDB::femittance, BeamProfile2DBReader::TheBSfromDB::fPhi, BeamProfile2DBReader::TheBSfromDB::fSigmaZ, BeamProfile2DBReader::TheBSfromDB::fTimeOffset, BeamProfile2DBReader::TheBSfromDB::fX0, BeamProfile2DBReader::TheBSfromDB::fY0, BeamProfile2DBReader::TheBSfromDB::fZ0, edm::EventSetup::getData(), iEvent, BeamProfile2DBReader::TheBSfromDB::init(), BeamProfile2DBReader::TheBSfromDB::ls, convertSQLitetoXML_cfg::output, output_, SimBeamSpotObjects::phi(), BeamProfile2DBReader::TheBSfromDB::run, SimBeamSpotObjects::sigmaZ(), theBSfromDB_, SimBeamSpotObjects::timeOffset(), watcher_, SimBeamSpotObjects::x(), SimBeamSpotObjects::y(), and SimBeamSpotObjects::z().

114  {
115  using namespace edm;
116  std::ostringstream output;
117 
118  // initialize the ntuple
119  theBSfromDB_.init();
120 
121  if (watcher_.check(iSetup)) { // check for new IOV for this run / LS
122 
123  output << " for runs: " << iEvent.id().run() << " - " << iEvent.id().luminosityBlock() << std::endl;
124 
125  // Get SimBeamSpot from EventSetup:
126  const SimBeamSpotObjects* mybeamspot = &iSetup.getData(beamSpotToken_);
127 
128  theBSfromDB_.run = iEvent.id().run();
129  theBSfromDB_.ls = iEvent.id().luminosityBlock();
130  theBSfromDB_.fX0 = mybeamspot->x();
131  theBSfromDB_.fY0 = mybeamspot->y();
132  theBSfromDB_.fZ0 = mybeamspot->z();
133  theBSfromDB_.fSigmaZ = mybeamspot->sigmaZ();
134  theBSfromDB_.fbetastar = mybeamspot->betaStar();
135  theBSfromDB_.femittance = mybeamspot->emittance();
136  theBSfromDB_.fPhi = mybeamspot->phi();
137  theBSfromDB_.fAlpha = mybeamspot->alpha();
138  theBSfromDB_.fTimeOffset = mybeamspot->timeOffset();
139  bstree_->Fill();
140  output << *mybeamspot << std::endl;
141  }
142 
143  // Final output - either message logger or output file:
144  if (output_.get())
145  *output_ << output.str();
146  else
147  edm::LogInfo("BeamProfile2DBReader") << output.str();
148 }
double sigmaZ() const
get sigmaZ
struct BeamProfile2DBReader::TheBSfromDB theBSfromDB_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
double alpha() const
get Alpha
std::unique_ptr< std::ofstream > output_
int iEvent
Definition: GenABIO.cc:224
edm::ESWatcher< SimBeamSpotObjectsRcd > watcher_
const edm::ESGetToken< SimBeamSpotObjects, SimBeamSpotObjectsRcd > beamSpotToken_
Log< level::Info, false > LogInfo
double timeOffset() const
get TimeOffset
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
double z() const
get Z position
double emittance() const
get Emittance
HLT enums.
double phi() const
get Phi
double betaStar() const
get BetaStar
double x() const
get X position
double y() const
get Y position

◆ beginJob()

void BeamProfile2DBReader::beginJob ( )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 151 of file BeamProfile2DBReader.cc.

References bstree_, BeamProfile2DBReader::TheBSfromDB::fAlpha, BeamProfile2DBReader::TheBSfromDB::fbetastar, BeamProfile2DBReader::TheBSfromDB::femittance, BeamProfile2DBReader::TheBSfromDB::fPhi, BeamProfile2DBReader::TheBSfromDB::fSigmaZ, BeamProfile2DBReader::TheBSfromDB::fTimeOffset, BeamProfile2DBReader::TheBSfromDB::fX0, BeamProfile2DBReader::TheBSfromDB::fY0, BeamProfile2DBReader::TheBSfromDB::fZ0, BeamProfile2DBReader::TheBSfromDB::ls, TFileService::make(), BeamProfile2DBReader::TheBSfromDB::run, tFileService, and theBSfromDB_.

151  {
152  bstree_ = tFileService->make<TTree>("BSNtuple", "SimBeamSpot analyzer ntuple");
153 
154  //Tree Branches
155  bstree_->Branch("run", &theBSfromDB_.run, "run/I");
156  bstree_->Branch("ls", &theBSfromDB_.ls, "ls/I");
157  bstree_->Branch("BSx0", &theBSfromDB_.fX0, "BSx0/F");
158  bstree_->Branch("BSy0", &theBSfromDB_.fY0, "BSy0/F");
159  bstree_->Branch("BSz0", &theBSfromDB_.fZ0, "BSz0/F");
160  bstree_->Branch("Beamsigmaz", &theBSfromDB_.fSigmaZ, "Beamsigmaz/F");
161  bstree_->Branch("BetaStar", &theBSfromDB_.fbetastar, "BetaStar/F");
162  bstree_->Branch("Emittance", &theBSfromDB_.femittance, "Emittance/F");
163  bstree_->Branch("Phi", &theBSfromDB_.fPhi, "Phi/F");
164  bstree_->Branch("Alpha", &theBSfromDB_.fAlpha, "Alpha/F");
165  bstree_->Branch("TimeOffset", &theBSfromDB_.fTimeOffset, "TimeOffset/F");
166 }
struct BeamProfile2DBReader::TheBSfromDB theBSfromDB_
edm::Service< TFileService > tFileService
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64

◆ fillDescriptions()

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

Member Data Documentation

◆ beamSpotToken_

const edm::ESGetToken<SimBeamSpotObjects, SimBeamSpotObjectsRcd> BeamProfile2DBReader::beamSpotToken_
private

Definition at line 66 of file BeamProfile2DBReader.cc.

Referenced by analyze().

◆ bstree_

TTree* BeamProfile2DBReader::bstree_
private

Definition at line 68 of file BeamProfile2DBReader.cc.

Referenced by analyze(), and beginJob().

◆ output_

std::unique_ptr<std::ofstream> BeamProfile2DBReader::output_
private

Definition at line 72 of file BeamProfile2DBReader.cc.

Referenced by analyze(), and BeamProfile2DBReader().

◆ tFileService

edm::Service<TFileService> BeamProfile2DBReader::tFileService
private

Definition at line 67 of file BeamProfile2DBReader.cc.

Referenced by beginJob().

◆ theBSfromDB_

struct BeamProfile2DBReader::TheBSfromDB BeamProfile2DBReader::theBSfromDB_
private

Referenced by analyze(), and beginJob().

◆ watcher_

edm::ESWatcher<SimBeamSpotObjectsRcd> BeamProfile2DBReader::watcher_
private

Definition at line 71 of file BeamProfile2DBReader.cc.

Referenced by analyze().