Skip to content

Commit de4389f

Browse files
authored
Merge pull request #243 from sy-c/master
v2.17.0
2 parents 0cd8417 + e757662 commit de4389f

5 files changed

Lines changed: 73 additions & 30 deletions

File tree

doc/configurationParameters.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The *receiverFMQ-\** section defines parameters for the test receiverFMQ.exe pro
1111

1212
Please see the provided example configuration files to see how they are usually arranged.
1313

14+
It is possible to define some default parameters to be used in all matching sections by creating a section which name ends with "-\*" and containing some key-value pairs. These pairs are applied to all sections with similar names. Existing key-value pairs are not overwritten, but are defined according to these defaults if they don't exist. It can be useful to create multiple equipments with similar settings.
15+
1416
## Parameter types
1517

1618
The following table describes the types used in the configuration, giving:
@@ -168,7 +170,6 @@ The parameters related to 3rd-party libraries are described here for convenience
168170
| readout | fairmqConsoleSeverity | int | -1 | Select amount of FMQ messages with fair::Logger::SetConsoleSeverity(). Value as defined in Severity enum defined from FairLogger/Logger.h. Use -1 to leave current setting. |
169171
| readout | flushConsumerTimeout | double | 1 | Time in seconds to wait before stopping the consumers (ie wait allocated pages released). 0 means stop immediately. |
170172
| readout | flushEquipmentTimeout | double | 1 | Time in seconds to wait for data once the equipments are stopped. 0 means stop immediately. |
171-
| readout | logbookApiToken | string | | The token to be used for the logbook API. |
172173
| readout | logbookEnabled | int | 0 | When set, the logbook is enabled and populated with readout stats at runtime. |
173174
| readout | logbookUpdateInterval | int | 30 | Amount of time (in seconds) between logbook publish updates. |
174175
| readout | logbookUrl | string | | The address to be used for the logbook API. |

doc/releaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,7 @@ This file describes the main feature changes for each readout.exe released versi
520520
- added equipment-cruemulator-*.PayloadSizeStdev: generate payload with random size (gaussian distribution mean=PayloadSize sigma=PayloadSizeStdev).
521521
- added equipment-cruemulator-*.linkThroughput: set incoming link data throughput (in Gbps).
522522
- Minor logging updates.
523+
524+
## v2.17.0 - 01/03/2022
525+
- Updated configuration syntax: section names ending with `-*` can be used to define default parameters. They are applied to all section with similar names. Existing key-value pairs are not overwritten, but are defined according to defaults if they don't exist. For example, it is possible to define the TFperiod for all equipments by adding a section named `[equipment-*]` with `TFperiod=32`.
526+
- Updated readout to new bookkeeping API.

src/ReadoutVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define READOUT_VERSION "2.16.1"
12+
#define READOUT_VERSION "2.17.0"
1313

src/mainReadout.cxx

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@
4242
#ifdef WITH_ZMQ
4343
#include "ZmqServer.hxx"
4444
#endif
45-
#undef WITH_LOGBOOK
4645

4746
#ifdef WITH_CONFIG
4847
#include <Configuration/ConfigurationFactory.h>
4948
#endif
5049

5150
#ifdef WITH_LOGBOOK
52-
#include <BookkeepingApiCpp/BookkeepingFactory.h>
51+
#include <BookkeepingApi/BkpClientFactory.h>
5352
#endif
5453

5554
#ifdef WITH_DB
@@ -266,7 +265,7 @@ class Readout
266265
bool logFirstError = 0; // flag set to 1 after 1 error reported from iterateCheck/iterateRunning procedures
267266

