Skip to content

Commit

Permalink
Merge pull request #26791 from cms-sw/code-format-simulation-faf297
Browse files Browse the repository at this point in the history
Running code-format for simulation
  • Loading branch information
cmsbuild committed May 16, 2019
2 parents 97824a5 + eed914b commit 07d3399
Show file tree
Hide file tree
Showing 116 changed files with 10,110 additions and 10,386 deletions.
121 changes: 61 additions & 60 deletions Mixing/Base/interface/BMixingModule.h
Expand Up @@ -35,81 +35,82 @@ namespace edm {
std::vector<std::string> sourceNames_;
std::vector<std::shared_ptr<PileUpConfig>> inputConfigs_;
};
}
} // namespace MixingCache

class BMixingModule : public stream::EDProducer<GlobalCache<MixingCache::Config>> {
public:
/** standard constructor*/
explicit BMixingModule(const edm::ParameterSet& ps, MixingCache::Config const* globalConf);
public:
/** standard constructor*/
explicit BMixingModule(const edm::ParameterSet& ps, MixingCache::Config const* globalConf);

/**Default destructor*/
~BMixingModule() override;
/**Default destructor*/
~BMixingModule() override;

/**Cumulates the pileup events onto this event*/
void produce(edm::Event& e1, const edm::EventSetup& c) override;
/**Cumulates the pileup events onto this event*/
void produce(edm::Event& e1, const edm::EventSetup& c) override;

virtual void initializeEvent(const edm::Event& event, const edm::EventSetup& setup) {}
virtual void initializeEvent(const edm::Event& event, const edm::EventSetup& setup) {}

// edm::Event is non-const because digitizers put their products into the Event.
virtual void finalizeEvent(edm::Event& event, const edm::EventSetup& setup) {}
// edm::Event is non-const because digitizers put their products into the Event.
virtual void finalizeEvent(edm::Event& event, const edm::EventSetup& setup) {}

void beginRun(const edm::Run& r, const edm::EventSetup& setup) override;
void beginLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& setup) override;
void beginRun(const edm::Run& r, const edm::EventSetup& setup) override;
void beginLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& setup) override;

void endRun(const edm::Run& r, const edm::EventSetup& setup) override;
void endLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& setup) override;
void endRun(const edm::Run& r, const edm::EventSetup& setup) override;
void endLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& setup) override;

static std::unique_ptr<MixingCache::Config> initializeGlobalCache(edm::ParameterSet const&);
static void globalEndJob(MixingCache::Config*) {}
static std::unique_ptr<MixingCache::Config> initializeGlobalCache(edm::ParameterSet const&);
static void globalEndJob(MixingCache::Config*) {}

// to be overloaded by dependent class
virtual void reload(const edm::EventSetup & setup){};
// to be overloaded by dependent class
virtual void reload(const edm::EventSetup& setup){};

// Should 'averageNumber' return 0 or 1 if there is no mixing? It is the average number of
// *crossings*, including the hard scatter, or the average number of overlapping events?
// We have guessed 'overlapping events'.
double averageNumber() const {return inputSources_[0] ? inputSources_[0]->averageNumber() : 0.0; }
// Should 'poisson' return 0 or 1 if there is no mixing? See also averageNumber above.
bool poisson() const {return inputSources_[0] ? inputSources_[0]->poisson() : 0.0 ;}
// Should 'averageNumber' return 0 or 1 if there is no mixing? It is the average number of
// *crossings*, including the hard scatter, or the average number of overlapping events?
// We have guessed 'overlapping events'.
double averageNumber() const { return inputSources_[0] ? inputSources_[0]->averageNumber() : 0.0; }
// Should 'poisson' return 0 or 1 if there is no mixing? See also averageNumber above.
bool poisson() const { return inputSources_[0] ? inputSources_[0]->poisson() : 0.0; }

