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

Hcal 2017 DB Writer and Reader Fix #16211

Merged
merged 3 commits into from Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
210 changes: 104 additions & 106 deletions CondTools/Geometry/plugins/calowriters.cc
Expand Up @@ -14,49 +14,49 @@ template<>
CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::PtrType
CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::produceAligned( const typename HcalGeometry::AlignedRecord& iRecord )
{
const Alignments* alignPtr ( 0 ) ;
const Alignments* globalPtr ( 0 ) ;
const Alignments* alignPtr( 0 );
const Alignments* globalPtr( 0 );
if( m_applyAlignment ) // get ptr if necessary
{
edm::ESHandle< Alignments > alignments ;
iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;

assert( alignments.isValid() && // require valid alignments and expected size
( alignments->m_align.size() == HcalGeometry::numberOfAlignments() ) ) ;
alignPtr = alignments.product() ;

edm::ESHandle< Alignments > globals ;
iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;

assert( globals.isValid() ) ;
globalPtr = globals.product() ;
edm::ESHandle< Alignments > alignments;
iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments );
assert( alignments.isValid() && // require valid alignments and expected size
( alignments->m_align.size() == HcalGeometry::numberOfAlignments()));
alignPtr = alignments.product();
edm::ESHandle< Alignments > globals;
iRecord.getRecord<GlobalPositionRcd>().get( globals );
assert( globals.isValid());
globalPtr = globals.product();
}

TrVec tvec ;
DimVec dvec ;
IVec ivec ;
IVec dins ;
TrVec tvec;
DimVec dvec;
IVec ivec;
IVec dins;

if( CaloGeometryDBWriter::writeFlag() )
if( CaloGeometryDBWriter::writeFlag())
{
edm::ESHandle<CaloSubdetectorGeometry> pG ;
iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ;
edm::ESHandle<CaloSubdetectorGeometry> pG;
iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG );

const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;

pGptr->getSummary( tvec, ivec, dvec, dins ) ;
const CaloSubdetectorGeometry* pGptr( pG.product());
pGptr->getSummary( tvec, ivec, dvec, dins );

CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString());
}
else
{
edm::ESHandle<PCaloGeometry> pG ;
iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ;
edm::ESHandle<PCaloGeometry> pG;
iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG );

tvec = pG->getTranslation() ;
dvec = pG->getDimension() ;
ivec = pG->getIndexes() ;
dins = pG->getDenseIndices();
tvec = pG->getTranslation();
dvec = pG->getDimension();
ivec = pG->getIndexes();
dins = pG->getDenseIndices();
}
//*********************************************************************************************

Expand All @@ -67,105 +67,103 @@ CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::produceAligned( const type
// so, this check is temporary disabled. We need to implement
// a way either to store or calculate the number of shapes or be able
// to deal with only max numer of shapes.
assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
HcalGeometry* hcg=new HcalGeometry( *hcalTopology );
PtrType ptr ( hcg );
assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape );
HcalGeometry* hcalGeometry = new HcalGeometry( *hcalTopology );
PtrType ptr( hcalGeometry );

const unsigned int nTrParm ( tvec.size()/hcalTopology->ncells() ) ;
const unsigned int nTrParm( hcalGeometry->numberOfTransformParms());

ptr->fillDefaultNamedParameters() ;

ptr->allocateCorners( hcalTopology->ncells() + hcalTopology->getHFSize() ) ;

ptr->allocatePar( dvec.size() ,
HcalGeometry::k_NumberOfParametersPerShape ) ;
ptr->fillDefaultNamedParameters();
ptr->allocateCorners( hcalTopology->ncells() + hcalTopology->getHFSize());
ptr->allocatePar( hcalGeometry->numberOfShapes(),
HcalGeometry::k_NumberOfParametersPerShape );

for( unsigned int i ( 0 ) ; i < dins.size(); ++i )
{
const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape ) ;
DimVec dims ;
dims.reserve( nPerShape ) ;

const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
const unsigned int nPerShape( HcalGeometry::k_NumberOfParametersPerShape );
DimVec dims;
dims.reserve( nPerShape );

DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
const unsigned int indx( ivec.size() == 1 ? 0 : i );

for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
{
dims.push_back( *dsrc ) ;
++dsrc ;
}
DimVec::const_iterator dsrc( dvec.begin() + ivec[indx] * nPerShape );