268267
#ifdef WITH_LOGBOOK
269-
std::unique_ptr<bookkeeping::BookkeepingInterface> logbookHandle; // handle to logbook
268+
std::unique_ptr<o2::bkp::api::BkpClient> logbookHandle; // handle to logbook
270269
#endif
271270
#ifdef WITH_DB
272271
std::unique_ptr<ReadoutDatabase> dbHandle; // handle to readout database
@@ -290,18 +289,20 @@ void Readout::publishLogbookStats()
290289
if (logbookHandle != nullptr) {
291290
bool isOk = false;
292291
try {
293-
// interface: https://github.com/AliceO2Group/Bookkeeping/blob/master/cpp-api-client/src/BookkeepingApi.h
292+
// interface: https://github.com/AliceO2Group/Bookkeeping/tree/main/cxx-client/include/BookkeepingApi
294293
if (testLogbook) {
295294
// in test mode, create a dummy run entry in logbook
296295
if (occRole.length() == 0) { occRole = "flp-test"; }
297296
if (occRunNumber == 0) { occRunNumber = 999999999; }
298297
theLog.log(LogInfoDevel_(3210), "Logbook in test mode: create run number/flp %d / %s", (int)occRunNumber, occRole.c_str());
298+
/*
299299
std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
300300
logbookHandle->runStart(occRunNumber, now, now, "readout", RunType::TECHNICAL, 0, 0, 0, false, false, false, "normal");
301301
logbookHandle->flpAdd(occRole, "localhost", occRunNumber);
302+
*/
302303
testLogbook=0;
303304
}
304-
logbookHandle->flpUpdateCounters(occRole, occRunNumber, (int64_t)gReadoutStats.counters.numberOfSubtimeframes, (int64_t)gReadoutStats.counters.bytesReadout, (int64_t)gReadoutStats.counters.bytesRecorded, (int64_t)gReadoutStats.counters.bytesFairMQ);
305+
logbookHandle->flp()->updateReadoutCountersByFlpNameAndRunNumber(occRole, occRunNumber, (int64_t)gReadoutStats.counters.numberOfSubtimeframes, (int64_t)gReadoutStats.counters.bytesReadout, (int64_t)gReadoutStats.counters.bytesRecorded, (int64_t)gReadoutStats.counters.bytesFairMQ);
305306
isOk = true;
306307
} catch (const std::exception& ex) {
307308
theLog.log(LogErrorDevel_(3210), "Failed to update logbook: %s", ex.what());
@@ -476,6 +477,7 @@ int Readout::init(int argc, char* argv[])
476477
#else
477478
theLog.log(LogInfoDevel, "GPERFTOOLS : no");
478479
#endif
480+
theLog.log(LogInfoDevel, "Working directory: %s", std::filesystem::current_path().c_str());
479481
}
480482

481483
// report cached logs
@@ -603,6 +605,9 @@ int Readout::configure(const boost::property_tree::ptree& properties)
603605
return -1;
604606
}
605607

