Skip to content

Commit

Permalink
formating, BuildFile cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JanChyczynski committed Jan 23, 2025
1 parent 052b7b6 commit 7ca3497
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 57 deletions.
3 changes: 0 additions & 3 deletions CondCore/CondDB/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<flags CXXFLAGS="-O0 -g"/>
<use name="CondFormats/Serialization"/>
<use name="CondFormats/Common"/>
<use name="CondFormats/BeamSpotObjects"/>
<use name="DataFormats/​BeamSpot"/>
<use name="RecoVertex/VertexPrimitives"/>
<!-- <use name="CondFormats/RunInfo"/> -->
<use name="FWCore/Framework"/>
<use name="Utilities/OpenSSL"/>
<use name="boost"/>
Expand Down
122 changes: 69 additions & 53 deletions CondCore/CondDB/src/IOVProxy.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <memory>

#include "CondCore/CondDB/interface/IOVProxy.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondCore/CondDB/interface/Session.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "RecoVertex/VertexPrimitives/interface/VertexState.h"
#include "SessionImpl.h"

Expand Down Expand Up @@ -299,18 +299,17 @@ namespace cond {
if (!m_session->isTransactionActive(false))
throwException("The transaction is not active.", ctx);
}
reco::BeamSpot beamSpotFromBSOnlineObjects(std::unique_ptr<BeamSpotOnlineObjects> const &beamspotObj) {
//TODO Is that a good way to set up a debug mode?
// Is that even needed for final PR or should it be treated temporarty and remove before merging?
// If it would be merged with the debug mode it should probably be improved
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG

reco::BeamSpot beamSpotFromBSOnlineObjects(std::unique_ptr<BeamSpotOnlineObjects> const& beamspotObj) {
//TODO Is that a good way to set up a debug mode?
// Is that even needed for final PR or should it be treated temporarty and remove before merging?
// If it would be merged with the debug mode it should probably be improved
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
static int testCaseNr = 0;
const double invalidMatrix[][3] = { //Invalid non-0 matrix that appeared in crash logs
{0, 0, -4.84531e-151},
{0, 0, 0},
{-4.84531e-151, 0, 1.06053e-07}
};
const double invalidMatrix[][3] = {//Invalid non-0 matrix that appeared in crash logs
{0, 0, -4.84531e-151},
{0, 0, 0},
{-4.84531e-151, 0, 1.06053e-07}};
#endif
bool changeFrame = false;
double f = changeFrame ? -1.0 : 1.0;
Expand All @@ -320,15 +319,16 @@ namespace cond {
for (int i = 0; i < reco::BeamSpot::dimension; ++i) {
for (int j = 0; j < reco::BeamSpot::dimension; ++j) {
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
switch(testCaseNr) {
switch (testCaseNr) {
case 0:
matrix(i, j) = beamspotObj->covariance(i, j);
break;
case 1:
matrix(i, j) = 0;
break;
case 2:
if (i < 3 && j < 3) matrix(i, j) = invalidMatrix[i][j];
if (i < 3 && j < 3)
matrix(i, j) = invalidMatrix[i][j];
break;
}
#else
Expand All @@ -338,13 +338,17 @@ namespace cond {
}

#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
if(testCaseNr == 3) {
if (testCaseNr == 3) {
return reco::BeamSpot();
}
testCaseNr++;
#endif
reco::BeamSpot beamSpot = reco::BeamSpot(apoint, beamspotObj->sigmaZ(), beamspotObj->dxdz(),
beamspotObj->dydz(), beamspotObj->beamWidthX(), matrix);
reco::BeamSpot beamSpot = reco::BeamSpot(apoint, // (force formatting)
beamspotObj->sigmaZ(),
beamspotObj->dxdz(),
beamspotObj->dydz(),
beamspotObj->beamWidthX(),
matrix);
beamSpot.setBeamWidthY(beamspotObj->beamWidthY());
beamSpot.setEmittanceX(beamspotObj->emittanceX());
beamSpot.setEmittanceY(beamspotObj->emittanceY());
Expand All @@ -354,58 +358,70 @@ namespace cond {

bool printBeamSpotDiagnostics(std::shared_ptr<IOVProxyData> iovProxyData,
std::shared_ptr<SessionImpl> sessionImpl,
cond::Time_t lowerGroup, cond::Time_t higherGroup) {
cond::Time_t lowerGroup,
cond::Time_t higherGroup) {
bool printedDiagnostics = false;
if (iovProxyData->tagInfo.payloadType == "BeamSpotOnlineObjects") {
if (iovProxyData->tagInfo.payloadType == "BeamSpotOnlineObjects") { //TODO refactor avoid unecessary nesting
cond::persistency::Session session(sessionImpl);
session.transaction().start(true);
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
int iSeq = 0;
#endif
for(const auto& [iov, hash] : iovProxyData->iovSequence) {
for (const auto& [iov, hash] : iovProxyData->iovSequence) {
std::unique_ptr<BeamSpotOnlineObjects> beamspotObj = session.fetchPayload<BeamSpotOnlineObjects>(hash);
reco::BeamSpot beamSpot = beamSpotFromBSOnlineObjects(beamspotObj);

//Check validity of BeamSpot by validating error of VertexState created from it
VertexState beamVertexState(beamSpot);
bool vertexFromBSInvalid = (beamVertexState.error().cxx() <= 0.) || (beamVertexState.error().cyy() <= 0.) ||
(beamVertexState.error().czz() <= 0.);
(beamVertexState.error().czz() <= 0.);

//Check validity of BeamSpot by confirming it can be inverted
int inversionFail = 2; //the .Inverse(...) will set it to 0 or 1
int inversionFail = 2; //the .Inverse(...) will set it to 0 or 1
reco::BeamSpot::CovarianceMatrix errorInverse = beamSpot.covariance().Inverse(inversionFail);

double det; //TODO do we check BS validity by det?
double det; //TODO do we check BS validity by det?
beamSpot.covariance().Det2(det);
if(vertexFromBSInvalid || inversionFail) {
edm::LogSystem("NewIOV") <<
"\n--------------------- BeamSpot Diagnostics (hash: " << hash << ") ----------------\n" <<
"Fetched invalid beamspot obj of hash " << hash << "\n" <<
"Tag: " << iovProxyData->tagInfo.name << "\n"
"IOV: " << iov << "(" << cond::time::timeTypeName(iovProxyData->tagInfo.timeType) << ")\n"
"Request info: " << "' request interval [ " << lowerGroup << " , " << higherGroup << " ] " <<
"new range [ " << iovProxyData->groupLowerIov << " , " << iovProxyData->groupHigherIov << " ] "
"#entries " << iovProxyData->iovSequence.size() << "\n" <<
"\n"
"BeamSpotOnlineObjects:" << *beamspotObj << "\n" <<
"BeamSpot:\n" << beamSpot << "\n" << //TODO probably no new info here, enough to preant only BeamSpotOnlineObjects
"BeamSpot (BS) rotatedCovariance3D:\n" << beamSpot.rotatedCovariance3D() << "\n" <<
"BS position:\n" << beamSpot.position() << "\n" <<
"BS covariance Determinant: " << det << "\n" <<
"Of matrix: \n" << beamSpot.covariance() << "\n" <<
"is VertexState(BS).error() invalid? (0=valid): " << vertexFromBSInvalid << "\n" <<
"VertexState(BS).error().matrix(): \n" << beamVertexState.error().matrix() << "\n" <<
"err cxx() = " << beamVertexState.error().cxx() << "\n" <<
"err cyy() = " << beamVertexState.error().cyy() << "\n" <<
"err czz() = " << beamVertexState.error().czz() << "\n" <<
"did BS.covariance() inversion failed? (0=ok, 1=failed): " << inversionFail << "\n" <<
"BS.covariance().Inverse():\n"<< errorInverse << "\n" <<
"\n-------------- end of BeamSpot Diagnostics (hash: " << hash << ") ----------------\n" <<
std::endl;
//TODO probably can be refactored to avoid unecessary nesting
if (vertexFromBSInvalid || inversionFail) {
std::ostringstream s; //tmp, just for better code formatting
s << "\n--------------------- BeamSpot Diagnostics (hash: " << hash << ") ----------------\n"
<< "Fetched invalid beamspot obj of hash " << hash << "\n"
<< "Tag: " << iovProxyData->tagInfo.name << "\n"
<< "IOV: " << iov << "(" << cond::time::timeTypeName(iovProxyData->tagInfo.timeType) << ")\n"
<< "Request info: "
<< "' request interval [ " << lowerGroup << " , " << higherGroup << " ] "
<< "new range [ " << iovProxyData->groupLowerIov << " , " << iovProxyData->groupHigherIov << " ] "
<< "#entries " << iovProxyData->iovSequence.size() << "\n"
<< "\n"
<< "BeamSpotOnlineObjects:\n"
<< *beamspotObj
<< "\n"
//TODO probably no new info here, enough to preant only BeamSpotOnlineObjects
<< "BeamSpot:\n"
<< beamSpot << "\n"
<< "BeamSpot (BS) rotatedCovariance3D:\n"
<< beamSpot.rotatedCovariance3D() << "\n"
<< "BS position: " << beamSpot.position() << "\n"
<< "BS covariance Determinant: " << det << "\n"
<< "Of matrix: " << beamSpot.covariance() << "\n"
<< "is VertexState(BS).error() invalid? (0=valid): " << vertexFromBSInvalid << "\n"
<< "VertexState(BS).error().matrix(): \n"
<< beamVertexState.error().matrix() << "\n"
<< "err cxx() = " << beamVertexState.error().cxx() << "\n"
<< "err cyy() = " << beamVertexState.error().cyy() << "\n"
<< "err czz() = " << beamVertexState.error().czz() << "\n"
<< "did BS.covariance() inversion failed? (0=ok, 1=failed): " << inversionFail << "\n"
<< "BS.covariance().Inverse():\n"
<< errorInverse << "\n"
<< "\n-------------- end of BeamSpot Diagnostics (hash: " << hash << ") ----------------\n"
<< std::endl;
edm::LogSystem("NewIOV") << s.str();
printedDiagnostics = true;
}
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
if(iSeq >= 3) break;
if (iSeq >= 3)
break;
iSeq++;
#endif
}
Expand Down Expand Up @@ -436,9 +452,9 @@ namespace cond {
}
}
#ifdef BEAM_SPOT_DIAGNOSTICS_DEBUG
if(printBeamSpotDiagnostics(m_data, m_session, lowerGroup, higherGroup)){
std::exit(0);
}
if (printBeamSpotDiagnostics(m_data, m_session, lowerGroup, higherGroup)) {
std::exit(0); //To avoid long exection of unrelated code after diagnostics got printed
}
#else
printBeamSpotDiagnostics(m_data, m_session, lowerGroup, higherGroup);
#endif
Expand Down
1 change: 0 additions & 1 deletion CondFormats/BeamSpotObjects/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<flags CXXFLAGS="-O0 -g"/>
<use name="CondFormats/Serialization"/>
<use name="FWCore/Utilities"/>
<use name="CondFormats/Common"/>
Expand Down

0 comments on commit 7ca3497

Please sign in to comment.