Skip to content
Snippets Groups Projects
Commit 6da43bde authored by Tomasz Bold's avatar Tomasz Bold Committed by Edward Moyse
Browse files

Added code to save HLT menu in Json form from c++ object

parent 80f95a76
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
/**
* @brief Write Json file from HLTMenu object
* To validate correct loading of the HLT menu
*/
#ifndef TRIGCONFSTORAGE_JSONFILEWRITERHLT_H
#define TRIGCONFSTORAGE_JSONFILEWRITERHLT_H
#include "TrigConfBase/TrigConfMessaging.h"
#include "TrigConfData/HLTMenu.h"
namespace TrigConf {
/**
* @brief Loader of trigger configurations from Json files
*/
class JsonFileWriterHLT : public TrigConfMessaging {
public:
/** Constructor */
JsonFileWriterHLT();
bool writeJsonFile(const std::string & filename, const HLTMenu & menu) const;
};
}
#endif
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "TrigConfIO/JsonFileWriterHLT.h"
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace std;
TrigConf::JsonFileWriterHLT::JsonFileWriterHLT() :
TrigConfMessaging( "JsonFileWriter")
{}
bool
TrigConf::JsonFileWriterHLT::writeJsonFile(const std::string & filename, const HLTMenu & menu) const
{
json chains({});
for ( const auto & chain : menu ) {
json jChain({});
jChain["counter"] = chain.counter();
jChain["nameHash"] = chain.name();
jChain["l1item"] = chain.l1item();
jChain["legMultiplicities"] = chain.legMultiplicities();
jChain["l1thresholds"] = chain.l1thresholds();
jChain["groups"] = chain.groups();
jChain["streams"] = chain.streams();
jChain["seqeuncers"] = chain.sequencers();
chains[chain.name()] = jChain;
}
json sequencers({});
for ( const auto [seqName, algsList]: menu.sequencers() ) {
json jSeq( algsList );
sequencers[seqName] = jSeq;
}
json streams({});
for ( const auto stream: menu.streams() ) {
json jStream({});
jStream["name"] = stream["name"];
jStream["type"] = stream["type"];
jStream["obeyLB"] = stream.getAttribute<bool>("obeyLB");
jStream["forceFullEventBuilding"] = stream.getAttribute<bool>("forceFullEventBuilding");
streams[stream["name"]] = jStream;
}
json j({});
j["filetype"] = "hltmenu";
j["name"] = menu.name();
j["chains"] = chains;
j["sequencers"] = sequencers;
j["streams"] = streams;
std::ofstream outfile(filename);
outfile << std::setw(4) << j << std::endl;
TRG_MSG_INFO("Saved file " << filename);
return true;
}
......@@ -7,6 +7,7 @@
#include "TrigConfIO/JsonFileLoader.h"
#include "TrigConfIO/JsonFileWriter.h"
#include "TrigConfIO/JsonFileWriterHLT.h"
#include "TrigConfIO/TrigDBMenuLoader.h"
#include "TrigConfIO/TrigDBJobOptionsLoader.h"
#include "TrigConfIO/TrigDBL1PrescalesSetLoader.h"
......@@ -170,15 +171,21 @@ namespace {
filename += ".json";
TrigConf::JsonFileLoader fileLoader;
return fileLoader.saveFile(filename, ds);
} else if ( cfg.writeFromDataStructure && kind=="L1Menu" ) {
} else if ( cfg.writeFromDataStructure ) {
std::string filename = kind;
if ( cfg.base != "" ) {
filename += "_" + cfg.base;
}
filename += ".fromDS.json";
TrigConf::JsonFileWriter fileWriter;
const auto & l1menu = dynamic_cast<const TrigConf::L1Menu &>(ds);
return fileWriter.writeJsonFile(filename, l1menu);
if ( kind=="L1Menu" ) {
TrigConf::JsonFileWriter fileWriter;
const auto & l1menu = dynamic_cast<const TrigConf::L1Menu &>(ds);
return fileWriter.writeJsonFile(filename, l1menu);
} else if ( kind == "HLTMenu") {
TrigConf::JsonFileWriterHLT fileWriter;
const auto & hltmenu = dynamic_cast<const TrigConf::HLTMenu &>(ds);
return fileWriter.writeJsonFile(filename, hltmenu);
}
}
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment