Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:11

0001 /// ===========================================================================
0002 /*! \file    TestPHFlags.cc
0003  *  \authors Derek Anderson
0004  *  \date    11.22.2024
0005  *
0006  *  A small F4A module to test if certain
0007  *  flags exist.
0008  */
0009 /// ===========================================================================
0010 
0011 #define TESTPHFLAGS_CC
0012 
0013 // module definition
0014 #include "TestPHFlags.h"
0015 
0016 // f4a libraries
0017 #include <fun4all/Fun4AllReturnCodes.h>
0018 
0019 // pdbcalbase libraries
0020 #include <pdbcalbase/PdbParameterMap.h>
0021 
0022 // phool libraries
0023 #include <phool/getClass.h>
0024 #include <phool/PHCompositeNode.h>
0025 #include <phool/phool.h>
0026 
0027 // c++ utilities
0028 #include <iostream>
0029 #include <vector>
0030 
0031 
0032 
0033 // ctor/dtor ==================================================================
0034 
0035 // ----------------------------------------------------------------------------
0036 //! Default module constructor
0037 // ----------------------------------------------------------------------------
0038 TestPHFlags::TestPHFlags(const std::string& name, const std::string& flags, const bool debug)
0039   : SubsysReco(name)
0040   , m_flags(name)
0041   , m_doDebug(debug)
0042   , m_flagNode(flags)
0043 {
0044 
0045   if (m_doDebug)
0046   {
0047     std::cout << "TestPHFlags::TestPHFlags(std::string &name, std::string&, bool) Calling ctor" << std::endl;
0048   }
0049 
0050 }  // end ctor(std::string&, std::string&, bool)
0051 
0052 
0053 
0054 // ----------------------------------------------------------------------------
0055 //! Default module destructor
0056 // ----------------------------------------------------------------------------
0057 TestPHFlags::~TestPHFlags()
0058 {
0059 
0060   if (m_doDebug)
0061   {
0062     std::cout << "TestPHFlags::~TestPHFlags() Calling dtor" << std::endl;
0063   }
0064 
0065 }  // end dtor
0066 
0067 
0068 
0069 // fun4all methods ============================================================ 
0070 
0071 // ----------------------------------------------------------------------------
0072 //! Process event, i.e. spit out the values of several flags
0073 // ----------------------------------------------------------------------------
0074 int TestPHFlags::process_event(PHCompositeNode* topNode)
0075 {
0076 
0077   if (m_doDebug)
0078   {
0079     std::cout << "TestPHFlags::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
0080   }
0081 
0082   // flags are stored under the PAR node
0083   PHNodeIterator itNode(topNode);
0084   PHCompositeNode* parNode = dynamic_cast<PHCompositeNode*>(itNode.findFirst("PHCompositeNode", "PAR"));
0085   if (!parNode)
0086   {
0087     std::cerr << PHWHERE << " PANIC: PAR node not found! No flags present, and aborting event!" << std::endl;
0088     return Fun4AllReturnCodes::EVENT_OK;
0089   }
0090 
0091   // now retrieve flag node
0092   PdbParameterMap* flagNode = findNode::getClass<PdbParameterMap>(parNode, m_flagNode);
0093   if (!flagNode)
0094   {
0095     std::cerr << PHWHERE << " PANIC: " << m_flagNode << " node not found! Aborting event!" << std::endl;
0096     return Fun4AllReturnCodes::EVENT_OK;
0097   }
0098 
0099   // now pull all flags from node and print
0100   // all int flags
0101   m_flags.FillFrom(flagNode);
0102   m_flags.printint();
0103 
0104   // and then explicitly look for these flags
0105   std::vector<std::string> flagsToCheck = {
0106     "HasBeamBackground_NullFilter",
0107     "HasBeamBackground_StreakSidebandFilter",
0108     "HasBeamBackground"
0109   };
0110 
0111   // if flag exists, print value
0112   for (const std::string& flag : flagsToCheck)
0113   {
0114     std::cout << "[" << flag << "] exists? " << m_flags.exist_int_param(flag);
0115     if (m_flags.exist_int_param(flag))
0116     {
0117       std::cout << " : value = " << m_flags.get_int_param(flag) << std::endl;
0118     }
0119     else
0120     {
0121       std::cout << std::endl;
0122     }
0123   }
0124   return Fun4AllReturnCodes::EVENT_OK;
0125 
0126 }  // end 'process_event(PHCompositeNode*)'
0127 
0128 // end ========================================================================