Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:14

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 /// Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DDDigi/DigiMonitorHandler.h>
0017 
0018 /// ROOT include files
0019 #include <TFile.h>
0020 
0021 /// C/C++ include files
0022 
0023 using namespace dd4hep::digi;
0024 
0025 /// Standard constructor
0026 DigiMonitorHandler::DigiMonitorHandler(const DigiKernel& kernel, const std::string& nam)
0027   : DigiAction(kernel, nam)
0028 {
0029   declareProperty("MonitorOutput", m_output_file);
0030 }
0031 
0032 /// Default destructor
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 /// Adopt monitor and keep reference for saving
0045 void DigiMonitorHandler::adopt(DigiAction* source, TNamed* object)    {
0046   source->addRef();
0047   m_monitors[source].insert(object);
0048 }
0049 
0050 /// Save monitors
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