Skip to content

Commit b7bb4e9

Browse files
authored
Algorithm Common: add braces to single statements (AliceO2Group#4567)
1 parent b0539d3 commit b7bb4e9

16 files changed

Lines changed: 167 additions & 85 deletions

File tree

Algorithm/include/Algorithm/Parser.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,30 @@ class ForwardParser
158158
{
159159
static_assert(sizeof(InputType) == 1,
160160
"ForwardParser currently only supports byte type buffer");
161-
if (buffer == nullptr || bufferSize == 0)
161+
if (buffer == nullptr || bufferSize == 0) {
162162
return 0;
163+
}
164+
163165
size_t position = 0;
164166
std::vector<FrameInfo> frames;
165167
do {
166168
FrameInfo entry;
167169

168170
// check the header
169-
if (sizeof(HeaderType) + position > bufferSize)
171+
if (sizeof(HeaderType) + position > bufferSize) {
170172
break;
173+
}
171174
entry.header = reinterpret_cast<const HeaderType*>(buffer + position);
172-
if (!checkHeader(*entry.header))
175+
if (!checkHeader(*entry.header)) {
173176
break;
177+
}
174178

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

181186
// payload starts right after the header
182187
entry.payload = reinterpret_cast<typename FrameInfo::PtrT>(entry.header + 1);
@@ -188,8 +193,9 @@ class ForwardParser
188193
} else {
189194
auto trailerStart = buffer + position + frameSize - tailOffset;
190195
entry.trailer = reinterpret_cast<const TrailerType*>(trailerStart);
191-
if (!CheckTrailer(entry, checkTrailer))
196+
if (!CheckTrailer(entry, checkTrailer)) {
192197
break;
198+
}
193199
}
194200

195201
// store the extracted frame info and continue with remaining buffer
@@ -201,8 +207,9 @@ class ForwardParser
201207
// frames found and format consistent, insert entries to target
202208
// Note: the complete block must be consistent
203209
for (auto entry : frames) {
204-
if (!insert(entry))
210+
if (!insert(entry)) {
205211
break;
212+
}
206213
}
207214
return frames.size();
208215
} else if (frames.size() == 0) {
@@ -332,30 +339,35 @@ class ReverseParser
332339
{
333340
static_assert(sizeof(InputType) == 1,
334341
"ReverseParser currently only supports byte type buffer");
335-
if (buffer == nullptr || bufferSize == 0)
342+
if (buffer == nullptr || bufferSize == 0) {
336343
return 0;
344+
}
337345
auto position = bufferSize;
338346
std::vector<FrameInfo> frames;
339347
do {
340348
FrameInfo entry;
341349

342350
// start from end, extract and check trailer
343-
if (sizeof(TrailerType) > position)
351+
if (sizeof(TrailerType) > position) {
344352
break;
353+
}
345354
entry.trailer = reinterpret_cast<const TrailerType*>(buffer + position - sizeof(TrailerType));
346-
if (!checkTrailer(*entry.trailer))
355+
if (!checkTrailer(*entry.trailer)) {
347356
break;
357+
}
348358

349359
// get the total frame size
350360
auto frameSize = getFrameSize(*entry.trailer);
351-
if (frameSize > position)
361+
if (frameSize > position) {
352362
break;
363+
}
353364

354365
// extract and check header
355366
auto headerStart = buffer + position - frameSize;
356367
entry.header = reinterpret_cast<const HeaderType*>(headerStart);
357-
if (!checkHeader(*entry.header))
368+
if (!checkHeader(*entry.header)) {
358369
break;
370+
}
359371

360372
// payload immediately after header
361373
entry.payload = reinterpret_cast<typename FrameInfo::PtrT>(entry.header + 1);
@@ -367,8 +379,9 @@ class ReverseParser
367379
if (position == 0) {
368380
// frames found and format consistent, the complete block must be consistent
369381
for (auto entry : frames) {
370-
if (!insert(entry))
382+
if (!insert(entry)) {
371383
break;
384+
}
372385
}
373386
return frames.size();
374387
} else if (frames.size() == 0) {

Algorithm/include/Algorithm/TableView.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ class TableView
6767

6868
bool operator<(const FrameIndex& rh) const
6969
{
70-
if (rh.columnIndex < columnIndex)
70+
if (rh.columnIndex < columnIndex) {
7171
return false;
72-
if (columnIndex < rh.columnIndex)
72+
}
73+
if (columnIndex < rh.columnIndex) {
7374
return true;
75+
}
7476
return row < rh.row;
7577
}
7678
};
@@ -143,8 +145,9 @@ class TableView
143145
/// get row data for a data set
144146
const RowDescType& getRowData(size_t row) const
145147
{
146-
if (row < mRowData.size())
148+
if (row < mRowData.size()) {
147149
return mRowData[row];
150+
}
148151
// TODO: better to throw exception?
149152
static RowDescType dummy;
150153
return dummy;
@@ -180,22 +183,26 @@ class TableView
180183
iterator(IteratorDirections direction, TableView* parent, unsigned row = 0, unsigned column = 0)
181184
: mDirection(direction), mRow(row), mColumn(column), mEnd(direction == kAlongRow ? parent->getNColumns() : parent->getNRows()), mParent(parent), mCache(), mIsCached(false)
182185
{
183-
while (!isValid() && !isEnd())
186+
while (!isValid() && !isEnd()) {
184187
operator++();
188+
}
185189
}
186190

187191
self_type& operator++()
188192
{
189193
mIsCached = false;
190194
if (mDirection == kAlongRow) {
191-
if (mColumn < mEnd)
195+
if (mColumn < mEnd) {
192196
mColumn++;
197+
}
193198
} else {
194-
if (mRow < mEnd)
199+
if (mRow < mEnd) {
195200
mRow++;
201+
}
196202
}
197-
while (!isEnd() && !isValid())
203+
while (!isEnd() && !isValid()) {
198204
operator++();
205+
}
199206
return *this;
200207
}
201208

@@ -265,11 +272,13 @@ class TableView
265272
self_type& operator++()
266273
{
267274
if (base::mDirection == iterator::kAlongRow) {
268-
if (base::mColumn < base::mEnd)
275+
if (base::mColumn < base::mEnd) {
269276
base::mColumn++;
277+
}
270278
} else {
271-
if (base::mRow < base::mEnd)
279+
if (base::mRow < base::mEnd) {
272280
base::mRow++;
281+
}
273282
}
274283
return *this;
275284
}
@@ -314,8 +323,9 @@ class TableView
314323
/// private access function for the iterators
315324
bool get(unsigned row, unsigned column, FrameData& data)
316325
{
317-
if (this->mColumns.size() == 0)
326+
if (this->mColumns.size() == 0) {
318327
return false;
328+
}
319329
auto element = this->mFrames.find(FrameIndex{this->mColumns[column], row});
320330
if (element != this->mFrames.end()) {
321331
data = element->second;

Algorithm/test/pageparser.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ std::pair<std::unique_ptr<uint8_t[]>, size_t> MakeBuffer(size_t pagesize,
7878
} while (nPages * pagesize < totalSize);
7979
} else {
8080
auto nRequiredPages = dataset.size() / maxElementsPerPage;
81-
if (dataset.size() % maxElementsPerPage > 0)
81+
if (dataset.size() % maxElementsPerPage > 0) {
8282
++nRequiredPages;
83+
}
8384
totalSize = (nRequiredPages > 0 ? nRequiredPages : 1) * pagesize;
8485
}
8586

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ T* BasicCCDBManager::getForTimeStamp(std::string const& path, long timestamp)
147147
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
148148
}
149149
auto& cached = mCache[path];
150-
if (mCheckObjValidityEnabled && cached.isValid(timestamp))
150+
if (mCheckObjValidityEnabled && cached.isValid(timestamp)) {
151151
return reinterpret_cast<T*>(cached.objPtr.get());
152+
}
152153

153154
T* ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, cached.uuid,
154155
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",

Common/Field/src/MagFieldFast.cxx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,25 @@ bool MagFieldFast::LoadData(const string inpFName)
6868
SolParam* curParam = nullptr;
6969

7070
while (std::getline(in, line)) {
71-
if (line.empty() || line[0] == '#')
71+
if (line.empty() || line[0] == '#') {
7272
continue; // empy or comment
73+
}
7374
std::stringstream ss(line);
7475
int cnt = 0;
7576

7677
if (component < 0) {
77-
while (cnt < 4 && (ss >> header[cnt++]))
78+
while (cnt < 4 && (ss >> header[cnt++])) {
7879
;
80+
}
7981
if (cnt != 4) {
8082
LOG(FATAL) << "Wrong header " << line;
8183
return false;
8284
}
8385
curParam = &mSolPar[header[0]][header[1]][header[2]];
8486
} else {
85-
while (cnt < header[3] && (ss >> curParam->parBxyz[component][cnt++]))
87+
while (cnt < header[3] && (ss >> curParam->parBxyz[component][cnt++])) {
8688
;
89+
}
8790
if (cnt != header[3]) {
8891
LOG(FATAL) << "Wrong data (npar=" << cnt << ") for param " << header[0] << " " << header[1] << " " << header[2]
8992
<< " " << header[3] << " " << line;
@@ -215,20 +218,24 @@ bool MagFieldFast::GetSegment(float x, float y, float z, int& zSeg, int& rSeg, i
215218
const float zGridSpaceInv = 1.f / (kSolZMax * 2 / kNSolZRanges);
216219
zSeg = -1;
217220
if (z < kSolZMax) {
218-
if (z > -kSolZMax)
221+
if (z > -kSolZMax) {
219222
zSeg = (z + kSolZMax) * zGridSpaceInv; // solenoid params
220-
else { // need to check dipole params
223+
} else { // need to check dipole params
221224
return false;
222225
}
223-
} else
226+
} else {
224227
return false;
228+
}
225229
// R segment
226230
float xx = x * x, yy = y * y, rr = xx + yy;
227-
for (rSeg = 0; rSeg < kNSolRRanges; rSeg++)
228-
if (rr < kSolR2Max[rSeg])
231+
for (rSeg = 0; rSeg < kNSolRRanges; rSeg++) {
232+
if (rr < kSolR2Max[rSeg]) {
229233
break;
230-
if (rSeg == kNSolRRanges)
234+
}
235+
}
236+
if (rSeg == kNSolRRanges) {
231237
return kFALSE;
238+
}
232239
quadrant = GetQuadrant(x, y);
233240
return true;
234241
}

Common/Field/src/MagFieldParam.cxx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ void MagFieldParam::SetParam(const MagneticField* field)
4848
void MagFieldParam::putParams(FairParamList* list)
4949
{
5050
/// store parameters in the list
51-
if (!list)
51+
if (!list) {
5252
return;
53+
}
5354
list->add("Map Type ID", int(mMapType));
5455
list->add("Beam Type ID", int(mBeamType));
5556
list->add("Integral Type", mDefaultIntegration);
@@ -65,33 +66,42 @@ Bool_t MagFieldParam::getParams(FairParamList* list)
6566
{
6667
/// retried parameters
6768
int int2enum = 0;
68-
if (!list->fill("Map Type ID", &int2enum))
69+
if (!list->fill("Map Type ID", &int2enum)) {
6970
return kFALSE;
71+
}
7072
mMapType = static_cast<BMap_t>(int2enum);
71-
if (!list->fill("Beam Type ID", &int2enum))
73+
if (!list->fill("Beam Type ID", &int2enum)) {
7274
return kFALSE;
75+
}
7376
mBeamType = static_cast<BeamType_t>(int2enum);
7477
//
75-
if (!list->fill("Integral Type", &mDefaultIntegration))
78+
if (!list->fill("Integral Type", &mDefaultIntegration)) {
7679
return kFALSE;
77-
if (!list->fill("Fact.Solenoid", &mFactorSol))
80+
}
81+
if (!list->fill("Fact.Solenoid", &mFactorSol)) {
7882
return kFALSE;
79-
if (!list->fill("Fact.Dipole ", &mFactorDip))
83+
}
84+
if (!list->fill("Fact.Dipole ", &mFactorDip)) {
8085
return kFALSE;
81-
if (!list->fill("Beam Energy ", &mBeamEnergy))
86+
}
87+
if (!list->fill("Beam Energy ", &mBeamEnergy)) {
8288
return kFALSE;
83-
if (!list->fill("Max. Field ", &mMaxField))
89+
}
90+
if (!list->fill("Max. Field ", &mMaxField)) {
8491
return kFALSE;
92+
}
8593
FairParamObj* parpath = list->find("Path to map ");
86-
if (!parpath)
94+
if (!parpath) {
8795
return kFALSE;
96+
}
8897
int lgt = parpath->getLength();
8998
// RS: is there a bug in FairParamList::fill(const Text_t* name,Text_t* value,const Int_t length)?
9099
// I think the "if (l<length-1)" should be "if (l<length)"
91100
char cbuff[lgt + 2];
92101
memset(cbuff, 0, sizeof(char) * (lgt + 2));
93-
if (!list->fill("Path to map ", cbuff, lgt + 2))
102+
if (!list->fill("Path to map ", cbuff, lgt + 2)) {
94103
return kFALSE;
104+
}
95105
mMapPath = cbuff;
96106
return kTRUE;
97107
}

0 commit comments

Comments
 (0)