File indexing completed on 2025-01-30 09:17:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DDDigi/DigiMonitorHandler.h>
0017
0018
0019 #include <TFile.h>
0020
0021
0022
0023 using namespace dd4hep::digi;
0024
0025
0026 DigiMonitorHandler::DigiMonitorHandler(const DigiKernel& kernel, const std::string& nam)
0027 : DigiAction(kernel, nam)
0028 {
0029 declareProperty("MonitorOutput", m_output_file);
0030 }
0031
0032
0033 DigiMonitorHandler::~DigiMonitorHandler() {
0034 for( auto& m : m_monitors ) {
0035 m.first->release();
0036 for( auto* itm : m.second ) {
0037 detail::deletePtr(itm);
0038 }
0039 m.second.clear();
0040 }
0041 m_monitors.clear();
0042 }
0043
0044
0045 void DigiMonitorHandler::adopt(DigiAction* source, TNamed* object) {
0046 source->addRef();
0047 m_monitors[source].insert(object);
0048 }
0049
0050
0051 void DigiMonitorHandler::save() {
0052 if ( !m_output_file.empty() ) {
0053 TFile* output = TFile::Open(m_output_file.c_str(),
0054 "DD4hep Digitization monitoring information",
0055 "RECREATE");
0056 TDirectory::TContext top_context(output);
0057 if ( output && !output->IsZombie() ) {
0058 for( const auto& m : m_monitors ) {
0059 const auto* act = m.first;
0060 const auto& items = m.second;
0061 const auto& nam = act->name();
0062 std::string title = "Monitor items of digitization action "+nam;
0063 TDirectory* direc = output->mkdir(nam.c_str(), title.c_str(), kTRUE);
0064 TDirectory::TContext action_context(direc);
0065 for( const auto* itm : items ) {
0066 Int_t nbytes = direc->WriteTObject(itm);
0067 if ( nbytes <= 0 ) {
0068 error("+++ Failed to write object: %s -> %s", nam.c_str(), itm->GetName());
0069 }
0070 }
0071 direc->Write();
0072 }
0073 output->Write();
0074 output->Close();
0075 delete output;
0076 return;
0077 }
0078 except("+++ Failed to open monitoring output file: %s", m_output_file.c_str());
0079 }
0080 }
0081