const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
ptr->parMgr(),
ptr->parVecVec() ) ) ;
for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
{
dims.push_back( *dsrc );
++dsrc ;
}

const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
ptr->parMgr(),
ptr->parVecVec()));

const DetId id ( hcalTopology->denseId2detId(dins[i]) ) ;
const DetId id( hcalTopology->denseId2detId( dins[i]));

const unsigned int iGlob ( 0 == globalPtr ? 0 :
HcalGeometry::alignmentTransformIndexGlobal( id ) ) ;
const unsigned int iGlob( 0 == globalPtr ? 0 :
HcalGeometry::alignmentTransformIndexGlobal( id ));

assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
assert( 0 == globalPtr || iGlob < globalPtr->m_align.size());

const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
const AlignTransform* gt( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ]);

assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId())));

const unsigned int iLoc ( 0 == alignPtr ? 0 :
HcalGeometry::alignmentTransformIndexLocal( id ) ) ;
const unsigned int iLoc( 0 == alignPtr ? 0 :
HcalGeometry::alignmentTransformIndexLocal( id ));

assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
assert( 0 == alignPtr || iLoc < alignPtr->m_align.size());

const AlignTransform* at ( 0 == alignPtr ? 0 :
&alignPtr->m_align[ iLoc ] ) ;
const AlignTransform* at( 0 == alignPtr ? 0 :
&alignPtr->m_align[ iLoc ]);

assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId())) == iLoc ));

Pt3D lRef ;
Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
hcg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
Pt3D lRef;
Pt3DVec lc( 8, Pt3D( 0, 0, 0 ));
hcalGeometry->localCorners( lc, &dims.front(), dins[i], lRef );

const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
const Pt3D lCor ( lc[0] ) ;
const Pt3D lBck( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] )); // ctr rear face in local
const Pt3D lCor( lc[0] ) ;

//----------------------------------- create transform from 6 numbers ---
const unsigned int jj ( dins[i]*nTrParm ) ;
//----------------------------------- create transform from 6 numbers ---
const unsigned int jj( i * nTrParm );

Tr3D tr ;
const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
const ROOT::Math::EulerAngles ea (
6==nTrParm ?
ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
ROOT::Math::EulerAngles() ) ;
const ROOT::Math::Transform3D rt ( ea, tl ) ;
double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
yx, yy, yz,
zx, zy, zz ),
CLHEP::Hep3Vector(dx,dy,dz) );

// now prepend alignment(s) for final transform
const Tr3D atr ( 0 == at ? tr :
( 0 == gt ? at->transform()*tr :
at->transform()*gt->transform()*tr ) ) ;
//--------------------------------- done making transform ---------------

const Pt3D gRef ( atr*lRef ) ;
const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
const Pt3D gBck ( atr*lBck ) ;
const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
const Pt3D gCor ( atr*lCor ) ;
const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;

assert( hcalTopology->detId2denseId(id) == dins[i] );
ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
Tr3D tr;
const ROOT::Math::Translation3D tl( tvec[jj], tvec[jj+1], tvec[jj+2] );
const ROOT::Math::EulerAngles ea( 6 == nTrParm ?
ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
ROOT::Math::EulerAngles());
const ROOT::Math::Transform3D rt( ea, tl );
double xx, xy, xz, dx;
double yx, yy, yz, dy;
double zx, zy, zz, dz;
rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
yx, yy, yz,
zx, zy, zz ),
CLHEP::Hep3Vector( dx, dy, dz ));

// now prepend alignment(s) for final transform
const Tr3D atr( 0 == at ? tr :
( 0 == gt ? at->transform() * tr :
at->transform() * gt->transform() * tr ));
//--------------------------------- done making transform ---------------

const Pt3D gRef( atr*lRef );
const GlobalPoint fCtr( gRef.x(), gRef.y(), gRef.z());
const Pt3D gBck( atr*lBck );
const GlobalPoint fBck( gBck.x(), gBck.y(), gBck.z());
const Pt3D gCor( atr*lCor );
const GlobalPoint fCor( gCor.x(), gCor.y(), gCor.z());

assert( hcalTopology->detId2denseId(id) == dins[i] );
ptr->newCell( fCtr, fBck, fCor, myParm, id );
}

ptr->initializeParms() ; // initializations; must happen after cells filled

return ptr ;
ptr->initializeParms(); // initializations; must happen after cells filled
return ptr;
}

template<>
Expand Down