Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bsunanda:Run2-hcx10 Port codes to enable full encapsulation of HcalDetId #8998

Merged
merged 5 commits into from May 18, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion CalibFormats/HcalObjects/interface/HcalCalibrationWidthsSet.h
Expand Up @@ -3,6 +3,7 @@

#include "CalibFormats/HcalObjects/interface/HcalCalibrationWidths.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
#include <vector>

/** \class HcalCalibrationWidthsSet
Expand All @@ -18,7 +19,17 @@ class HcalCalibrationWidthsSet {
void clear();
private:
struct CalibWidthSetObject {
CalibWidthSetObject(const DetId& aid) : id(aid) { }
CalibWidthSetObject(const DetId& aid) {
if (aid.det()==DetId::Hcal) {
HcalDetId hcid(aid);
id = HcalDetId(hcid.subdet(),hcid.ieta(),hcid.iphi(),hcid.depth());
} else if (aid.det()==DetId::Calo && aid.subdetId()==HcalZDCDetId::SubdetectorId) {
HcalZDCDetId hcid(aid);
id = HcalZDCDetId(hcid.section(),(hcid.zside()>0),hcid.channel());
} else {
id = aid;
}
}
DetId id;
HcalCalibrationWidths calib;
bool operator<(const CalibWidthSetObject& cso) const { return id < cso.id; }
Expand Down
13 changes: 12 additions & 1 deletion CalibFormats/HcalObjects/interface/HcalCalibrationsSet.h
Expand Up @@ -3,6 +3,7 @@

#include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
#include <vector>

/** \class HcalCalibrationsSet
Expand All @@ -18,7 +19,17 @@ class HcalCalibrationsSet {
void clear();
private:
struct CalibSetObject {
CalibSetObject(const DetId& aid) : id(aid) { }
CalibSetObject(const DetId& aid) {
if (aid.det()==DetId::Hcal) {
HcalDetId hcid(aid);
id = HcalDetId(hcid.subdet(),hcid.ieta(),hcid.iphi(),hcid.depth());
} else if (aid.det()==DetId::Calo && aid.subdetId()==HcalZDCDetId::SubdetectorId) {
HcalZDCDetId hcid(aid);
id = HcalZDCDetId(hcid.section(),(hcid.zside()>0),hcid.channel());
} else {
id = aid;
}
}
DetId id;
HcalCalibrations calib;
bool operator<(const CalibSetObject& cso) const { return id < cso.id; }
Expand Down
21 changes: 12 additions & 9 deletions CalibFormats/HcalObjects/src/HcalCalibrationWidthsSet.cc
Expand Up @@ -13,32 +13,35 @@ const HcalCalibrationWidths& HcalCalibrationWidthsSet::getCalibrationWidths(cons
std::vector<Item>::const_iterator cell;
if (sorted_) {
cell = std::lower_bound (mItems.begin(), mItems.end(), target);
}
else {
} else {
cell = std::find(mItems.begin(),mItems.end(), target);
}
if (cell == mItems.end() || cell->id != fId)
if (cell == mItems.end() ||
((fId.det()==DetId::Hcal && HcalDetId(cell->id) != HcalDetId(fId)) ||
(fId.det()==DetId::Calo && fId.subdetId()==HcalZDCDetId::SubdetectorId && HcalZDCDetId(cell->id) != HcalZDCDetId(fId)) ||
(fId.det()!=DetId::Hcal && (fId.det()==DetId::Calo && fId.subdetId()!=HcalZDCDetId::SubdetectorId) && (cell->id != fId))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bsunanda this check is duplicated other times, e.g. here and here and here.
In order to avoid code duplication, can this become a utility function in the Condition package?

throw cms::Exception ("Conditions not found") << "Unavailable HcalCalibrationWidths for cell " << HcalGenericDetId(fId);
return cell->calib;
}

void HcalCalibrationWidthsSet::setCalibrationWidths(DetId fId, const HcalCalibrationWidths& ca) {
sorted_=false;
std::vector<Item>::iterator cell=std::find(mItems.begin(),mItems.end(),Item(fId)); //slow, but guaranteed
if (cell==mItems.end())
{
mItems.push_back(Item(fId));
mItems.at(mItems.size()-1).calib=ca;
return;
}
if (cell==mItems.end()) {
mItems.push_back(Item(fId));
mItems.at(mItems.size()-1).calib=ca;
return;
}
cell->calib=ca;
}

void HcalCalibrationWidthsSet::sort () {
if (!sorted_) {
std::sort (mItems.begin(), mItems.end());
sorted_ = true;
}
}

void HcalCalibrationWidthsSet::clear() {
mItems.clear();
}
21 changes: 12 additions & 9 deletions CalibFormats/HcalObjects/src/HcalCalibrationsSet.cc
Expand Up @@ -13,32 +13,35 @@ const HcalCalibrations& HcalCalibrationsSet::getCalibrations(const DetId fId) co
std::vector<Item>::const_iterator cell;
if (sorted_) {
cell = std::lower_bound (mItems.begin(), mItems.end(), target);
}
else {
} else {
cell = std::find(mItems.begin(),mItems.end(), target);
}
if (cell == mItems.end() || cell->id != fId)
if (cell == mItems.end() ||
((fId.det()==DetId::Hcal && HcalDetId(cell->id) != HcalDetId(fId)) ||
(fId.det()==DetId::Calo && fId.subdetId()==HcalZDCDetId::SubdetectorId && HcalZDCDetId(cell->id) != HcalZDCDetId(fId)) ||
(fId.det()!=DetId::Hcal && (fId.det()==DetId::Calo && fId.subdetId()!=HcalZDCDetId::SubdetectorId) && (cell->id != fId))))
throw cms::Exception ("Conditions not found") << "Unavailable HcalCalibrations for cell " << HcalGenericDetId(fId);
return cell->calib;
}

void HcalCalibrationsSet::setCalibrations(DetId fId, const HcalCalibrations& ca) {
sorted_=false;
std::vector<Item>::iterator cell=std::find(mItems.begin(),mItems.end(),Item(fId)); //slow, but guaranteed
if (cell==mItems.end())
{
mItems.push_back(Item(fId));
mItems.at(mItems.size()-1).calib=ca;
return;
}
if (cell==mItems.end()) {
mItems.push_back(Item(fId));
mItems.at(mItems.size()-1).calib=ca;
return;
}
cell->calib=ca;
}

void HcalCalibrationsSet::sort () {
if (!sorted_) {
std::sort (mItems.begin(), mItems.end());
sorted_ = true;
}
}

void HcalCalibrationsSet::clear() {
mItems.clear();
}
102 changes: 45 additions & 57 deletions CondFormats/HcalObjects/interface/HcalCondObjectContainer.h
Expand Up @@ -102,8 +102,7 @@ HcalCondObjectContainer<Item>::~HcalCondObjectContainer()
}

template<class Item> void
HcalCondObjectContainer<Item>::initContainer(DetId fId)
{
HcalCondObjectContainer<Item>::initContainer(DetId fId) {
Item emptyItem;

if (fId.det()==DetId::Hcal) {
Expand All @@ -129,8 +128,7 @@ HcalCondObjectContainer<Item>::initContainer(DetId fId)


template<class Item> const Item*
HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const
{
HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const {
unsigned int index=indexFor(fId);

const Item* cell = NULL;
Expand All @@ -157,14 +155,14 @@ HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const
}
}

// Item emptyItem;
// if (cell->rawId() == emptyItem.rawId() )
if ((!cell)) {
if (throwOnFail) {
throw cms::Exception ("Conditions not found")
<< "Unavailable Conditions of type " << myname() << " for cell " << textForId(fId);
}
} else if (cell->rawId() != fId) {
} else if ((fId.det()==DetId::Hcal && HcalDetId(cell->rawId()) != HcalDetId(fId)) ||
(fId.det()==DetId::Calo && fId.subdetId()==HcalZDCDetId::SubdetectorId && HcalZDCDetId(cell->rawId()) != HcalZDCDetId(fId)) ||
(fId.det()!=DetId::Hcal && (fId.det()==DetId::Calo && fId.subdetId()!=HcalZDCDetId::SubdetectorId) && (cell->rawId() != fId))) {
if (throwOnFail) {
throw cms::Exception ("Conditions mismatch")
<< "Requested conditions of type " << myname() << " for cell " << textForId(fId) << " got conditions for cell " << textForId(DetId(cell->rawId()));
Expand All @@ -176,20 +174,20 @@ HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const
}

template<class Item> const bool
HcalCondObjectContainer<Item>::exists(DetId fId) const
{
HcalCondObjectContainer<Item>::exists(DetId fId) const {
const Item* cell = getValues(fId,false);

if (cell)
if (cell->rawId() == fId )
if (cell) {
if ((fId.det()==DetId::Hcal && HcalDetId(cell->rawId()) == HcalDetId(fId)) ||
(fId.det()==DetId::Calo && fId.subdetId()==HcalZDCDetId::SubdetectorId && HcalZDCDetId(cell->rawId()) == HcalZDCDetId(fId)) ||
(fId.det()!=DetId::Hcal && (fId.det()==DetId::Calo && fId.subdetId()!=HcalZDCDetId::SubdetectorId) && (cell->rawId() == fId)))
return true;

}
return false;
}

template<class Item> bool
HcalCondObjectContainer<Item>::addValues(const Item& myItem)
{
HcalCondObjectContainer<Item>::addValues(const Item& myItem) {
bool success = false;
DetId fId(myItem.rawId());
unsigned int index=indexFor(fId);
Expand Down Expand Up @@ -239,53 +237,43 @@ HcalCondObjectContainer<Item>::addValues(const Item& myItem)
}

template<class Item> std::vector<DetId>
HcalCondObjectContainer<Item>::getAllChannels() const
{
HcalCondObjectContainer<Item>::getAllChannels() const {
std::vector<DetId> channels;
Item emptyItem;
for (unsigned int i=0; i<HBcontainer.size(); i++)
{
if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
channels.push_back( DetId(HBcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HEcontainer.size(); i++)
{
if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
channels.push_back( DetId(HEcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HOcontainer.size(); i++)
{
if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
channels.push_back( DetId(HOcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HFcontainer.size(); i++)
{
if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
channels.push_back( DetId(HFcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HTcontainer.size(); i++)
{
if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
channels.push_back( DetId(HTcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<ZDCcontainer.size(); i++)
{
if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<CALIBcontainer.size(); i++)
{
if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<CASTORcontainer.size(); i++)
{
if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HBcontainer.size(); i++) {
if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
channels.push_back( DetId(HBcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HEcontainer.size(); i++) {
if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
channels.push_back( DetId(HEcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HOcontainer.size(); i++) {
if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
channels.push_back( DetId(HOcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HFcontainer.size(); i++) {
if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
channels.push_back( DetId(HFcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<HTcontainer.size(); i++) {
if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
channels.push_back( DetId(HTcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<ZDCcontainer.size(); i++) {
if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<CALIBcontainer.size(); i++) {
if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
}
for (unsigned int i=0; i<CASTORcontainer.size(); i++) {
if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
}

return channels;
}


#endif