Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:06

0001 #include "EventNumberCheck.h"
0002 
0003 #include <fun4all/Fun4AllInputManager.h>
0004 #include <fun4all/Fun4AllReturnCodes.h>
0005 #include <fun4all/Fun4AllServer.h>
0006 #include <fun4all/SubsysReco.h>  // for SubsysReco
0007 
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/PHDataNode.h>
0010 #include <phool/PHNode.h>          // for PHNode
0011 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0012 #include <phool/getClass.h>
0013 
0014 #include <Event/Event.h>
0015 #include <Event/oncsEvent.h>
0016 
0017 #include <TSystem.h>
0018 
0019 #include <iostream>  // for operator<<, endl, basic_ost...
0020 #include <utility>   // for pair
0021 #include <vector>    // for vector
0022 
0023 //____________________________________________________________________________..
0024 EventNumberCheck::EventNumberCheck(const std::string &name)
0025   : SubsysReco(name)
0026 {
0027 }
0028 
0029 //____________________________________________________________________________..
0030 int EventNumberCheck::Init(PHCompositeNode * /*topNode*/)
0031 {
0032   return Fun4AllReturnCodes::EVENT_OK;
0033 }
0034 
0035 //____________________________________________________________________________..
0036 int EventNumberCheck::process_event(PHCompositeNode *topNode)
0037 {
0038   Fun4AllServer *se = Fun4AllServer::instance();
0039   Event *evt = findNode::getClass<Event>(topNode, m_MyPrdfNode);
0040   evt->identify();
0041   int eventno = evt->getEvtSequence();
0042   int nw = evt->getPacketList(plist, 10000);
0043   if (nw >= 10000)
0044   {
0045     std::cout << "Packet array too small, need " << nw << " entries" << std::endl;
0046     return Fun4AllReturnCodes::EVENT_OK;
0047   }
0048   auto insert_chk = m_EventSeen.insert(eventno);
0049   if (!insert_chk.second)
0050   {
0051     std::cout << "event " << eventno << " exists already"
0052               << " counter: " << se->EventNumber() << std::endl;
0053   }
0054   return Fun4AllReturnCodes::EVENT_OK;
0055 }
0056 
0057 void EventNumberCheck::CheckFem(int nw)
0058 {
0059   std::set<int> femclkcemc;
0060   std::set<int> clkcemc;
0061   std::set<int> femclkmbd;
0062   std::set<int> clkmbd;
0063   static int ifirst = 1;
0064   for (int i = 0; i < nw; i++)
0065   {
0066     int pktid = plist[i]->getIdentifier();
0067     if (pktid > 2000)
0068     {
0069       clkcemc.insert(plist[i]->iValue(0, "CLOCK"));
0070     }
0071     else
0072     {
0073       clkmbd.insert(plist[i]->iValue(0, "CLOCK"));
0074     }
0075     if (Verbosity() > 1)
0076     {
0077       std::cout << "packet " << plist[i]->getIdentifier() << ", evt nr "
0078                 << plist[i]->iValue(0, "EVTNR") << ", bclk 0x" << std::hex
0079                 << plist[i]->iValue(0, "CLOCK") << std::dec << std::endl;
0080     }
0081     for (int j = 0; j < plist[i]->iValue(0, "NRMODULES"); j++)
0082     {
0083       if (Verbosity() > 1)
0084       {
0085         std::cout << "FEM " << j << ", Clock 0x" << std::hex
0086                   << plist[i]->iValue(j, "FEMCLOCK") << std::dec << std::endl;
0087       }
0088       if (pktid > 2000)
0089       {
0090         femclkcemc.insert(plist[i]->iValue(j, "FEMCLOCK"));
0091       }
0092       else
0093       {
0094         femclkmbd.insert(plist[i]->iValue(j, "FEMCLOCK"));
0095       }
0096     }
0097     delete plist[i];
0098   }
0099   if (femclkcemc.size() > 1)
0100   {
0101     std::cout << "CEMC FEM clock mismatch, saw " << std::hex << std::endl;
0102     for (auto iter : femclkcemc)
0103     {
0104       std::cout << iter << std::endl;
0105     }
0106     std::cout << std::dec;
0107   }
0108   if (femclkmbd.size() > 1)
0109   {
0110     std::cout << "MBD FEM clock mismatch, saw " << std::hex << std::endl;
0111     for (auto iter : femclkmbd)
0112     {
0113       std::cout << iter << std::endl;
0114     }
0115     std::cout << std::dec;
0116   }
0117   if (clkcemc.size() > 1)
0118   {
0119     std::cout << "CEMC Packet clock mismatch, saw " << std::hex << std::endl;
0120     for (auto iter : clkcemc)
0121     {
0122       std::cout << iter << std::endl;
0123     }
0124     std::cout << std::dec;
0125   }
0126   if (clkmbd.size() > 1)
0127   {
0128     std::cout << "MBD Packet clock mismatch, saw " << std::hex << std::endl;
0129     for (auto iter : clkmbd)
0130     {
0131       std::cout << iter << std::endl;
0132     }
0133     std::cout << std::dec;
0134   }
0135 
0136   int femclockcemc = *(clkcemc.begin());
0137   int femclockmbd = *(clkmbd.begin());
0138   if (previous_event_clkdiff != femclockcemc - femclockmbd)
0139   {
0140     if (ifirst)
0141     {
0142       ifirst = 0;
0143     }
0144     else
0145     {
0146       std::cout << "clock diff changed at event "  //<< eventno
0147                 << " from " << previous_event_clkdiff << " to "
0148                 << femclockcemc - femclockmbd << std::endl;
0149     }
0150     previous_event_clkdiff = femclockcemc - femclockmbd;
0151   }
0152   return;
0153 }