33 return StatusCode::SUCCESS;
38 return StatusCode::SUCCESS;
44 getObject(TFile& a_file,
const std::string&
path)
46 std::unique_ptr<T>
obj(
dynamic_cast<T*
>(a_file.Get(
path.c_str())));
48 std::stringstream
msg;
49 msg <<
"Failed object " <<
path <<
" from File " << a_file.GetName()
50 <<
" with type " <<
typeid(T).
name();
51 throw std::runtime_error(
msg.str());
53 obj->SetDirectory(
nullptr);
62 std::vector<std::unique_ptr<TH1>> ownedRetrievedHistos;
63 const unsigned int layer_info = ownedRetrievedHistos.size();
69 ownedRetrievedHistos.push_back( getObject<TH2>(
input_file,
folder+
"InputsInfo") );
73 unsigned int n_hidden = ownedRetrievedHistos.at(layer_info)->GetNbinsX()-2;
74 ATH_MSG_VERBOSE(
" Retrieving calibration: " <<
folder <<
" for NN with: " << n_hidden <<
" hidden layers.");
76 ownedRetrievedHistos.reserve( ownedRetrievedHistos.size() + n_hidden*2 );
77 for (
unsigned int i=0;
i<=n_hidden; ++
i) {
78 std::stringstream folder_name;
85 std::vector<const TH1*> retrievedHistos;
86 retrievedHistos.reserve(ownedRetrievedHistos.size());
88 for(
const auto &
h: ownedRetrievedHistos){
89 retrievedHistos.push_back(
h.get());
92 std::unique_ptr<TTrainedNetwork> a_nn(
m_networkToHistoTool->fromHistoToTrainedNetwork(retrievedHistos));
94 ATH_MSG_ERROR(
"Failed to create NN from " << retrievedHistos.size() <<
" histograms read from " <<
folder);
100 return a_nn.release();
107 if (NnWriteHandle.isValid()) {
108 ATH_MSG_DEBUG(
"Write CondHandle "<< NnWriteHandle.fullKey() <<
" is already valid");
109 return StatusCode::SUCCESS;
113 if(!readHandle.isValid()) {
115 return StatusCode::FAILURE;
118 assert( atrcol !=
nullptr);
120 EventIDRange cdo_iov;
121 if(!readHandle.range(cdo_iov)) {
122 ATH_MSG_ERROR(
"Failed to get valid validaty range from " << readHandle.key());
123 return StatusCode::FAILURE;
128 if (channel_iter==atrcol->end()) {
130 return StatusCode::FAILURE;
134 const std::string coolguid=channel_iter->second[
"fileGUID"].data<std::string>();
136 std::unique_ptr<TTrainedNetworkCollection> writeCdo{std::make_unique<TTrainedNetworkCollection>()};
140 m_poolsvc->catalog()->getFirstPFN(coolguid, pfname, tech );
141 ATH_MSG_VERBOSE(
"Get NNs from file " << pfname.c_str() <<
" [" << coolguid <<
" <- " << readHandle.key() <<
"]." );
142 std::unique_ptr<TFile> a_file( TFile::Open(pfname.c_str(),
"READ") );
143 if (!a_file || !a_file->IsOpen()) {
144 ATH_MSG_ERROR(
"Failed to open file " << pfname <<
" referenced by " << readHandle.key() <<
" GUID " << coolguid);
145 return StatusCode::FAILURE;
156 if(NnWriteHandle.record(cdo_iov,std::move(writeCdo)).isFailure()) {
157 ATH_MSG_ERROR(
"Failed to record Trained network collection to "
158 << NnWriteHandle.key()
159 <<
" with IOV " << cdo_iov );
160 return StatusCode::FAILURE;
162 return StatusCode::SUCCESS;