Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "Fun4AllTriggeredInputManager.h"
0002 
0003 #include "SingleTriggeredInput.h"
0004 
0005 #include <fun4all/Fun4AllInputManager.h>  // for Fun4AllInputManager
0006 #include <fun4all/Fun4AllReturnCodes.h>
0007 #include <fun4all/Fun4AllServer.h>
0008 #include <fun4all/Fun4AllSyncManager.h>
0009 
0010 #include <ffaobjects/SyncObject.h>    // for SyncObject
0011 #include <ffaobjects/SyncObjectv1.h>  // for SyncObject
0012 
0013 #include <ffarawobjects/CaloPacket.h>
0014 #include <ffarawobjects/CaloPacketContainer.h>
0015 #include <ffarawobjects/Gl1Packet.h>
0016 #include <ffarawobjects/LL1Packet.h>
0017 #include <ffarawobjects/LL1PacketContainer.h>
0018 
0019 #include <phool/PHCompositeNode.h>
0020 #include <phool/PHDataNode.h>
0021 #include <phool/PHNode.h>          // for PHNode
0022 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0023 #include <phool/PHObject.h>        // for PHObject
0024 #include <phool/getClass.h>
0025 #include <phool/phool.h>  // for PHWHERE
0026 
0027 #include <TSystem.h>
0028 
0029 #include <algorithm>  // for std::search
0030 #include <cassert>
0031 #include <climits>
0032 #include <cstdlib>
0033 #include <iostream>  // for operator<<, basic_ostream, endl
0034 #include <utility>   // for pair
0035 
0036 Fun4AllTriggeredInputManager::Fun4AllTriggeredInputManager(const std::string &name, const std::string &prdfnodename, const std::string &topnodename)
0037   : Fun4AllInputManager(name, prdfnodename, topnodename)
0038   , m_SyncObject(new SyncObjectv1())
0039 {
0040   Fun4AllServer *se = Fun4AllServer::instance();
0041   m_topNode = se->topNode(TopNodeName());
0042 }
0043 
0044 Fun4AllTriggeredInputManager::~Fun4AllTriggeredInputManager()
0045 {
0046   if (IsOpen())
0047   {
0048     fileclose();
0049   }
0050   delete m_SyncObject;
0051   for (auto *iter : m_TriggeredInputVector)
0052   {
0053     if (Verbosity() > 1)
0054     {
0055       std::cout << PHWHERE << " deleting " << iter->Name() << std::endl;
0056     }
0057     delete iter;
0058   }
0059 }
0060 
0061 int Fun4AllTriggeredInputManager::run(const int /*nevents*/)
0062 {
0063   m_Gl1TriggeredInput->FillPool();
0064   for (auto *iter : m_TriggeredInputVector)
0065   {
0066     //    std::cout << "prdf input: " << iter->Name() << std::endl;
0067     iter->FillPool();
0068     if (iter->AllDone())
0069     {
0070       return -1;
0071     }
0072   }
0073   m_Gl1TriggeredInput->ReadEvent();
0074   for (auto *iter : m_TriggeredInputVector)
0075   {
0076     //    std::cout << "prdf input: " << iter->Name() << std::endl;
0077     iter->ReadEvent();
0078     if (iter->AllDone())
0079     {
0080       return -1;
0081     }
0082   }
0083 
0084   if (m_RunNumber == 0)
0085   {
0086     m_RunNumber = m_Gl1TriggeredInput->RunNumber();
0087     SetRunNumber(m_RunNumber);
0088   }
0089   if (m_Gl1TriggeredInput->AllDone())
0090   {
0091     return -1;
0092   }
0093   EventNumber(m_Gl1TriggeredInput->EventNumber());
0094   m_SyncObject->EventNumber(EventNumber());
0095   m_SyncObject->RunNumber(m_RunNumber);
0096   m_SyncObject->SegmentNumber(0);
0097   //    std::cout << "saving event on dst" << std::endl;
0098   return 0;
0099 }
0100 
0101 int Fun4AllTriggeredInputManager::fileclose()
0102 {
0103   // for (auto iter : m_TriggerInputVector)
0104   // {
0105   //   delete iter;
0106   // }
0107   //  m_TriggerInputVector.clear();
0108   return 0;
0109 }
0110 
0111 void Fun4AllTriggeredInputManager::Print(const std::string &what) const
0112 {
0113   std::cout << "Triggered Inputs" << std::endl;
0114   if (what == "ALL" || what == "INPUT")
0115   {
0116     for (auto *iter : m_TriggeredInputVector)
0117     {
0118       std::cout << "prdf input: " << iter->Name() << std::endl;
0119     }
0120   }
0121   return;
0122 }
0123 
0124 int Fun4AllTriggeredInputManager::ResetEvent()
0125 {
0126   return 0;
0127 }
0128 
0129 int Fun4AllTriggeredInputManager::PushBackEvents(const int /*i*/)
0130 {
0131   return 0;
0132 }
0133 
0134 int Fun4AllTriggeredInputManager::GetSyncObject(SyncObject **mastersync)
0135 {
0136   // here we copy the sync object from the current file to the
0137   // location pointed to by mastersync. If mastersync is a 0 pointer
0138   // the syncobject is cloned. If mastersync allready exists the content
0139   // of syncobject is copied
0140   if (!(*mastersync))
0141   {
0142     if (m_SyncObject)
0143     {
0144       *mastersync = dynamic_cast<SyncObject *>(m_SyncObject->CloneMe());
0145       assert(*mastersync);
0146     }
0147   }
0148   else
0149   {
0150     *(*mastersync) = *m_SyncObject;  // copy syncobject content
0151   }
0152   return Fun4AllReturnCodes::SYNC_OK;
0153 }
0154 
0155 int Fun4AllTriggeredInputManager::SyncIt(const SyncObject *mastersync)
0156 {
0157   if (!mastersync)
0158   {
0159     std::cout << PHWHERE << Name() << " No MasterSync object, cannot perform synchronization" << std::endl;
0160     std::cout << "Most likely your first file does not contain a SyncObject and the file" << std::endl;
0161     std::cout << "opened by the Fun4AllDstInputManager with Name " << Name() << " has one" << std::endl;
0162     std::cout << "Change your macro and use the file opened by this input manager as first input" << std::endl;
0163     std::cout << "and you will be okay. Fun4All will not process the current configuration" << std::endl
0164               << std::endl;
0165     return Fun4AllReturnCodes::SYNC_FAIL;
0166   }
0167   int iret = m_SyncObject->Different(mastersync);
0168   if (iret)
0169   {
0170     std::cout << "big problem" << std::endl;
0171     exit(1);
0172   }
0173   return Fun4AllReturnCodes::SYNC_OK;
0174 }
0175 
0176 std::string Fun4AllTriggeredInputManager::GetString(const std::string &what) const
0177 {
0178   std::cout << PHWHERE << " called with " << what << " , returning empty string" << std::endl;
0179   return "";
0180 }
0181 
0182 void Fun4AllTriggeredInputManager::registerGl1TriggeredInput(SingleTriggeredInput *prdfin)
0183 {
0184   m_Gl1TriggeredInput = prdfin;
0185   prdfin->topNode(m_topNode);
0186   std::cout << "registering " << prdfin->Name() << std::endl;
0187 }
0188 
0189 void Fun4AllTriggeredInputManager::registerTriggeredInput(SingleTriggeredInput *prdfin)
0190 {
0191   if (m_Gl1TriggeredInput == nullptr)
0192   {
0193     std::cout << "You need to register the Gl1 input manager first" << std::endl;
0194     gSystem->Exit(1);
0195     exit(1);
0196   }
0197   m_TriggeredInputVector.push_back(prdfin);
0198   prdfin->Gl1Input(m_Gl1TriggeredInput);
0199   prdfin->topNode(m_topNode);
0200   std::cout << "registering " << prdfin->Name() << std::endl;
0201   //  prdfin->CreateDSTNode(m_topNode);
0202   //  prdfin->TriggerInputManager(this);
0203   return;
0204 }