Skip to content

Commit

Permalink
Fix for ensuring backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Jan 17, 2014
1 parent 05a8be6 commit e2af6f5
Show file tree
Hide file tree
Showing 33 changed files with 1,099 additions and 56 deletions.
13 changes: 12 additions & 1 deletion CalibFormats/HcalObjects/interface/HcalCalibrationWidthsSet.h
Original file line number Diff line number Diff line change
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 @@ -20,7 +21,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
Original file line number Diff line number Diff line change
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 @@ -20,7 +21,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
14 changes: 10 additions & 4 deletions CalibFormats/HcalObjects/src/HcalCalibrationWidthsSet.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "CalibFormats/HcalObjects/interface/HcalCalibrationWidthsSet.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <algorithm>
#include <iostream>
Expand All @@ -17,18 +19,22 @@ const HcalCalibrationWidths& HcalCalibrationWidthsSet::getCalibrationWidths(cons
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 HcalCalibrationWidths for cell " << HcalGenericDetId(fId);
return cell->calib;
}

void HcalCalibrationWidthsSet::setCalibrationWidths(DetId fId, const HcalCalibrationWidths& ca) {
Item target(fId);
sorted_=false;
std::vector<Item>::iterator cell=std::find(mItems.begin(),mItems.end(),Item(fId)); //slow, but guaranteed
std::vector<Item>::iterator cell=std::find(mItems.begin(),mItems.end(),target); //slow, but guaranteed
if (cell==mItems.end())
{
mItems.push_back(Item(fId));
mItems.at(mItems.size()-1).calib=ca;
target.calib=ca;
mItems.push_back(target);
return;
}
cell->calib=ca;
Expand Down
5 changes: 4 additions & 1 deletion CalibFormats/HcalObjects/src/HcalCalibrationsSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const HcalCalibrations& HcalCalibrationsSet::getCalibrations(const DetId fId) co
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;
}
Expand Down
11 changes: 7 additions & 4 deletions CondFormats/HcalObjects/interface/HcalCondObjectContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define HcalCondObjectContainer_h