608+
// TODO
609+
// save config somewhere ?
610+
606611
// apply provided occ properties over loaded configuration
607612
// with function to overwrtie configuration tree t1 with (selected) content of t2
608613
auto mergeConfig = [&](boost::property_tree::ptree& t1, const boost::property_tree::ptree& t2) {
@@ -618,7 +623,7 @@ int Readout::configure(const boost::property_tree::ptree& properties)
618623
// check for a consumer with same fairmq channel
619624
for (auto kName : ConfigFileBrowser(&cfg, "consumer-")) {
620625
std::string cfgType;
621-
cfgType = cfg.getValue<std::string>(kName + ".consumerType");
626+
cfg.getOptionalValue<std::string>(kName + ".consumerType", cfgType);
622627
if (cfgType == "FairMQChannel") {
623628
std::string cfgChannelName;
624629
cfg.getOptionalValue<std::string>(kName + ".fmq-name", cfgChannelName);
@@ -660,6 +665,43 @@ int Readout::configure(const boost::property_tree::ptree& properties)
660665
};
661666
mergeConfig(cfg.get(), properties);
662667

668+
// merge default trees
669+
const char *defaultTag = "-*";
670+
// if a section ends with above string, its parameters are copied to all matching section names, when these parameters are not already defined there
671+
// append configuration tree t1 with content of t2 (existing leaves in t1 not overwritten by same ones from t2)
672+
auto appendConfig = [&](boost::property_tree::ptree& t1, boost::property_tree::ptree& t2) {
673+
for (boost::property_tree::ptree::iterator it = t2.begin(); it != t2.end();++it) {
674+
if (!t1.get_child_optional(it->first)) {
675+
//printf("set %s = %s\n", it->first.c_str(),it->second.data().c_str());
676+
t1.put_child( it->first, it->second );
677+
}
678+
}
679+
};
680+
// function returns true when end of string matches tag
681+
auto isEndOfStringMatching = [&](const std::string &s, const char* tag) {
682+
if (s.length()<=strlen(tag)) return false;
683+
if (s.substr(s.length()-strlen(tag)) != tag) return false;
684+
return true;
685+
};
686+
for (boost::property_tree::ptree::iterator pos = cfg.get().begin(); pos != cfg.get().end();) {
687+
const std::string section = pos->first;
688+
if (!isEndOfStringMatching(section, defaultTag)) {
689+
++pos;
690+
continue;
691+
}
692+
auto smatch = section.substr(0,section.length()-strlen(defaultTag));
693+
for (boost::property_tree::ptree::iterator pos2 = cfg.get().begin(); pos2 != cfg.get().end();++pos2) {
694+
if (pos2 == pos) continue; // do not self-overwrite
695+
const std::string section2 = pos2->first;
696+
if (section2.compare(0,smatch.length(),smatch)) continue; // mismatch
697+
if (isEndOfStringMatching(section2, defaultTag)) continue; // do not overwrite other defaults sections
698+
theLog.log(LogInfoDevel_(3002), "Updating configuration section [%s] with defaults from [%s]", pos2->first.c_str(), pos->first.c_str());
699+
appendConfig(pos2->second,pos->second);
700+
}
701+
// delete section with defaults, to avoid it is used further
702+
pos = cfg.get().erase(pos);
703+
}
704+
663705
// extract optional configuration parameters
664706
// configuration parameter: | readout | customCommands | string | | List of key=value pairs defining some custom shell commands to be executed at before/after state change commands. |
665707
if (customCommandsShellPid) {
@@ -805,11 +847,9 @@ int Readout::configure(const boost::property_tree::ptree& properties)
805847
#else
806848
// configuration parameter: | readout | logbookUrl | string | | The address to be used for the logbook API. |
807849
cfg.getOptionalValue<std::string>("readout.logbookUrl", cfgLogbookUrl);
808-
// configuration parameter: | readout | logbookApiToken | string | | The token to be used for the logbook API. |
809-
cfg.getOptionalValue<std::string>("readout.logbookApiToken", cfgLogbookApiToken);
810850

811851
theLog.log(LogInfoDevel, "Logbook enabled, %ds update interval, using URL = %s", cfgLogbookUpdateInterval, cfgLogbookUrl.c_str());
812-
logbookHandle = bookkeeping::getApiInstance(cfgLogbookUrl, cfgLogbookApiToken);
852+
logbookHandle = o2::bkp::api::BkpClientFactory::create(cfgLogbookUrl);
813853
if (logbookHandle == nullptr) {
814854
theLog.log(LogErrorSupport_(3210), "Failed to create handle to logbook");
815855
}
@@ -846,11 +886,8 @@ int Readout::configure(const boost::property_tree::ptree& properties)
846886
for (auto kName : ConfigFileBrowser(&cfg, "bank-")) {
847887
// skip disabled
848888
int enabled = 1;
849-
try {
850-
// configuration parameter: | bank-* | enabled | int | 1 | Enable (1) or disable (0) the memory bank. |
851-
enabled = cfg.getValue<int>(kName + ".enabled");
852-
} catch (...) {
853-
}
889+
// configuration parameter: | bank-* | enabled | int | 1 | Enable (1) or disable (0) the memory bank. |
890+
cfg.getOptionalValue<int>(kName + ".enabled", enabled);
854891
if (!enabled) {
855892
continue;
856893
}
@@ -868,13 +905,9 @@ int Readout::configure(const boost::property_tree::ptree& properties)
868905
// bank type
869906
// configuration parameter: | bank-* | type | string| | Support used to allocate memory. Possible values: malloc, MemoryMappedFile. |
870907
std::string cfgType = "";
871-
try {
872-
cfgType = cfg.getValue<std::string>(kName + ".type");
873-
} catch (...) {
874-
theLog.log(LogErrorSupport_(3100), "Skipping memory bank %s: no type specified", kName.c_str());
875-
continue;
876-
}
908+
cfg.getOptionalValue<std::string>(kName + ".type", cfgType);
877909
if (cfgType.length() == 0) {
910+
theLog.log(LogErrorSupport_(3100), "Skipping memory bank %s: no type specified", kName.c_str());
878911
continue;
879912
}
880913

@@ -934,11 +967,8 @@ int Readout::configure(const boost::property_tree::ptree& properties)
934967

935968
// skip disabled
936969
int enabled = 1;
937-
try {
938-
// configuration parameter: | consumer-* | enabled | int | 1 | Enable (value=1) or disable (value=0) the consumer. |
939-
enabled = cfg.getValue<int>(kName + ".enabled");
940-
} catch (...) {
941-
}
970+
// configuration parameter: | consumer-* | enabled | int | 1 | Enable (value=1) or disable (value=0) the consumer. |
971+
cfg.getOptionalValue<int>(kName + ".enabled", enabled);
942972
if (!enabled) {
943973
continue;
944974
}
@@ -957,7 +987,11 @@ int Readout::configure(const boost::property_tree::ptree& properties)
957987
try {
958988
// configuration parameter: | consumer-* | consumerType | string | | The type of consumer to be instanciated. One of:stats, FairMQDevice, DataSampling, FairMQChannel, fileRecorder, checker, processor, tcp. |
959989
std::string cfgType = "";
960-
cfgType = cfg.getValue<std::string>(kName + ".consumerType");
990+
cfg.getOptionalValue<std::string>(kName + ".consumerType", cfgType);
991+
if (cfgType.length() == 0) {
992+
theLog.log(LogErrorSupport_(3100), "Skipping consumer %s: no type specified", kName.c_str());
993+
continue;
994+
}
961995
theLog.log(LogInfoDevel, "Configuring consumer %s: %s", kName.c_str(), cfgType.c_str());
962996

963997
#ifdef WITH_NUMA
@@ -1090,7 +1124,12 @@ int Readout::configure(const boost::property_tree::ptree& properties)
10901124

10911125
// configuration parameter: | equipment-* | equipmentType | string | | The type of equipment to be instanciated. One of: dummy, rorc, cruEmulator |
10921126
std::string cfgEquipmentType = "";
1093-
cfgEquipmentType = cfg.getValue<std::string>(kName + ".equipmentType");
1127+
cfg.getOptionalValue<std::string>(kName + ".equipmentType", cfgEquipmentType);
1128+
if (cfgEquipmentType.length() == 0) {
1129+
theLog.log(LogErrorSupport_(3100), "Skipping equipment %s: no type specified", kName.c_str());
1130+
continue;
1131+
}
1132+
10941133
theLog.log(LogInfoDevel, "Configuring equipment %s: %s", kName.c_str(), cfgEquipmentType.c_str());
10951134

10961135
#ifdef WITH_NUMA

src/readoutConfigEditor.tcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ set configurationParametersDescriptor {
146146
| readout | fairmqConsoleSeverity | int | -1 | Select amount of FMQ messages with fair::Logger::SetConsoleSeverity(). Value as defined in Severity enum defined from FairLogger/Logger.h. Use -1 to leave current setting. |
147147
| readout | flushConsumerTimeout | double | 1 | Time in seconds to wait before stopping the consumers (ie wait allocated pages released). 0 means stop immediately. |
148148
| readout | flushEquipmentTimeout | double | 1 | Time in seconds to wait for data once the equipments are stopped. 0 means stop immediately. |
149-
| readout | logbookApiToken | string | | The token to be used for the logbook API. |
150149
| readout | logbookEnabled | int | 0 | When set, the logbook is enabled and populated with readout stats at runtime. |
151150
| readout | logbookUpdateInterval | int | 30 | Amount of time (in seconds) between logbook publish updates. |
152151
| readout | logbookUrl | string | | The address to be used for the logbook API. |

0 commit comments

Comments
 (0)