Skip to content

Commit

Permalink
Merge pull request #1139 from Dr15Jones/fixStaticsDataFormatsEcalDetId
Browse files Browse the repository at this point in the history
Multithreading fixes -- Fix statics DataFormats/EcalDet
  • Loading branch information
ktf committed Oct 31, 2013
2 parents ea1143a + 4b2c7b2 commit 1ace0a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
13 changes: 11 additions & 2 deletions DataFormats/EcalDetId/interface/EcalContainer.h
Expand Up @@ -71,9 +71,8 @@ class EcalContainer {
// std::cout << "resizing to " << DetId::kSizeForDenseIndexing << std::endl;
// m_items.resize((size_t) DetId::kSizeForDenseIndexing);
// }
static Item dummy;
DetId id(rawId);
if ( !isValidId(id) ) return dummy;
if ( !isValidId(id) ) return dummy_item();
return m_items[id.hashedIndex()];
}

Expand All @@ -97,6 +96,16 @@ class EcalContainer {

private:

//Cint can't parse the new C++11 initialization syntax
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)

static const Item& dummy_item() {
static const Item s_dummy{};
return s_dummy;
}
#else
static const Item& dummy_item();
#endif
// not protected on EB <--> EE swap -- FIXME?
inline bool isValidId(const DetId id) const {
return id.det() == ::DetId::Ecal;
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/EcalDetId/src/EEDetId.cc
Expand Up @@ -303,7 +303,7 @@ EEDetId::isc( int jx, int jy )
const int iCol = ( 1 == iquad || 4 == iquad ? jx - 10 : 11 - jx ) ;
const int iRow = ( 1 == iquad || 2 == iquad ? jy - 10 : 11 - jy ) ;

static int nSCinQuadrant = ISC_MAX/4;
static const int nSCinQuadrant = ISC_MAX/4;

const int yOff ( iYoffset[iCol] ) ;

Expand Down
27 changes: 15 additions & 12 deletions DataFormats/EcalDetId/src/EcalScDetId.cc
Expand Up @@ -3,6 +3,7 @@

#include <ostream>
#include <cassert>
#include <mutex>

short EcalScDetId::xyz2HashedIndex[EcalScDetId::IX_MAX][EcalScDetId::IY_MAX][EcalScDetId::nEndcaps];

Expand Down Expand Up @@ -90,20 +91,22 @@ std::ostream& operator<<(std::ostream& s,const EcalScDetId& id) {
return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
}

//NOTE: When looping is possible in constexpr, this should be changed to one
static std::once_flag initializedFlag;
void EcalScDetId::checkHashedIndexMap(){
static bool initialized = false;
if(initialized) return;
int hashedIndex = -1;
for(int iZ = -1; iZ <= +1; iZ+=2){
for(int iY = IY_MIN; iY <= IY_MAX; ++iY){
for(int iX = IX_MIN; iX <= IX_MAX; ++iX){
if(validDetId(iX,iY,iZ)){
xyz2HashedIndex[iX-IX_MIN][iY-IY_MIN][iZ>0?1:0] = ++hashedIndex;
assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId)/sizeof(hashedIndex2DetId[0]));
hashedIndex2DetId[hashedIndex] = EcalScDetId(iX, iY, iZ);
std::call_once(initializedFlag, []()
{
int hashedIndex = -1;
for(int iZ = -1; iZ <= +1; iZ+=2){
for(int iY = IY_MIN; iY <= IY_MAX; ++iY){
for(int iX = IX_MIN; iX <= IX_MAX; ++iX){
if(validDetId(iX,iY,iZ)){
xyz2HashedIndex[iX-IX_MIN][iY-IY_MIN][iZ>0?1:0] = ++hashedIndex;
assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId)/sizeof(hashedIndex2DetId[0]));
hashedIndex2DetId[hashedIndex] = EcalScDetId(iX, iY, iZ);
}
}
}
}
}
initialized = true;
});
}

0 comments on commit 1ace0a0

Please sign in to comment.