Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:20:28

0001 #include "PktSizeCommon.h"
0002 #include <onlmon/OnlMonServer.h>
0003 
0004 #include <cstdlib>
0005 #include <fstream>
0006 #include <iostream>
0007 #include <set>
0008 #include <sstream>
0009 #include <string>
0010 
0011 int PktSizeCommon::fillgranules(std::map<std::string, std::pair<unsigned int, unsigned int> > &granulepacketlimits)
0012 {
0013   std::pair<unsigned int, unsigned int> pktlimits;
0014   pktlimits.first = 17000;
0015   pktlimits.second = 17999;
0016   granulepacketlimits["ACC"] = pktlimits;
0017 
0018   pktlimits.first = 1000;
0019   pktlimits.second = 1999;
0020   granulepacketlimits["BBC"] = pktlimits;
0021 
0022   pktlimits.first = 3000;
0023   pktlimits.second = 3999;
0024   granulepacketlimits["DCH"] = pktlimits;
0025 
0026   pktlimits.first = 8000;
0027   pktlimits.second = 8999;
0028   granulepacketlimits["EMC"] = pktlimits;
0029 
0030   pktlimits.first = 14200;
0031   pktlimits.second = 14201;
0032   granulepacketlimits["ERT"] = pktlimits;
0033 
0034   //   pktlimits.first = 16000;
0035   //   pktlimits.second = 16999;
0036   //   granulepacketlimits["FCAL"] = pktlimits;
0037 
0038   pktlimits.first = 25000;
0039   pktlimits.second = 25999;
0040   granulepacketlimits["FVTX"] = pktlimits;
0041 
0042   pktlimits.first = 14000;
0043   pktlimits.second = 14024;
0044   granulepacketlimits["GL1"] = pktlimits;
0045 
0046   pktlimits.first = 14050;
0047   pktlimits.second = 14199;
0048   granulepacketlimits["LVL2"] = pktlimits;
0049 
0050   pktlimits.first = 14777;
0051   pktlimits.second = 14777;
0052   granulepacketlimits["LVL1"] = pktlimits;
0053 
0054   pktlimits.first = 21100;
0055   pktlimits.second = 21110;
0056   granulepacketlimits["MPC"] = pktlimits;
0057 
0058   pktlimits.first = 12000;
0059   pktlimits.second = 12999;
0060   granulepacketlimits["MUID"] = pktlimits;
0061 
0062   pktlimits.first = 11000;
0063   pktlimits.second = 11999;
0064   granulepacketlimits["MUTR"] = pktlimits;
0065 
0066   //   this one is for testing if no packet exists
0067   //   pktlimits.first = 2000;
0068   //   pktlimits.second = 2999;
0069   //   granulepacketlimits["MVD"] = pktlimits;
0070 
0071   pktlimits.first = 4000;
0072   pktlimits.second = 4999;
0073   granulepacketlimits["PAD"] = pktlimits;
0074 
0075   pktlimits.first = 6000;
0076   pktlimits.second = 6999;
0077   granulepacketlimits["RICH"] = pktlimits;
0078 
0079   pktlimits.first = 19000;
0080   pktlimits.second = 19999;
0081   granulepacketlimits["RPC"] = pktlimits;
0082 
0083   pktlimits.first = 7000;
0084   pktlimits.second = 7099;
0085   granulepacketlimits["TOFE"] = pktlimits;
0086 
0087   pktlimits.first = 7100;
0088   pktlimits.second = 7999;
0089   granulepacketlimits["TOFW"] = pktlimits;
0090 
0091   pktlimits.first = 21300;
0092   pktlimits.second = 21360;
0093   granulepacketlimits["MPCEX"] = pktlimits;
0094 
0095   pktlimits.first = 24000;
0096   pktlimits.second = 24099;
0097   granulepacketlimits["VTXP"] = pktlimits;
0098 
0099   pktlimits.first = 24100;
0100   pktlimits.second = 24199;
0101   granulepacketlimits["VTXS"] = pktlimits;
0102 
0103   pktlimits.first = 13000;
0104   pktlimits.second = 13999;
0105   granulepacketlimits["ZDC"] = pktlimits;
0106 
0107   return 0;
0108 }
0109 
0110 int PktSizeCommon::filldcmgroups(std::map<unsigned int, std::string> &dcmgroupmap)
0111 {
0112   //  OnlMonServer *se = OnlMonServer::instance();
0113   std::set<std::string> pcffiles;
0114   //  se->parse_granuleDef(pcffiles);
0115   std::set<std::string>::const_iterator piter;
0116   for (piter = pcffiles.begin(); piter != pcffiles.end(); ++piter)
0117   {
0118     std::ostringstream filenam;
0119     if (getenv("ONLINE_CONFIGURATION"))
0120     {
0121       filenam << getenv("ONLINE_CONFIGURATION") << "/rc/hw/";
0122     }
0123     filenam << *piter;
0124     std::ifstream infile;
0125     infile.open(filenam.str().c_str(), std::ifstream::in);
0126     if (!infile)
0127     {
0128       if (filenam.str().find("gl1test.pcf") != std::string::npos)
0129       {
0130         std::cout << "  Could not open " << filenam.str() << std::endl;
0131       }
0132       continue;
0133     }
0134     std::string FullLine;  // a complete line in the config file
0135     getline(infile, FullLine);
0136     std::string::size_type pos1;
0137     std::string::size_type pos2;
0138     std::string dcmgrp = "NONE";
0139     while (!infile.eof())
0140 
0141     {
0142       if (FullLine.find("//") == std::string::npos)
0143       {
0144         if ((pos1 = FullLine.find("DCMGROUP")) != std::string::npos && FullLine.find("level1dd") != std::string::npos)
0145         {
0146           FullLine.erase(0, pos1);  // erase all before DCMGROUP string
0147           pos2 = FullLine.find(',');
0148           dcmgrp = FullLine.substr(0, pos2);
0149           //                  std::cout << dcmgrp << std::endl;
0150         }
0151         if ((pos1 = FullLine.find("packetid")) != std::string::npos)
0152         {
0153           FullLine.erase(0, pos1);  // erase all before packetid string
0154           while ((pos1 = FullLine.find(':')) != std::string::npos)
0155           {
0156             pos2 = FullLine.find(',');
0157             // search the int between the ":" and the ","
0158             std::string packetidstr = FullLine.substr(pos1 + 1, pos2 - (pos1 + 1));
0159             std::istringstream line;
0160             line.str(packetidstr);
0161             unsigned int packetid;
0162             line >> packetid;
0163             if (packetid > 0)
0164             {
0165               if (dcmgrp != "NONE")
0166               {
0167                 dcmgroupmap[packetid] = dcmgrp;
0168               }
0169               else
0170               {
0171                 std::cout << "error assigning packet " << packetid << " to dcm group" << std::endl;
0172               }
0173             }
0174             // erase this entry from the line
0175             FullLine.erase(0, pos2 + 1);
0176           }
0177         }
0178       }
0179       getline(infile, FullLine);
0180     }
0181     infile.close();
0182   }
0183   return 0;
0184 }
0185 
0186 int PktSizeCommon::fillfibergroups(std::map<unsigned int, std::string> &fibergroupmap)
0187 {
0188   //  OnlMonServer *se = OnlMonServer::instance();
0189   std::set<std::string> pcffiles;
0190   //  se->parse_granuleDef(pcffiles);
0191   std::set<std::string>::const_iterator piter;
0192   for (piter = pcffiles.begin(); piter != pcffiles.end(); ++piter)
0193   {
0194     std::ostringstream filenam;
0195     if (getenv("ONLINE_CONFIGURATION"))
0196     {
0197       filenam << getenv("ONLINE_CONFIGURATION") << "/rc/hw/";
0198     }
0199     filenam << *piter;
0200     std::ifstream infile;
0201     infile.open(filenam.str().c_str(), std::ifstream::in);
0202     if (!infile)
0203     {
0204       std::cout << "  Could not open " << filenam.str() << std::endl;
0205       continue;
0206     }
0207     std::string FullLine;  // a complete line in the config file
0208     getline(infile, FullLine);
0209     std::string::size_type pos1;
0210     std::string::size_type pos2;
0211     std::string dcmgrp = "NONE";
0212     std::string unitgrp = "NONE";
0213     while (!infile.eof())
0214     {
0215       if (FullLine.find("//") == std::string::npos)
0216       {
0217         if ((pos1 = FullLine.find("DCMGROUP")) != std::string::npos && FullLine.find("level1dd") != std::string::npos)
0218         {
0219           FullLine.erase(0, pos1);  // erase all before DCMGROUP string
0220           pos2 = FullLine.find(',');
0221           dcmgrp = FullLine.substr(0, pos2);
0222           //                  std::cout << dcmgrp << std::endl;
0223         }
0224         if ((pos1 = FullLine.find("unit")) != std::string::npos)
0225         {
0226           FullLine.erase(0, pos1);  // erase all before unit string
0227           pos1 = FullLine.find(':');
0228           FullLine.erase(0, pos1 + 1);  // erase all before : string
0229           pos2 = FullLine.find(',');
0230           unitgrp = FullLine.substr(0, pos2);
0231           //                  std::cout << unitgrp << std::endl;
0232         }
0233         if ((pos1 = FullLine.find("packetid")) != std::string::npos)
0234         {
0235           FullLine.erase(0, pos1);  // erase all before packetid string
0236           while ((pos1 = FullLine.find(':')) != std::string::npos)
0237           {
0238             pos2 = FullLine.find(',');
0239             // search the int between the ":" and the ","
0240             std::string packetidstr = FullLine.substr(pos1 + 1, pos2 - (pos1 + 1));
0241             std::istringstream line;
0242             line.str(packetidstr);
0243             unsigned int packetid;
0244             line >> packetid;
0245             if (packetid > 0)
0246             {
0247               if (dcmgrp != "NONE" && unitgrp != "NONE")
0248               {
0249                 std::string fibergrp = dcmgrp + ":" + unitgrp;
0250                 fibergroupmap[packetid] = fibergrp;
0251               }
0252               else
0253               {
0254                 std::cout << "error assigning packet " << packetid << " to fiber group" << std::endl;
0255               }
0256             }
0257             // erase this entry from the line
0258             FullLine.erase(0, pos2 + 1);
0259           }
0260         }
0261       }
0262       getline(infile, FullLine);
0263     }
0264     infile.close();
0265   }
0266   return 0;
0267 }