Skip to content

Commit 7984630

Browse files
committed
feat: support iguana::Algorithm::Run calls
1 parent e771463 commit 7984630

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Clas12Banks/clas12reader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ namespace clas12 {
461461
_event.getStructure(*ibank.get());
462462
}
463463

464+
// call user's custom read action
465+
_readEventUserAction(this);
464466

465467
return true;
466468
}

Clas12Banks/clas12reader.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <vector>
4545
#include <string>
4646
#include <iostream>
47+
#include <functional>
4748

4849
#ifdef RCDB_MYSQL
4950
#include "rcdb_reader.h"
@@ -257,6 +258,13 @@ namespace clas12 {
257258
_verbose=level;
258259
_reader.setVerbose(level);
259260
}
261+
262+
// Set a "read action", a custom lambda function which is executed for every event within `readEvent()`.
263+
// The lambda argument is a pointer to an instance of this `clas12reader` class
264+
void SetReadAction(std::function<void(clas12reader*)> readEventUserAction) {
265+
_readEventUserAction = readEventUserAction;
266+
}
267+
260268

261269
protected:
262270

@@ -345,7 +353,10 @@ namespace clas12 {
345353
bool _useFTBased{false};
346354
bool _isOpen{false};
347355
std::vector<std::string> _addBankNames;
348-
356+
357+
// user-definable lambda, called in `readEvent()`
358+
std::function<void(clas12reader*)> _readEventUserAction = [](clas12reader* r) {};
359+
349360
///////////////////////////////DB
350361
private:
351362
int _runNo{0};

idea.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// iguana user code
2+
clas12reader reader;
3+
iguana::algorithm algo;
4+
algo.Start();
5+
auto bank3 = algo.CreateBank("new::bank");
6+
auto read_action = [&algo, &bank3](clas12reader* CR) {
7+
algo.Run(
8+
*CR->bank1(),
9+
*CR->bank2(),
10+
bank3
11+
);
12+
}
13+
reader.SetReadAction(read_action);
14+
15+
// FIXME
16+
// FIXME: handle hipo::bank::rowlist iteration
17+
// FIXME

0 commit comments

Comments
 (0)