Skip to content

Commit

Permalink
Merge pull request #18322 from sabasehrish/ss_threadsafe_EcalDigiToRaw
Browse files Browse the repository at this point in the history
Ss threadsafe ecal digi to raw
  • Loading branch information
cmsbuild committed Aug 8, 2017
2 parents 65ad419 + ddd1936 commit c925d3e
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 418 deletions.
36 changes: 13 additions & 23 deletions EventFilter/EcalDigiToRaw/interface/BlockFormatter.h
Expand Up @@ -20,34 +20,24 @@ class BlockFormatter {
typedef uint64_t Word64;
typedef uint16_t Word16;

BlockFormatter();
~BlockFormatter();
void SetParam(EcalDigiToRaw* base);
BlockFormatter(EcalDigiToRaw* base);
static const int kCardsPerTower = 5; // Number of VFE cards per trigger tower
void DigiToRaw(FEDRawDataCollection* productRawData);
void print(FEDRawData& rawdata);
// void CleanUp(FEDRawDataCollection* productRawData);
void CleanUp(FEDRawDataCollection* productRawData,
std::map<int, std::map<int,int> >* FEDorder);
void PrintSizes(FEDRawDataCollection* productRawData);
void DigiToRaw(FEDRawDataCollection* productRawData, int run_number, int orbit_number, int bx, int lv1) const;
void print(FEDRawData& rawdata) const;
void CleanUp(FEDRawDataCollection& productRawData,
std::map<int, std::map<int,int> >& FEDorder);
void PrintSizes(FEDRawDataCollection* productRawData) const;

protected :
bool debug_;

bool doBarrel_;
bool doEndCap_;
bool doTCC_;
bool doSR_;
bool doTower_;

std::vector<int32_t> * plistDCCId_;

int* pcounter_;
int* porbit_number_;
int* pbx_;
int* plv1_;
int* prunnumber_;
const bool debug_;

const bool doBarrel_;
const bool doEndCap_;
const std::vector<int32_t> * plistDCCId_;
const bool doTCC_;
const bool doSR_;
const bool doTower_;

};

Expand Down
88 changes: 36 additions & 52 deletions EventFilter/EcalDigiToRaw/interface/EcalDigiToRaw.h
Expand Up @@ -27,11 +27,11 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "EventFilter/EcalDigiToRaw/interface/TowerBlockFormatter.h"
Expand All @@ -47,31 +47,22 @@
// class decleration
//

