Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions Algorithm/include/Algorithm/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,30 @@ class ForwardParser
{
static_assert(sizeof(InputType) == 1,
"ForwardParser currently only supports byte type buffer");
if (buffer == nullptr || bufferSize == 0)
if (buffer == nullptr || bufferSize == 0) {
return 0;
}

size_t position = 0;
std::vector<FrameInfo> frames;
do {
FrameInfo entry;

// check the header
if (sizeof(HeaderType) + position > bufferSize)
if (sizeof(HeaderType) + position > bufferSize) {
break;
}
entry.header = reinterpret_cast<const HeaderType*>(buffer + position);
if (!checkHeader(*entry.header))
if (!checkHeader(*entry.header)) {
break;
}

// extract frame size from header, this is expected to be the
// total frome size including header, payload and optional trailer
auto frameSize = getFrameSize(*entry.header);
if (frameSize + position > bufferSize)
if (frameSize + position > bufferSize) {
break;
}

// payload starts right after the header
entry.payload = reinterpret_cast<typename FrameInfo::PtrT>(entry.header + 1);
Expand All @@ -188,8 +193,9 @@ class ForwardParser
} else {
auto trailerStart = buffer + position + frameSize - tailOffset;
entry.trailer = reinterpret_cast<const TrailerType*>(trailerStart);
if (!CheckTrailer(entry, checkTrailer))
if (!CheckTrailer(entry, checkTrailer)) {
break;
}
}

// store the extracted frame info and continue with remaining buffer
Expand All @@ -201,8 +207,9 @@ class ForwardParser
// frames found and format consistent, insert entries to target
// Note: the complete block must be consistent
for (auto entry : frames) {
if (!insert(entry))
if (!insert(entry)) {
break;
}
}
return frames.size();
} else if (frames.size() == 0) {
Expand Down Expand Up @@ -332,30 +339,35 @@ class ReverseParser
{
static_assert(sizeof(InputType) == 1,
"ReverseParser currently only supports byte type buffer");
if (buffer == nullptr || bufferSize == 0)
if (buffer == nullptr || bufferSize == 0) {
return 0;
}
auto position = bufferSize;
std::vector<FrameInfo> frames;
do {
FrameInfo entry;

// start from end, extract and check trailer
if (sizeof(TrailerType) > position)
if (sizeof(TrailerType) > position) {
break;
}
entry.trailer = reinterpret_cast<const TrailerType*>(buffer + position - sizeof(TrailerType));
if (!checkTrailer(*entry.trailer))
if (!checkTrailer(*entry.trailer)) {
break;
}

// get the total frame size
auto frameSize = getFrameSize(*entry.trailer);
if (frameSize > position)
if (frameSize > position) {
break;
}

// extract and check header
auto headerStart = buffer + position - frameSize;
entry.header = reinterpret_cast<const HeaderType*>(headerStart);
if (!checkHeader(*entry.header))
if (!checkHeader(*entry.header)) {
break;
}

// payload immediately after header
entry.payload = reinterpret_cast<typename FrameInfo::PtrT>(entry.header + 1);
Expand All @@ -367,8 +379,9 @@ class ReverseParser
if (position == 0) {
// frames found and format consistent, the complete block must be consistent
for (auto entry : frames) {
if (!insert(entry))
if (!insert(entry)) {
break;
}
}
return frames.size();
} else if (frames.size() == 0) {
Expand Down
30 changes: 20 additions & 10 deletions Algorithm/include/Algorithm/TableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class TableView

bool operator<(const FrameIndex& rh) const
{
if (rh.columnIndex < columnIndex)
if (rh.columnIndex < columnIndex) {
return false;
if (columnIndex < rh.columnIndex)
}
if (columnIndex < rh.columnIndex) {
return true;
}
return row < rh.row;
}
};
Expand Down Expand Up @@ -143,8 +145,9 @@ class TableView
/// get row data for a data set
const RowDescType& getRowData(size_t row) const
{
if (row < mRowData.size())
if (row < mRowData.size()) {
return mRowData[row];
}
// TODO: better to throw exception?
static RowDescType dummy;
return dummy;
Expand Down Expand Up @@ -180,22 +183,26 @@ class TableView
iterator(IteratorDirections direction, TableView* parent, unsigned row = 0, unsigned column = 0)
: mDirection(direction), mRow(row), mColumn(column), mEnd(direction == kAlongRow ? parent->getNColumns() : parent->getNRows()), mParent(parent), mCache(), mIsCached(false)
{
while (!isValid() && !isEnd())
while (!isValid() && !isEnd()) {
operator++();
}
}

self_type& operator++()
{
mIsCached = false;
if (mDirection == kAlongRow) {
if (mColumn < mEnd)
if (mColumn < mEnd) {
mColumn++;
}
} else {
if (mRow < mEnd)
if (mRow < mEnd) {
mRow++;
}
}
while (!isEnd() && !isValid())
while (!isEnd() && !isValid()) {
operator++();
}
return *this;
}

Expand Down Expand Up @@ -265,11 +272,13 @@ class TableView
self_type& operator++()
{
if (base::mDirection == iterator::kAlongRow) {
if (base::mColumn < base::mEnd)
if (base::mColumn < base::mEnd) {
base::mColumn++;
}
} else {
if (base::mRow < base::mEnd)
if (base::mRow < base::mEnd) {
base::mRow++;
}
}
return *this;
}
Expand Down Expand Up @@ -314,8 +323,9 @@ class TableView
/// private access function for the iterators
bool get(unsigned row, unsigned column, FrameData& data)
{
if (this->mColumns.size() == 0)
if (this->mColumns.size() == 0) {
return false;
}
auto element = this->mFrames.find(FrameIndex{this->mColumns[column], row});
if (element != this->mFrames.end()) {
data = element->second;
Expand Down
3 changes: 2 additions & 1 deletion Algorithm/test/pageparser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ std::pair<std::unique_ptr<uint8_t[]>, size_t> MakeBuffer(size_t pagesize,
} while (nPages * pagesize < totalSize);
} else {
auto nRequiredPages = dataset.size() / maxElementsPerPage;
if (dataset.size() % maxElementsPerPage > 0)
if (dataset.size() % maxElementsPerPage > 0) {
++nRequiredPages;
}
totalSize = (nRequiredPages > 0 ? nRequiredPages : 1) * pagesize;
}

Expand Down
3 changes: 2 additions & 1 deletion CCDB/include/CCDB/BasicCCDBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ T* BasicCCDBManager::getForTimeStamp(std::string const& path, long timestamp)
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
}
auto& cached = mCache[path];
if (mCheckObjValidityEnabled && cached.isValid(timestamp))
if (mCheckObjValidityEnabled && cached.isValid(timestamp)) {
return reinterpret_cast<T*>(cached.objPtr.get());
}

T* ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, cached.uuid,
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
Expand Down
25 changes: 16 additions & 9 deletions Common/Field/src/MagFieldFast.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,25 @@ bool MagFieldFast::LoadData(const string inpFName)
SolParam* curParam = nullptr;

while (std::getline(in, line)) {
if (line.empty() || line[0] == '#')
if (line.empty() || line[0] == '#') {
continue; // empy or comment
}
std::stringstream ss(line);
int cnt = 0;

if (component < 0) {
while (cnt < 4 && (ss >> header[cnt++]))
while (cnt < 4 && (ss >> header[cnt++])) {
;
}
if (cnt != 4) {
LOG(FATAL) << "Wrong header " << line;
return false;
}
curParam = &mSolPar[header[0]][header[1]][header[2]];
} else {
while (cnt < header[3] && (ss >> curParam->parBxyz[component][cnt++]))
while (cnt < header[3] && (ss >> curParam->parBxyz[component][cnt++])) {
;
}
if (cnt != header[3]) {
LOG(FATAL) << "Wrong data (npar=" << cnt << ") for param " << header[0] << " " << header[1] << " " << header[2]
<< " " << header[3] << " " << line;
Expand Down Expand Up @@ -215,20 +218,24 @@ bool MagFieldFast::GetSegment(float x, float y, float z, int& zSeg, int& rSeg, i
const float zGridSpaceInv = 1.f / (kSolZMax * 2 / kNSolZRanges);
zSeg = -1;
if (z < kSolZMax) {
if (z > -kSolZMax)
if (z > -kSolZMax) {
zSeg = (z + kSolZMax) * zGridSpaceInv; // solenoid params
else { // need to check dipole params
} else { // need to check dipole params
return false;
}
} else
} else {
return false;
}
// R segment
float xx = x * x, yy = y * y, rr = xx + yy;
for (rSeg = 0; rSeg < kNSolRRanges; rSeg++)
if (rr < kSolR2Max[rSeg])
for (rSeg = 0; rSeg < kNSolRRanges; rSeg++) {
if (rr < kSolR2Max[rSeg]) {
break;
if (rSeg == kNSolRRanges)
}
}
if (rSeg == kNSolRRanges) {
return kFALSE;
}
quadrant = GetQuadrant(x, y);
return true;
}
30 changes: 20 additions & 10 deletions Common/Field/src/MagFieldParam.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ void MagFieldParam::SetParam(const MagneticField* field)
void MagFieldParam::putParams(FairParamList* list)
{
/// store parameters in the list
if (!list)
if (!list) {
return;
}
list->add("Map Type ID", int(mMapType));
list->add("Beam Type ID", int(mBeamType));
list->add("Integral Type", mDefaultIntegration);
Expand All @@ -65,33 +66,42 @@ Bool_t MagFieldParam::getParams(FairParamList* list)
{
/// retried parameters
int int2enum = 0;
if (!list->fill("Map Type ID", &int2enum))
if (!list->fill("Map Type ID", &int2enum)) {
return kFALSE;
}
mMapType = static_cast<BMap_t>(int2enum);
if (!list->fill("Beam Type ID", &int2enum))
if (!list->fill("Beam Type ID", &int2enum)) {
return kFALSE;
}
mBeamType = static_cast<BeamType_t>(int2enum);
//
if (!list->fill("Integral Type", &mDefaultIntegration))
if (!list->fill("Integral Type", &mDefaultIntegration)) {
return kFALSE;
if (!list->fill("Fact.Solenoid", &mFactorSol))
}
if (!list->fill("Fact.Solenoid", &mFactorSol)) {
return kFALSE;
if (!list->fill("Fact.Dipole ", &mFactorDip))
}
if (!list->fill("Fact.Dipole ", &mFactorDip)) {
return kFALSE;
if (!list->fill("Beam Energy ", &mBeamEnergy))
}
if (!list->fill("Beam Energy ", &mBeamEnergy)) {
return kFALSE;
if (!list->fill("Max. Field ", &mMaxField))
}
if (!list->fill("Max. Field ", &mMaxField)) {
return kFALSE;
}
FairParamObj* parpath = list->find("Path to map ");
if (!parpath)
if (!parpath) {
return kFALSE;
}
int lgt = parpath->getLength();
// RS: is there a bug in FairParamList::fill(const Text_t* name,Text_t* value,const Int_t length)?
// I think the "if (l<length-1)" should be "if (l<length)"
char cbuff[lgt + 2];
memset(cbuff, 0, sizeof(char) * (lgt + 2));
if (!list->fill("Path to map ", cbuff, lgt + 2))
if (!list->fill("Path to map ", cbuff, lgt + 2)) {
return kFALSE;
}
mMapPath = cbuff;
return kTRUE;
}
Loading