#include <vector>
#include <iostream>
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalOtherDetId.h"
#include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
Expand Down Expand Up @@ -123,7 +124,6 @@ template<class Item> const Item*
HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const
{
unsigned int index=indexFor(fId);

const Item* cell = NULL;

if (index<0xFFFFFFFu) {
Expand All @@ -147,15 +147,16 @@ 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 @@ -172,7 +173,9 @@ HcalCondObjectContainer<Item>::exists(DetId fId) const
const Item* cell = getValues(fId,false);

if (cell)
if (cell->rawId() == fId )
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;
Expand Down
12 changes: 8 additions & 4 deletions CondFormats/HcalObjects/src/HcalCholeskyMatrices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ HcalCholeskyMatrices::getValues(DetId fId, bool throwOnFail) const

// HcalCholeskyMatrix emptyHcalCholeskyMatrix;
// if (cell->rawId() == emptyHcalCholeskyMatrix.rawId() )
if ((!cell) || (cell->rawId() != fId ) ) {
if ((!cell) ||
(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 not found")
throw cms::Exception ("Conditions not found")
<< "Unavailable Conditions of type " << myname() << " for cell " << fId.rawId();
} else {
cell=0;
Expand All @@ -63,8 +66,9 @@ HcalCholeskyMatrices::exists(DetId fId) const

// HcalCholeskyMatrix emptyHcalCholeskyMatrix;
if (cell)
// if (cell->rawId() != emptyHcalCholeskyMatrix.rawId() )
if (cell->rawId() == fId )
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;
Expand Down
14 changes: 9 additions & 5 deletions CondFormats/HcalObjects/src/HcalCovarianceMatrices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ HcalCovarianceMatrices::initContainer(DetId fId)
case(HcalForward) : for (unsigned int i=0; i<sizeFor(fId); i++) HFcontainer.push_back(emptyItem); break;
default: break;
}
}
}

}

Expand All @@ -50,9 +50,12 @@ HcalCovarianceMatrices::getValues(DetId fId, bool throwOnFail) const

// HcalCovarianceMatrix emptyHcalCovarianceMatrix;
// if (cell->rawId() == emptyHcalCovarianceMatrix.rawId() )
if ((!cell) || (cell->rawId() != fId ) ) {
if ((!cell) ||
(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 not found")
throw cms::Exception ("Conditions not found")
<< "Unavailable Conditions of type " << myname() << " for cell " << fId.rawId();
} else {
cell=0;
Expand All @@ -68,8 +71,9 @@ HcalCovarianceMatrices::exists(DetId fId) const

// HcalCovarianceMatrix emptyHcalCovarianceMatrix;
if (cell)
// if (cell->rawId() != emptyHcalCovarianceMatrix.rawId() )
if (cell->rawId() == fId )
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;
Expand Down
8 changes: 5 additions & 3 deletions DataFormats/ForwardDetId/interface/CFCDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class CFCDetId : public DetId {
CFCDetId();
/** Create cellid from raw id (0=invalid tower id) */
CFCDetId(uint32_t rawid);
/** Constructor from subdetector, signed ieta,iphi and depth */
CFCDetId(ForwardSubdetector subdet, int ieta, int iphi, int depth);
/** Constructor from subdetector, signed ieta,iphi, depth and type */
CFCDetId(ForwardSubdetector subdet, int ieta, int iphi, int depth, int type);
/** Constructor from a generic cell id */
CFCDetId(const DetId& id);
/** Assignment from a generic cell id */
Expand All @@ -30,7 +30,9 @@ class CFCDetId : public DetId {
/// get the cell iphi
int iphi() const { return id_&0x3FF; }
/// get the tower depth
int depth() const { return (id_>>20)&0xF; }
int depth() const { return (id_>>21)&0x7; }
/// get the fibre type
int type() const { return (id_>>20)&0x1; }

static const CFCDetId Undefined;

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/ForwardDetId/interface/ForwardSubdetector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef DataFormats_ForwardDetId_ForwardSubDetector_H
#define DataFormats_ForwardDetId_ForwardSubDetector_H 1

enum ForwardSubdetector { ForwardEmpty=0, ForwardCFC=1, ForwardBHM=2};
enum ForwardSubdetector { ForwardEmpty=0, ForwardCFC=1, ForwardBHM=2, HGCEE=3, HGCHE=4};

#endif
42 changes: 42 additions & 0 deletions DataFormats/ForwardDetId/interface/HGCEEDetId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef DataFormats_ForwardDetId_HGCEEDetId_H
#define DataFormats_ForwardDetId_HGCEEDetId_H 1

#include <iosfwd>
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"


class HGCEEDetId : public DetId {
public:
enum { Subdet=HGCEE};
/** Create a null cellid*/
HGCEEDetId();
/** Create cellid from raw id (0=invalid tower id) */
HGCEEDetId(uint32_t rawid);
/** Constructor from subdetector, zplus, layer, module, cell numbers */
HGCEEDetId(ForwardSubdetector subdet, int zp, int lay, int mod,
int cellx, int celly);
/** Constructor from a generic cell id */
HGCEEDetId(const DetId& id);
/** Assignment from a generic cell id */
HGCEEDetId& operator=(const DetId& id);

/// get the subdetector
ForwardSubdetector subdet() const { return HGCEE; }
/// get the z-side of the cell (1/-1)
int zside() const { return (id_&0x1000000)?(1):(-1); }
/// get the absolute value of the cell #'s in x and y
int cellX() const { return (id_>>6)&0x3F; }
int cellY() const { return id_&0x3F; }
/// get the module #
int module() const { return (id_>>12)&0x3F; }
/// get the layer #
int layer() const { return (id_>>18)&0x3F; }

static const HGCEEDetId Undefined;

};

std::ostream& operator<<(std::ostream&,const HGCEEDetId& id);

#endif
43 changes: 43 additions & 0 deletions DataFormats/ForwardDetId/interface/HGCHEDetId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef DataFormats_ForwardDetId_HGCHEDetId_H
#define DataFormats_ForwardDetId_HGCHEDetId_H 1

#include <iosfwd>
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"


class HGCHEDetId : public DetId {
public:
enum { Subdet=HGCHE};
/** Create a null cellid*/
HGCHEDetId();
/** Create cellid from raw id (0=invalid tower id) */
HGCHEDetId(uint32_t rawid);
/** Constructor from subdetector, zplus, layer, module, cell numbers */
HGCHEDetId(ForwardSubdetector subdet, int zp, int lay, int mod,
int cellx, int celly);
/** Constructor from a generic cell id */
HGCHEDetId(const DetId& id);
/** Assignment from a generic cell id */
HGCHEDetId& operator=(const DetId& id);

/// get the subdetector
ForwardSubdetector subdet() const { return HGCHE; }
/// get the z-side of the cell (1/-1)
int zside() const { return (id_&0x1000000)?(1):(-1); }
/// get the absolute value of the cell #'s in x and y
int cellX() const { return (id_>>6)&0x3F; }
int cellY() const { return id_&0x3F; }
/// get the module #
int module() const { return (id_>>12)&0x3F; }
/// get the layer #
int layer() const { return (id_>>18)&0x3F; }

static const HGCHEDetId Undefined;

};

std::ostream& operator<<(std::ostream&,const HGCHEDetId& id);

#endif

9 changes: 5 additions & 4 deletions DataFormats/ForwardDetId/src/CFCDetId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
#include "FWCore/Utilities/interface/Exception.h"
#include <ostream>

const CFCDetId CFCDetId::Undefined(ForwardEmpty,0,0,0);
const CFCDetId CFCDetId::Undefined(ForwardEmpty,0,0,0,0);

CFCDetId::CFCDetId() : DetId() {
}

CFCDetId::CFCDetId(uint32_t rawid) : DetId(rawid) {
}

CFCDetId::CFCDetId(ForwardSubdetector subdet, int ieta, int iphi, int depth) : DetId(Forward,subdet) {
CFCDetId::CFCDetId(ForwardSubdetector subdet, int ieta, int iphi, int depth,
int type) : DetId(Forward,subdet) {
// (no checking at this point!)
id_ |= ((depth&0xF)<<20) |
id_ |= ((depth&0x7)<<21) | ((type&0x1)<20) |
((ieta>0)?(0x1000000|((ieta&0x3FF)<<10)):(((-ieta)&0x3FF)<<10)) |
(iphi&0x3FF);
}
Expand Down Expand Up @@ -40,7 +41,7 @@ CFCDetId& CFCDetId::operator=(const DetId& gen) {

std::ostream& operator<<(std::ostream& s,const CFCDetId& id) {
switch (id.subdet()) {
case(ForwardCFC) : return s << "(CFC " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
case(ForwardCFC) : return s << "(CFC " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ',' << id.type() << ')';
default : return s << id.rawId();
}
}
Expand Down

0 comments on commit e2af6f5

Please sign in to comment.