Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:19:35

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 number of Events
0102   virtual void SetLastEventNumber(int ival) { m_LastEventNumber = ival; }
0103   virtual int LastEventNumber() const { return m_LastEventNumber; }
0104   virtual void UpdateLastEvent() { m_LastEventNumber += m_EventRollover; }
0105   //! set number of events
0106   virtual void SetEventNumberRollover(const int evtno);
0107   //! get output file name
0108   virtual std::string OutFileName() const { return m_OutFileName; }
0109   //! set compression level (if implemented)
0110   virtual void CompressionSetting(const int /*i*/) { return; }
0111   virtual int GetEventNumberRollover() const {return m_EventRollover;}
0112   virtual void InitializeLastEvent(int /*eventnumber*/) {return;}
0113   virtual void StartSegment(int iseg) {m_CurrentSegment = iseg;}
0114 
0115   void OutFileName(const std::string &name) { m_OutFileName = name; }
0116   void SetClosingScript(const std::string &script) { m_RunAfterClosingScript = script; }
0117   const std::string &GetClosingScript() const {return m_RunAfterClosingScript;}
0118   void SetClosingScriptArgs(const std::string &args) { m_ClosingArgs = args; }
0119   const std::string &GetClosingScriptArgs() const { return m_ClosingArgs; }
0120   int RunAfterClosing();
0121   void UseFileRule(bool b = true) { m_UseFileRuleFlag = b; }
0122   bool ApplyFileRule() const { return m_UseFileRuleFlag; }
0123   void SetNEvents(const unsigned int nevt);
0124   unsigned int GetNEvents() const { return m_MaxEvents; }
0125   void FileRule(const std::string &newrule) { m_FileRule = newrule; }
0126   const std::string &FileRule() const { return m_FileRule; }
0127   void SplitLevel(const int split) { splitlevel = split; }
0128   void BufferSize(const int size) { buffersize = size; }
0129   int SplitLevel() const { return splitlevel; }
0130   int BufferSize() const { return buffersize; }
0131   int Segment() const { return m_CurrentSegment; }
0132 
0133  protected:
0134   /*!
0135     constructor.
0136     is protected since we do not want the  class to be created in root macros
0137   */
0138   Fun4AllOutputManager(const std::string &myname);
0139   Fun4AllOutputManager(const std::string &myname, const std::string &outfname);
0140 
0141   //! current segment
0142   int m_CurrentSegment{0};
0143 
0144  private:
0145   //! add file rule to filename (runnumber-segment)
0146   bool m_UseFileRuleFlag{false};
0147 
0148   //! Buffer Size for baskets in root file
0149   int buffersize{std::numeric_limits<int>::min()};
0150 
0151   //! Split level of TBranches
0152   int splitlevel{std::numeric_limits<int>::min()};
0153 
0154   //! Last Event Number in output file
0155   int m_LastEventNumber{std::numeric_limits<int>::max()};
0156 
0157   //! Event number for rollover
0158   int m_EventRollover{0};
0159 
0160   //! Number of Events
0161   unsigned int m_NEvents{0};
0162 
0163   //! Number of Events to write before roll over
0164   unsigned int m_MaxEvents{std::numeric_limits<unsigned int>::max()};
0165 
0166   //! Script to run after closing of file
0167   std::string m_RunAfterClosingScript;
0168 
0169   //! string with arguments for closing script
0170   std::string m_ClosingArgs;
0171 
0172   //! output file name
0173   std::string m_OutFileName;
0174 
0175   //! last output file name which was closed
0176   std::string m_LastClosedFileName;
0177 
0178   //! file rule when writing multiple segments (-<runnumber>-segment)
0179   std::string m_FileRule{"-%08d-%05d"};
0180 
0181   //! vector of event selectors modules
0182   std::vector<std::string> m_EventSelectorsVector;
0183 
0184   //! vector of associated module indexes
0185   std::vector<unsigned> m_RecoModuleIndexVector;
0186 };
0187 
0188 #endif