60:
env(ORT_LOGGING_LEVEL_WARNING,
"test"),
64 dqm_core::AlgorithmManager::instance().registerAlgorithm(
"AutoencoderExampleAlgorithm",
this);
79 size_t num_input_nodes =
session->GetInputCount();
80 Ort::AllocatorWithDefaultOptions allocator;
81 for (
size_t i = 0; i < num_input_nodes; ++i)
83 std::unique_ptr<char, Ort::detail::AllocatedFree> input_name_ptr =
session->GetInputNameAllocated(i, allocator);
84 char* input_name = input_name_ptr.get();
89 size_t num_output_nodes =
session->GetOutputCount();
90 for (
size_t i = 0; i < num_output_nodes; ++i)
92 std::unique_ptr<char, Ort::detail::AllocatedFree> output_name_ptr =
session->GetOutputNameAllocated(i, allocator);
93 char* output_name = output_name_ptr.get();
116 const TObject&
object,
117 const dqm_core::AlgorithmConfig& )
124 if (
object.
IsA()->InheritsFrom(
"TH2"))
126 histogram =
dynamic_cast<const TH2*
>(&object);
129 throw dqm_core::BadConfig( ERS_HERE, name,
"dimension of histogram < 2");
134 throw dqm_core::BadConfig( ERS_HERE, name,
"does not inherit from TH2" );
141 std::vector<std::vector<float>> output_data;
142 std::vector<int64_t> input_dims = {1, 3};
144 Ort::MemoryInfo memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
145 const char* input_names_cstr[] = {
input_names[0].c_str() };
146 const char* output_names_cstr[] = {
output_names[0].c_str() };
147 for (
auto& input_data : hist_data) {
149 Ort::Value input_tensor = Ort::Value::CreateTensor<float>(memory_info, input_data.data(), input_data.size(), input_dims.data(), input_dims.size());
152 auto output_tensors =
session->Run(Ort::RunOptions{
nullptr}, input_names_cstr, &input_tensor, 1, output_names_cstr, 1);
155 if (output_tensors.empty() || output_tensors[0].HasValue())
157 throw dqm_core::BadConfig(ERS_HERE, name,
"Output tensor does not have values or does not exist");
161 const size_t tensor_size = output_tensors[0].GetTensorTypeAndShapeInfo().GetElementCount();
165 throw dqm_core::BadConfig(ERS_HERE, name,
"Output tensor < 3 elements");
169 float* raw_output = output_tensors[0].GetTensorMutableData<
float>();
170 std::vector<float> output_point(raw_output, raw_output + 3);
171 output_data.push_back(output_point);
176 std::vector<float> reconstruction_errors;
177 for (
size_t i = 0; i < hist_data.size(); ++i) {
179 for (
size_t j = 0; j < 3; ++j) {
180 error += std::pow(hist_data[i][j] - output_data[i][j], 2);
182 reconstruction_errors.push_back(std::sqrt(
error));
187 std::nth_element(reconstruction_errors.begin(), reconstruction_errors.begin() + std::roundl(reconstruction_errors.size() * (99. / 100.)), reconstruction_errors.end());
188 float threshold = reconstruction_errors[reconstruction_errors.size() * 99 / 100];
192 std::vector<bool> anomalies;
193 for (
const auto&
error : reconstruction_errors) {
208 resulthisto=
static_cast<TH2*
>(
histogram->Clone());
212 throw dqm_core::BadConfig( ERS_HERE, name,
"does not inherit from TH2" );
214 resulthisto->Reset();
217 for (
size_t i = 0; i < anomalies.size(); ++i) {
221 resulthisto->SetBinContent(hist_data[i][0], hist_data[i][1], hist_data[i][2]);
226 dqm_core::Result* result =
new dqm_core::Result();
229 result->tags_[
"NBins"] = anomalies.size();
232 result->object_ = boost::shared_ptr<TObject>(resulthisto);
235 double gthreshold = 5000;
236 double rthreshold = 10000;
239 if (anomalies.size() <= gthreshold)
241 result->status_ = dqm_core::Result::Green;
243 else if (anomalies.size() < rthreshold)
245 result->status_ = dqm_core::Result::Yellow;
249 result->status_ = dqm_core::Result::Red;