Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:48

0001 #include "SingleStreamingInput.h"
0002 
0003 #include <fun4all/DBInterface.h>
0004 
0005 #include <phool/phool.h>
0006 
0007 #include <Event/Eventiterator.h>
0008 #include <Event/fileEventiterator.h>
0009 
0010 #include <cstdint>   // for uint64_t
0011 #include <iostream>  // for operator<<, basic_ostream, endl
0012 #include <set>
0013 #include <utility>  // for pair
0014 
0015 SingleStreamingInput::SingleStreamingInput(const std::string &name)
0016   : Fun4AllBase(name)
0017 {
0018 }
0019 
0020 SingleStreamingInput::~SingleStreamingInput()
0021 {
0022   delete m_EventIterator;
0023 }
0024 
0025 int SingleStreamingInput::fileopen(const std::string &filenam)
0026 {
0027   std::cout << PHWHERE << "trying to open " << filenam << std::endl;
0028   if (IsOpen())
0029   {
0030     std::cout << "Closing currently open file "
0031               << FileName()
0032               << " and opening " << filenam << std::endl;
0033     fileclose();
0034   }
0035   FileName(filenam);
0036   std::string fname = DBInterface::instance()->location(FileName());
0037   if (Verbosity() > 0)
0038   {
0039     std::cout << Name() << ": opening file " << FileName() << std::endl;
0040   }
0041   int status = 0;
0042   m_EventIterator = new fileEventiterator(fname.c_str(), status);
0043   m_EventsThisFile = 0;
0044   if (status)
0045   {
0046     delete m_EventIterator;
0047     m_EventIterator = nullptr;
0048     std::cout << PHWHERE << Name() << ": could not open file " << fname << std::endl;
0049     return -1;
0050   }
0051   IsOpen(1);
0052   AddToFileOpened(fname);  // add file to the list of files which were opened
0053   return 0;
0054 }
0055 
0056 int SingleStreamingInput::fileclose()
0057 {
0058   if (!IsOpen())
0059   {
0060     std::cout << Name() << ": fileclose: No Input file open" << std::endl;
0061     return -1;
0062   }
0063   delete m_EventIterator;
0064   m_EventIterator = nullptr;
0065   IsOpen(0);
0066   // if we have a file list, move next entry to top of the list
0067   // or repeat the same entry again
0068   UpdateFileList();
0069   return 0;
0070 }
0071 
0072 void SingleStreamingInput::Print(const std::string &what) const
0073 {
0074   if (what == "ALL" || what == "FEE")
0075   {
0076     for (const auto &bcliter : m_BeamClockFEE)
0077     {
0078       std::cout << "Beam clock 0x" << std::hex << bcliter.first << std::dec << std::endl;
0079       for (auto feeiter : bcliter.second)
0080       {
0081         std::cout << "FEM: " << feeiter << std::endl;
0082       }
0083     }
0084   }
0085   if (what == "ALL" || what == "FEEBCLK")
0086   {
0087     for (auto bcliter : m_FEEBclkMap)
0088     {
0089       std::cout << "FEE" << bcliter.first << " bclk: 0x"
0090                 << std::hex << bcliter.second << std::dec << std::endl;
0091     }
0092   }
0093   if (what == "ALL" || what == "STACK")
0094   {
0095     for (auto iter : m_BclkStack)
0096     {
0097       std::cout << "stacked bclk: 0x" << std::hex << iter << std::dec << std::endl;
0098     }
0099   }
0100 }
0101 
0102 bool SingleStreamingInput::CheckPoolDepth(const uint64_t bclk)
0103 {
0104   // if (m_FEEBclkMap.size() < 10)
0105   // {
0106   //   std::cout << "not all FEEs in map: " << m_FEEBclkMap.size() << std::endl;
0107   //   return true;
0108   // }
0109   for (auto iter : m_FEEBclkMap)
0110   {
0111     if (Verbosity() > 2)
0112     {
0113       std::cout << "my bclk 0x" << std::hex << iter.second
0114                 << " req: 0x" << bclk << std::dec << std::endl;
0115     }
0116     if (iter.second < bclk)
0117     {
0118       if (Verbosity() > 1)
0119       {
0120         std::cout << "FEE " << iter.first << " beamclock 0x" << std::hex << iter.second
0121                   << " smaller than req bclk: 0x" << bclk << std::dec << std::endl;
0122       }
0123       return true;
0124     }
0125   }
0126   return false;
0127 }
0128 
0129 void SingleStreamingInput::ClearCurrentEvent()
0130 {
0131   // called interactively, to get rid of the current event
0132   uint64_t currentbclk = *m_BclkStack.begin();
0133   std::cout << "clearing bclk 0x" << std::hex << currentbclk << std::dec << std::endl;
0134   CleanupUsedPackets(currentbclk);
0135   m_BclkStack.erase(currentbclk);
0136   m_BeamClockFEE.erase(currentbclk);
0137   return;
0138 }