class EcalDigiToRaw : public edm::EDProducer {
class EcalDigiToRaw : public edm::global::EDProducer<> {
public:
EcalDigiToRaw(const edm::ParameterSet& pset);
virtual ~EcalDigiToRaw();

void beginJob();
void produce(edm::Event& e, const edm::EventSetup& c);
void endJob() ;

typedef long long Word64;
typedef unsigned int Word32;

int* GetCounter() {return &counter_ ;}
bool GetDebug() {return debug_ ;}
int* GetOrbit() {return &orbit_number_ ;}
int* GetBX() {return &bx_ ;}
int* GetLV1() {return &lv1_ ;}
int* GetRunNumber() {return &runnumber_ ;}
bool GetDoBarrel() {return doBarrel_ ;}
bool GetDoEndCap() {return doEndCap_ ;}
bool GetDoSR() {return doSR_ ;}
bool GetDoTower() {return doTower_ ;}
bool GetDoTCC() {return doTCC_ ;}

std::vector<int32_t>* GetListDCCId() {return &listDCCId_ ;}
virtual void produce(edm::StreamID, edm::Event& e, const edm::EventSetup& c) const override;

typedef long long Word64;
typedef unsigned int Word32;

bool GetDebug() const {return debug_ ;}
bool GetDoBarrel() const {return doBarrel_ ;}
bool GetDoEndCap() const {return doEndCap_ ;}
bool GetDoSR() const {return doSR_ ;}
bool GetDoTower() const{return doTower_ ;}
bool GetDoTCC() const {return doTCC_ ;}

const std::vector<int32_t>* GetListDCCId() const {return &listDCCId_ ;}

static const int BXMAX = 2808;

Expand All @@ -81,36 +72,29 @@ class EcalDigiToRaw : public edm::EDProducer {

// ----------member data ---------------------------

int counter_;
int orbit_number_;
bool debug_;
int runnumber_;
int bx_;
int lv1_;

bool doTCC_;
bool doSR_;
bool doTower_;

edm::EDGetTokenT<EcalTrigPrimDigiCollection> labelTT_ ;
edm::EDGetTokenT<EBSrFlagCollection> labelEBSR_ ;
edm::EDGetTokenT<EESrFlagCollection> labelEESR_ ;
edm::EDGetTokenT<EBDigiCollection> EBDigiToken_ ;
edm::EDGetTokenT<EEDigiCollection> EEDigiToken_;
const bool doTCC_;
const bool doSR_;
const bool doTower_;

bool doBarrel_;
bool doEndCap_;
const bool doBarrel_;
const bool doEndCap_;

std::vector<int32_t> listDCCId_;
const std::vector<int32_t> listDCCId_;

std::string label_;
std::string instanceNameEB_;
std::string instanceNameEE_;

TowerBlockFormatter* Towerblockformatter_;
TCCBlockFormatter* TCCblockformatter_;
BlockFormatter* Headerblockformatter_;
SRBlockFormatter* SRblockformatter_;
const std::string label_;
const std::string instanceNameEB_;
const std::string instanceNameEE_;

const edm::EDGetTokenT<EBDigiCollection> EBDigiToken_ ;
const edm::EDGetTokenT<EEDigiCollection> EEDigiToken_;
const edm::EDGetTokenT<EcalTrigPrimDigiCollection> labelTT_ ;
const edm::EDGetTokenT<EBSrFlagCollection> labelEBSR_ ;
const edm::EDGetTokenT<EESrFlagCollection> labelEESR_ ;
const bool debug_;
const std::unique_ptr<TowerBlockFormatter> Towerblockformatter_;
const std::unique_ptr<TCCBlockFormatter> TCCblockformatter_;
const std::unique_ptr<BlockFormatter> Headerblockformatter_;
const std::unique_ptr<SRBlockFormatter> SRblockformatter_;


};
Expand Down
22 changes: 11 additions & 11 deletions EventFilter/EcalDigiToRaw/interface/SRBlockFormatter.h
Expand Up @@ -9,21 +9,21 @@
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"



class SRBlockFormatter : public BlockFormatter {
public :

SRBlockFormatter();
~SRBlockFormatter();
void DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData& rawdata);

void StartEvent();

private :
std::map<int, int> header_;
public :
SRBlockFormatter(EcalDigiToRaw* es): BlockFormatter(es) {};
void DigiToRaw(int dccid, int dcc_channel, int flag, FEDRawData& rawdata, int bx, int lv1, std::map<int, int>& header_) const;

inline std::map<int, int> StartEvent() const {
std::map<int, int> header;
header.clear();
return header;
}
private :
};


Expand Down
17 changes: 7 additions & 10 deletions EventFilter/EcalDigiToRaw/interface/TCCBlockFormatter.h
Expand Up @@ -9,7 +9,7 @@
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"


Expand All @@ -19,16 +19,13 @@



class TCCBlockFormatter : public BlockFormatter {
public :

TCCBlockFormatter();
~TCCBlockFormatter();
static const int kCardsPerTower = 5; // Number of VFE cards per trigger tower
void DigiToRaw(const EcalTriggerPrimitiveDigi& trigprim, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping);
class TCCBlockFormatter : public BlockFormatter {
public :
TCCBlockFormatter(EcalDigiToRaw* es) : BlockFormatter(es) {};
static const int kCardsPerTower = 5; // Number of VFE cards per trigger tower
void DigiToRaw(const EcalTriggerPrimitiveDigi& trigprim, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping, int bx, int lv1) const;

private :
bool AllTPsamples_;
private :

};

Expand Down
35 changes: 16 additions & 19 deletions EventFilter/EcalDigiToRaw/interface/TowerBlockFormatter.h
Expand Up @@ -9,33 +9,30 @@
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "EventFilter/EcalDigiToRaw/interface/BlockFormatter.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"


//
// The crystals corresponding to a given FE in a given FED
//



class TowerBlockFormatter : public BlockFormatter {
public :

TowerBlockFormatter();
~TowerBlockFormatter();
static const int kCardsPerTower = 5; // Number of VFE cards per trigger tower
void DigiToRaw(const EBDataFrame& dataframe, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping);
void DigiToRaw(const EEDataFrame& dataframe, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping);
void StartEvent();
void EndEvent(FEDRawDataCollection* productRawData);

std::map<int, std::map<int,int> >* GetFEDorder() {return FEDorder; }

private :
std::map<int, std::map<int,int> >* FEDmap;
std::map<int, std::map<int,int> >* FEDorder;

public :
struct FEDMapOrder {
std::map<int, std::map<int,int> > fedmap {};
std::map<int, std::map<int,int> > fedorder {};
FEDMapOrder() = default;
};

TowerBlockFormatter(EcalDigiToRaw *es) : BlockFormatter(es) {};
static const int kCardsPerTower = 5; // Number of VFE cards per trigger tower
void DigiToRaw(const EBDataFrame& dataframe, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping, int bx, int lv1, FEDMapOrder &local) const;
void DigiToRaw(const EEDataFrame& dataframe, FEDRawData& rawdata, const EcalElectronicsMapping* TheMapping, int bx, int lv1, FEDMapOrder &local) const;
inline FEDMapOrder StartEvent() const {return FEDMapOrder();}
void EndEvent(FEDRawDataCollection* productRawData);

private :

};

Expand Down
63 changes: 22 additions & 41 deletions EventFilter/EcalDigiToRaw/src/BlockFormatter.cc
Expand Up @@ -10,40 +10,21 @@


using namespace std;
using namespace edm;

BlockFormatter::BlockFormatter() {
}

BlockFormatter::~BlockFormatter() {
}
BlockFormatter::BlockFormatter(EcalDigiToRaw* base) :
debug_(base -> GetDebug()),
doBarrel_(base -> GetDoBarrel()),
doEndCap_(base -> GetDoEndCap()),
plistDCCId_(base -> GetListDCCId()),
doTCC_(base -> GetDoTCC()),
doSR_(base -> GetDoSR()),
doTower_(base -> GetDoTower())
{}

void BlockFormatter::DigiToRaw(FEDRawDataCollection* productRawData, int run_number, int orbit_number_, int bx, int lv1) const {

void BlockFormatter::SetParam(EcalDigiToRaw* base) {

pcounter_ = (base -> GetCounter());
debug_ = base -> GetDebug();
porbit_number_ = (base -> GetOrbit());
plv1_ = (base -> GetLV1());
pbx_ = (base -> GetBX());
prunnumber_ = (base -> GetRunNumber());
doBarrel_ = base -> GetDoBarrel();
doEndCap_ = base -> GetDoEndCap();
plistDCCId_ = base -> GetListDCCId();
doTCC_ = base -> GetDoTCC();
doSR_ = base -> GetDoSR();
doTower_ = base -> GetDoTower();

}


void BlockFormatter::DigiToRaw(FEDRawDataCollection* productRawData) {

int run_number = *prunnumber_;
int orbit_number_ = *porbit_number_;
int bx = *pbx_;
int lv1 = *plv1_;

if (debug_) cout << "in BlockFormatter::DigiToRaw run_number orbit_number bx lv1 " << dec << run_number << " " <<
if (debug_) LogInfo("EcalDigiToRaw: ") << "in BlockFormatter::DigiToRaw run_number orbit_number bx lv1 " << dec << run_number << " " <<
orbit_number_ << " " << bx << " " << lv1 << endl;

for (int idcc=1; idcc <= 54; idcc++) {
Expand Down Expand Up @@ -106,9 +87,9 @@ void BlockFormatter::DigiToRaw(FEDRawDataCollection* productRawData) {



void BlockFormatter::print(FEDRawData& rawdata) {
void BlockFormatter::print(FEDRawData& rawdata) const{
int size = rawdata.size();
cout << "Print RawData size " << dec << size << endl;
LogInfo("EcalDigiToRaw: ") << "Print RawData size " << dec << size << endl;
unsigned char* pData = rawdata.data();

int n = size/8;
Expand All @@ -122,16 +103,16 @@ void BlockFormatter::print(FEDRawData& rawdata) {



void BlockFormatter::CleanUp(FEDRawDataCollection* productRawData,
map<int, map<int,int> >* FEDorder ) {
void BlockFormatter::CleanUp(FEDRawDataCollection& productRawData,
map<int, map<int,int> >& FEDorder ) {


for (int id=0; id < 36 + 18; id++) {
if ( (! doBarrel_) && (id >= 9 && id <= 44)) continue;
if ( (! doEndCap_) && (id <= 8 || id >= 45)) continue;

int FEDid = FEDNumbering::MINECALFEDID + id +1;
FEDRawData& rawdata = productRawData -> FEDData(FEDid);
FEDRawData& rawdata = productRawData.FEDData(FEDid);

// ---- if raw need not be made for a given fed, set its size to empty and return
if ( find( (*plistDCCId_).begin(), (*plistDCCId_).end(), (id+1) ) == (*plistDCCId_).end() )
Expand Down Expand Up @@ -164,11 +145,11 @@ void BlockFormatter::CleanUp(FEDRawDataCollection* productRawData,

// cout << " in BlockFormatter::CleanUp. FEDid = " << FEDid << " event_length*8 " << dec << event_length*8 << endl;

map<int, map<int,int> >::iterator fen = FEDorder -> find(FEDid);
map<int, map<int,int> >::iterator fen = FEDorder.find(FEDid);

bool FED_has_data = true;
if (fen == FEDorder->end()) FED_has_data = false;
if (debug_ && (! FED_has_data)) cout << " FEDid is not in FEDorder ! " << endl;
if (fen == FEDorder.end()) FED_has_data = false;
if (debug_ && (! FED_has_data)) LogInfo("EcalDigiToRaw: ") << " FEDid is not in FEDorder ! " << endl;
if ( ! FED_has_data) {
int ch_status = 7;
for (int iFE=1; iFE <= 68; iFE++) {
Expand Down Expand Up @@ -199,7 +180,7 @@ void BlockFormatter::CleanUp(FEDRawDataCollection* productRawData,
}


void BlockFormatter::PrintSizes(FEDRawDataCollection* productRawData) {
void BlockFormatter::PrintSizes(FEDRawDataCollection* productRawData) const {


for (int id=0; id < 36 + 18; id++) {
Expand All @@ -211,7 +192,7 @@ void BlockFormatter::PrintSizes(FEDRawDataCollection* productRawData) {
int FEDid = FEDNumbering::MINECALFEDID + id;
FEDRawData& rawdata = productRawData -> FEDData(FEDid);
if (rawdata.size() > 0)
cout << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;
LogInfo("EcalDigiToRaw: ") << "Size of FED id " << dec << FEDid << " is : " << dec << rawdata.size() << endl;

}
}
Expand Down

0 comments on commit c925d3e

Please sign in to comment.