Skip to content

Commit

Permalink
Synchronous QC flags call in cxx-client (#1616)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Tichák <[email protected]>
  • Loading branch information
justonedev1 and Michal Tichák authored Jun 20, 2024
1 parent 0e04183 commit 7de8b33
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cxx-client/include/BookkeepingApi/QcFlagServiceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class QcFlagServiceClient
const std::string& productionName,
const std::string& detectorName,
const std::vector<QcFlag>& qcFlags) = 0;

/// Create a list of new QC flag for a given run and detector
virtual std::vector<int> createForSynchronous(
uint32_t runNumber,
const std::string& detectorName,
const std::vector<QcFlag>& qcFlags) = 0;
};
} // namespace o2::bkp::api

Expand Down
28 changes: 28 additions & 0 deletions cxx-client/src/grpc/services/GrpcQcFlagServiceClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include "GrpcQcFlagServiceClient.h"

using grpc::ClientContext;

using o2::bookkeeping::DataPassQcFlagCreationRequest;
using o2::bookkeeping::QcFlagCreationResponse;
using o2::bookkeeping::SimulationPassQcFlagCreationRequest;
using o2::bookkeeping::SynchronousQcFlagCreationRequest;

namespace o2::bkp::api::grpc::services
{
Expand Down Expand Up @@ -82,6 +84,32 @@ std::vector<int> grpc::services::GrpcQcFlagServiceClient::createForSimulationPas
return { flagIds.begin(), flagIds.end() };
}

std::vector<int> grpc::services::GrpcQcFlagServiceClient::createForSynchronous(
uint32_t runNumber,
const std::string& detectorName,
const std::vector<QcFlag>& qcFlags)
{
ClientContext context;
SynchronousQcFlagCreationRequest request;
QcFlagCreationResponse response;

request.set_runnumber(runNumber);
request.set_detectorname(detectorName);

for (const auto& qcFlag : qcFlags) {
auto grpcQcFlag = request.add_flags();
mirrorQcFlagOnGrpcQcFlag(qcFlag, grpcQcFlag);
}

auto status = mStub->CreateSynchronous(&context, request, &response);
if (!status.ok()) {
throw std::runtime_error(status.error_message());
}

auto flagIds = response.flagids();
return { flagIds.begin(), flagIds.end() };
}

void GrpcQcFlagServiceClient::mirrorQcFlagOnGrpcQcFlag(const QcFlag& qcFlag, bookkeeping::QcFlag* grpcQcFlag)
{
grpcQcFlag->set_flagtypeid(qcFlag.flagTypeId);
Expand Down
9 changes: 4 additions & 5 deletions cxx-client/src/grpc/services/GrpcQcFlagServiceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
namespace o2::bkp::api::grpc::services
{

class GrpcQcFlagServiceClient: public QcFlagServiceClient
class GrpcQcFlagServiceClient : public QcFlagServiceClient
{
public:
explicit GrpcQcFlagServiceClient(const std::shared_ptr<::grpc::ChannelInterface>& channel);

std::vector<int> createForDataPass(uint32_t runNumber, const std::string& passName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags) override;
std::vector<int> createForSimulationPass(uint32_t runNumber, const std::string& productionName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags) override;
std::vector<int> createForSynchronous(uint32_t runNumber, const std::string& detectorName, const std::vector<QcFlag>& qcFlags) override;

private:
/**
Expand All @@ -37,13 +38,11 @@ class GrpcQcFlagServiceClient: public QcFlagServiceClient
* @param qcFlag the model QC flag
* @param grpcQcFlag the destination QC flag
*/
static void mirrorQcFlagOnGrpcQcFlag(const QcFlag &qcFlag, bookkeeping::QcFlag* grpcQcFlag);
static void mirrorQcFlagOnGrpcQcFlag(const QcFlag& qcFlag, bookkeeping::QcFlag* grpcQcFlag);

std::unique_ptr<o2::bookkeeping::QcFlagService::Stub> mStub;
};

} // namespace o2::bkp::api


} // namespace o2::bkp::api::grpc::services

#endif // CXX_CLIENT_BOOKKEEPINGAPI_GRPCQCFLAGSERVICECLIENT_H

0 comments on commit 7de8b33

Please sign in to comment.