Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:16:45

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef FUN4ALL_FUN4ALLOUTPUTMANAGER_H
0004 #define FUN4ALL_FUN4ALLOUTPUTMANAGER_H
0005 
0006 #include "Fun4AllBase.h"
0007 
0008 #include <limits>
0009 #include <string>
0010 #include <vector>
0011 
0012 class PHCompositeNode;
0013 
0014 class Fun4AllOutputManager : public Fun4AllBase
0015 {
0016  public:
0017   //! destructor
0018   ~Fun4AllOutputManager() override;
0019 
0020   //! print method (dump event selector)
0021   void Print(const std::string &what = "ALL") const override;
0022 
0023   //! add a node in outputmanager
0024   virtual int AddNode(const std::string & /*nodename*/)
0025   {
0026     return 0;
0027   }
0028 
0029   //! add a runwise node in outputmanager
0030   virtual int AddRunNode(const std::string & /*nodename*/)
0031   {
0032     return 0;
0033   }
0034 
0035   //! not write a node in outputmanager
0036   virtual int StripNode(const std::string & /*nodename*/)
0037   {
0038     return 0;
0039   }
0040 
0041   //! not write a runwise node in outputmanager
0042   virtual int StripRunNode(const std::string & /*nodename*/)
0043   {
0044     return 0;
0045   }
0046 
0047   virtual int StripCompositeNode(const std::string & /*nodename*/) {return 0;}
0048 
0049   virtual void SaveRunNode(const int) { return; }
0050   virtual void SaveDstNode(const int) { return; }
0051 
0052   /*! \brief
0053     add an event selector to the outputmanager.
0054     event will get written only if all event selectors process_event method
0055     return EVENT_OK
0056   */
0057   virtual int AddEventSelector(const std::string &recomodule);
0058 
0059   //! opens output file
0060   virtual int outfileopen(const std::string & /*nodename*/)
0061   {
0062     return 0;
0063   }
0064 
0065   //! Common method, called before calling virtual Write
0066   int WriteGeneric(PHCompositeNode *startNode);
0067 
0068   //! write starting from given node
0069   virtual int Write(PHCompositeNode * /*startNode*/)
0070   {
0071     return 0;
0072   }
0073 
0074   //! write specified node
0075   virtual int WriteNode(PHCompositeNode * /*thisNode*/)
0076   {
0077     return 0;
0078   }
0079 
0080   //! retrieves pointer to vector of event selector module names
0081   virtual std::vector<std::string> *EventSelector()
0082   {
0083     return &m_EventSelectorsVector;
0084   }
0085 
0086   //! retrieves pointer to vector of event selector module ids
0087   virtual std::vector<unsigned> *RecoModuleIndex()
0088   {
0089     return &m_RecoModuleIndexVector;
0090   }
0091 
0092   //! decides if event is to be written or not
0093   virtual int DoNotWriteEvent(std::vector<int> *retcodes) const;
0094 
0095   //! get number of Events
0096   virtual unsigned int EventsWritten() const { return m_NEvents; }
0097   //! increment number of events
0098   virtual void IncrementEvents(const unsigned int i) { m_NEvents += i; }
0099   //! set number of events
0100   virtual void SetEventsWritten(const unsigned int i) { m_NEvents = i; }
0101   //! get output file name
0102   virtual std::string OutFileName() const { return m_OutFileName; }
0103   //! set compression level (if implemented)
0104   virtual void CompressionSetting(const int /*i*/) { return; }
0105 
0106   void OutFileName(const std::string &name) { m_OutFileName = name; }
0107   void SetClosingScript(const std::string &script) { m_RunAfterClosingScript = script; }
0108   void SetClosingScriptArgs(const std::string &args) { m_ClosingArgs = args; }
0109   int RunAfterClosing();
0110   void UseFileRule() { m_UseFileRuleFlag = true; }
0111   bool ApplyFileRule() const { return m_UseFileRuleFlag; }
0112   void SetNEvents(const unsigned int nevt);
0113   unsigned int GetNEvents() const { return m_MaxEvents; }
0114   void FileRule(const std::string &newrule) { m_FileRule = newrule; }
0115   const std::string &FileRule() const { return m_FileRule; }
0116   void SplitLevel(const int split) { splitlevel = split; }
0117   void BufferSize(const int size) { buffersize = size; }
0118   int SplitLevel() const { return splitlevel; }
0119   int BufferSize() const { return buffersize; }
0120   int Segment() { return m_CurrentSegment; }
0121 
0122  protected:
0123   /*!
0124     constructor.
0125     is protected since we do not want the  class to be created in root macros
0126   */
0127   Fun4AllOutputManager(const std::string &myname);
0128   Fun4AllOutputManager(const std::string &myname, const std::string &outfname);
0129 
0130   //! current segment
0131   int m_CurrentSegment{0};
0132 
0133  private:
0134   //! add file rule to filename (runnumber-segment)
0135   bool m_UseFileRuleFlag{false};
0136 
0137   //! Buffer Size for baskets in root file
0138   int buffersize{std::numeric_limits<int>::min()};
0139 
0140   //! Split level of TBranches
0141   int splitlevel{std::numeric_limits<int>::min()};
0142 
0143   //! Number of Events
0144   unsigned int m_NEvents{0};
0145 
0146   //! Number of Events to write before roll over
0147   unsigned int m_MaxEvents{std::numeric_limits<unsigned int>::max()};
0148 
0149   //! Script to run after closing of file
0150   std::string m_RunAfterClosingScript;
0151 
0152   //! string with arguments for closing script
0153   std::string m_ClosingArgs;
0154 
0155   //! output file name
0156   std::string m_OutFileName;
0157 
0158   //! last output file name which was closed
0159   std::string m_LastClosedFileName;
0160 
0161   //! file rule when writing multiple segments (-<runnumber>-segment)
0162   std::string m_FileRule{"-%08d-%05d"};
0163 
0164   //! vector of event selectors modules
0165   std::vector<std::string> m_EventSelectorsVector;
0166 
0167   //! vector of associated module indexes
0168   std::vector<unsigned> m_RecoModuleIndexVector;
0169 };
0170 
0171 #endif