virtual void createnewEDProduct();
virtual void checkSignal(const edm::Event &e);
virtual void addSignals(const edm::Event &e,const edm::EventSetup& c) {}
virtual void addPileups(const int bcr, EventPrincipal *ep, unsigned int eventId,unsigned int worker, const edm::EventSetup& c) {}
virtual void setBcrOffset ();
virtual void setSourceOffset (const unsigned int s);
virtual void put(edm::Event &e,const edm::EventSetup& c) {}
virtual void doPileUp(edm::Event &e, const edm::EventSetup& c);
virtual void createnewEDProduct();
virtual void checkSignal(const edm::Event& e);
virtual void addSignals(const edm::Event& e, const edm::EventSetup& c) {}
virtual void addPileups(
const int bcr, EventPrincipal* ep, unsigned int eventId, unsigned int worker, const edm::EventSetup& c) {}
virtual void setBcrOffset();
virtual void setSourceOffset(const unsigned int s);
virtual void put(edm::Event& e, const edm::EventSetup& c) {}
virtual void doPileUp(edm::Event& e, const edm::EventSetup& c);

protected:
void setupPileUpEvent(const edm::EventSetup& setup);
void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
void beginStream(edm::StreamID) override;
void endStream() override;
// std::string type_;
int bunchSpace_;
int vertexOffset_;
bool checktof_;
int minBunch_;
int maxBunch_;
bool const mixProdStep1_;
bool const mixProdStep2_;
bool readDB_;
bool playback_;
const static unsigned int maxNbSources_;
bool doit_[4];//FIXME
std::vector< float > TrueNumInteractions_;

unsigned int eventId_;

// input, cosmics, beamhalo_plus, beamhalo_minus
std::vector<std::shared_ptr<PileUp>> inputSources_;

void update(edm::EventSetup const&);
edm::ESWatcher<MixingRcd> parameterWatcher_;
void setupPileUpEvent(const edm::EventSetup& setup);
void dropUnwantedBranches(std::vector<std::string> const& wantedBranches);
void beginStream(edm::StreamID) override;
void endStream() override;
// std::string type_;
int bunchSpace_;
int vertexOffset_;
bool checktof_;
int minBunch_;
int maxBunch_;
bool const mixProdStep1_;
bool const mixProdStep2_;

bool readDB_;
bool playback_;
const static unsigned int maxNbSources_;
bool doit_[4]; //FIXME
std::vector<float> TrueNumInteractions_;

unsigned int eventId_;

// input, cosmics, beamhalo_plus, beamhalo_minus
std::vector<std::shared_ptr<PileUp>> inputSources_;

void update(edm::EventSetup const&);
edm::ESWatcher<MixingRcd> parameterWatcher_;
};

}//edm
} // namespace edm

#endif
121 changes: 67 additions & 54 deletions Mixing/Base/interface/PileUp.h
Expand Up @@ -21,7 +21,7 @@ namespace CLHEP {
class RandPoissonQ;
class RandPoisson;
class HepRandomEngine;
}
} // namespace CLHEP

