Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:10

0001 #include "Fun4AllOutputManager.h"
0002 
0003 #include <phool/phool.h>
0004 
0005 #include <TSystem.h>
0006 
0007 #include <filesystem>
0008 #include <iostream>
0009 #include <string>
0010 #include <vector>
0011 
0012 Fun4AllOutputManager::Fun4AllOutputManager(const std::string &name)
0013   : Fun4AllBase(name)
0014 {
0015 }
0016 
0017 Fun4AllOutputManager::~Fun4AllOutputManager()
0018 {
0019   // the last file is closed by deleting the output manager, if we want to execute a script at the end
0020   // we have to run it here
0021   RunAfterClosing();
0022 }
0023 
0024 Fun4AllOutputManager::Fun4AllOutputManager(const std::string &name, const std::string &outfname)
0025   : Fun4AllBase(name)
0026   , m_OutFileName(outfname)
0027 {
0028 }
0029 
0030 //___________________________________________________________________
0031 int Fun4AllOutputManager::AddEventSelector(const std::string &recomodule)
0032 {
0033   const std::string &newselector = recomodule;
0034   for (const std::string &evtsel : m_EventSelectorsVector)
0035   {
0036     if (evtsel == newselector)
0037     {
0038       std::cout << "Event Selector " << newselector << " allready in list" << std::endl;
0039       return -1;
0040     }
0041   }
0042   std::cout << "EventSelector: " << &m_EventSelectorsVector << std::endl;
0043   m_EventSelectorsVector.push_back(newselector);
0044   return 0;
0045 }
0046 
0047 //___________________________________________________________________
0048 int Fun4AllOutputManager::WriteGeneric(PHCompositeNode *startNode)
0049 {
0050   m_NEvents++;
0051   int iret = Write(startNode);
0052   return iret;
0053 }
0054 
0055 //___________________________________________________________________
0056 void Fun4AllOutputManager::Print(const std::string &what) const
0057 {
0058   if (what == "ALL" || what == "EVENTSELECTOR")
0059   {
0060     unsigned icnt = 0;
0061     for (const std::string &evtsel : m_EventSelectorsVector)
0062     {
0063       std::cout << Name() << ": Reco Module " << evtsel << " select Events" << std::endl;
0064       std::cout << Name() << ": Reco Module Index: " << m_RecoModuleIndexVector[icnt] << std::endl;
0065       icnt++;
0066     }
0067   }
0068   if (what == "ALL" || what == "EVENTSWRITTEN")
0069   {
0070     std::cout << Name() << " wrote " << EventsWritten() << " Events" << std::endl;
0071   }
0072   return;
0073 }
0074 
0075 //___________________________________________________________________
0076 int Fun4AllOutputManager::DoNotWriteEvent(std::vector<int> *retcodes) const
0077 {
0078   int iret = 0;
0079   for (unsigned int index : m_RecoModuleIndexVector)
0080   {
0081     iret += (*retcodes)[index];
0082   }
0083   return iret;
0084 }
0085 
0086 int Fun4AllOutputManager::RunAfterClosing()
0087 {
0088   unsigned int iret = 0;
0089   if (m_OutFileName == m_LastClosedFileName)
0090   {
0091     if (Verbosity() > 1)
0092     {
0093       std::cout << PHWHERE << " Output file name has not changed, not closing "
0094                 << m_OutFileName << " again" << std::endl;
0095     }
0096     return iret;
0097   }
0098   m_LastClosedFileName = m_OutFileName;
0099   if (!m_RunAfterClosingScript.empty())
0100   {
0101     if (!std::filesystem::exists(m_RunAfterClosingScript))
0102     {
0103       std::cout << PHWHERE << "RunAfterClosing() closing script " << m_RunAfterClosingScript << " not found" << std::endl;
0104       return -1;
0105     }
0106     if (!((std::filesystem::status(m_RunAfterClosingScript).permissions() & std::filesystem::perms::owner_exec) == std::filesystem::perms::owner_exec))
0107     {
0108       std::cout << PHWHERE << "RunAfterClosing() closing script " << m_RunAfterClosingScript << " is not owner executable" << std::endl;
0109       return -1;
0110     }
0111 
0112     std::string fullcmd = m_RunAfterClosingScript + " " + m_OutFileName + " " + m_ClosingArgs;
0113     if (Verbosity() > 1)
0114     {
0115       std::cout << PHWHERE << " running " << fullcmd << std::endl;
0116     }
0117     iret = gSystem->Exec(fullcmd.c_str());
0118   }
0119   if (iret)
0120   {
0121     iret = iret >> 8U;
0122   }
0123   return iret;
0124 }
0125 void Fun4AllOutputManager::SetNEvents(const unsigned int nevt)
0126 {
0127   if (nevt == 0)
0128   {
0129     std::cout << PHWHERE << " Number of Events has to be > 0" << std::endl;
0130     gSystem->Exit(1);
0131     exit(1);
0132   }
0133   m_MaxEvents = nevt;
0134   return;
0135 }