namespace edm {
class SecondaryEventProvider;
Expand All @@ -30,7 +30,7 @@ namespace edm {

struct PileUpConfig {
PileUpConfig(std::string sourcename, double averageNumber, std::unique_ptr<TH1F>& histo, const bool playback)
: sourcename_(sourcename), averageNumber_(averageNumber), histo_(histo.release()), playback_(playback) {}
: sourcename_(sourcename), averageNumber_(averageNumber), histo_(histo.release()), playback_(playback) {}
std::string sourcename_;
double averageNumber_;
std::shared_ptr<TH1F> histo_;
Expand All @@ -42,23 +42,32 @@ namespace edm {
explicit PileUp(ParameterSet const& pset, const std::shared_ptr<PileUpConfig>& config);
~PileUp();

template<typename T>
void readPileUp(edm::EventID const& signal, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator, int const NumPU, StreamID const&);

template<typename T>
void playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin, std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator);

template<typename T>
void playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin, std::vector<edm::EventID>::const_iterator end, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator);

double averageNumber() const {return averageNumber_;}
bool poisson() const {return poisson_;}
bool doPileUp( int BX ) {
if(Source_type_ != "cosmics") {
return none_ ? false : averageNumber_>0.;
}
else {
return ( BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
template <typename T>
void readPileUp(edm::EventID const& signal,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator,
int const NumPU,
StreamID const&);

template <typename T>
void playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin,
std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator);

template <typename T>
void playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin,
std::vector<edm::EventID>::const_iterator end,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator);

double averageNumber() const { return averageNumber_; }
bool poisson() const { return poisson_; }
bool doPileUp(int BX) {
if (Source_type_ != "cosmics") {
return none_ ? false : averageNumber_ > 0.;
} else {
return (BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
}
}
void dropUnwantedBranches(std::vector<std::string> const& wantedBranches) {
Expand All @@ -75,24 +84,27 @@ namespace edm {

void setupPileUpEvent(const edm::EventSetup& setup);

void reload(const edm::EventSetup & setup);
void reload(const edm::EventSetup& setup);

void CalculatePileup(int MinBunch, int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions, StreamID const&);
void CalculatePileup(int MinBunch,
int MaxBunch,
std::vector<int>& PileupSelection,
std::vector<float>& TrueNumInteractions,
StreamID const&);

//template<typename T>
// void recordEventForPlayback(EventPrincipal const& eventPrincipal,
// std::vector<edm::SecondaryEventIDAndFileInfo> &ids, T& eventOperator);
// std::vector<edm::SecondaryEventIDAndFileInfo> &ids, T& eventOperator);

const unsigned int & input()const{return inputType_;}
void input(unsigned int s){inputType_=s;}
const unsigned int& input() const { return inputType_; }
void input(unsigned int s) { inputType_ = s; }

private:

std::unique_ptr<CLHEP::RandPoissonQ> const& poissonDistribution(StreamID const& streamID);
std::unique_ptr<CLHEP::RandPoisson> const& poissonDistr_OOT(StreamID const& streamID);
CLHEP::HepRandomEngine* randomEngine(StreamID const& streamID);

unsigned int inputType_;
unsigned int inputType_;
std::string type_;
std::string Source_type_;
double averageNumber_;
Expand All @@ -110,9 +122,8 @@ namespace edm {
bool PU_Study_;
std::string Study_type_;


int intFixed_OOT_;
int intFixed_ITPU_;
int intFixed_OOT_;
int intFixed_ITPU_;

int minBunch_cosmics_;
int maxBunch_cosmics_;
Expand All @@ -134,30 +145,27 @@ namespace edm {
//TH1F *h1f;
//TH1F *hprobFunction;
//TFile *probFileHisto;

//playback info
bool playback_;

// sequential reading
bool sequential_;
};



template<typename T>
class RecordEventID
{
template <typename T>
class RecordEventID {
private:
std::vector<edm::SecondaryEventIDAndFileInfo>& ids_;
T& eventOperator_;
int eventCount ;
int eventCount;

public:
RecordEventID(std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T& eventOperator)
: ids_(ids), eventOperator_(eventOperator), eventCount(1) {
}
: ids_(ids), eventOperator_(eventOperator), eventCount(1) {}
bool operator()(EventPrincipal const& eventPrincipal, size_t fileNameHash) {
bool used = eventOperator_(eventPrincipal, eventCount);
if(used) {
if (used) {
++eventCount;
ids_.emplace_back(eventPrincipal.id(), fileNameHash);
}
Expand All @@ -175,39 +183,44 @@ namespace edm {
* The "signal" event is optionally used to restrict
* the secondary events used for pileup and mixing.
*/
template<typename T>
void
PileUp::readPileUp(edm::EventID const& signal, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator,
int const pileEventCnt, StreamID const& streamID) {

template <typename T>
void PileUp::readPileUp(edm::EventID const& signal,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator,
int const pileEventCnt,
StreamID const& streamID) {
// One reason PileUp is responsible for recording event IDs is
// that it is the one that knows how many events will be read.
ids.reserve(pileEventCnt);
RecordEventID<T> recorder(ids,eventOperator);
RecordEventID<T> recorder(ids, eventOperator);
int read = 0;
CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
if (read != pileEventCnt)
edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt
<< " requested.";
}

template<typename T>
void
PileUp::playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin, std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator) {
template <typename T>
void PileUp::playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin,
std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator) {
//TrueNumInteractions.push_back( end - begin ) ;
RecordEventID<T> recorder(ids, eventOperator);
input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
}

template<typename T>
void
PileUp::playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin, std::vector<edm::EventID>::const_iterator end, std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T eventOperator) {
template <typename T>
void PileUp::playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin,
std::vector<edm::EventID>::const_iterator end,
std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
T eventOperator) {
//TrueNumInteractions.push_back( end - begin ) ;
RecordEventID<T> recorder(ids, eventOperator);
input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
}

}

} // namespace edm

#endif

0 comments on commit 07d3399

Please sign in to comment.