Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:39

0001 /*
0002  *   File: DataFormats/Scalers/src/Level1TriggerRates.cc   (W.Badgett)
0003  */
0004 
0005 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
0006 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0007 
0008 #include <iostream>
0009 #include <cstdio>
0010 
0011 Level1TriggerRates::Level1TriggerRates()
0012     : version_(0),
0013       collectionTime_(0, 0),
0014       deltaNS_(0),
0015       deltaT_(0.0),
0016       gtTriggersRate_(0.0),
0017       gtEventsRate_(0.0),
0018       collectionTimeLumiSeg_(0, 0),
0019       triggersPhysicsGeneratedFDLRate_(0.0),
0020       triggersPhysicsLostRate_(0.0),
0021       triggersPhysicsLostBeamActiveRate_(0.0),
0022       triggersPhysicsLostBeamInactiveRate_(0.0),
0023       l1AsPhysicsRate_(0.0),
0024       l1AsRandomRate_(0.0),
0025       l1AsTestRate_(0.0),
0026       l1AsCalibrationRate_(0.0),
0027       deadtimePercent_(0.0),
0028       deadtimeBeamActivePercent_(0.0),
0029       deadtimeBeamActiveTriggerRulesPercent_(0.0),
0030       deadtimeBeamActiveCalibrationPercent_(0.0),
0031       deadtimeBeamActivePrivateOrbitPercent_(0.0),
0032       deadtimeBeamActivePartitionControllerPercent_(0.0),
0033       deadtimeBeamActiveTimeSlotPercent_(0.0),
0034       gtAlgoCountsRate_(Level1TriggerScalers::nLevel1Triggers),
0035       gtTechCountsRate_(Level1TriggerScalers::nLevel1TestTriggers) {}
0036 
0037 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s) {
0038   Level1TriggerRates(s, Level1TriggerScalers::firstShortLSRun);
0039 }
0040 
0041 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s, int runNumber) {
0042   Level1TriggerRates();
0043   computeRates(s, runNumber);
0044 }
0045 
0046 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s1, Level1TriggerScalers const& s2) {
0047   Level1TriggerRates(s1, s2, Level1TriggerScalers::firstShortLSRun);
0048 }
0049 
0050 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s1, Level1TriggerScalers const& s2, int runNumber) {
0051   Level1TriggerRates();
0052   computeRates(s1, s2, runNumber);
0053 }
0054 
0055 Level1TriggerRates::~Level1TriggerRates() {}
0056 
0057 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t) {
0058   computeRates(t, Level1TriggerScalers::firstShortLSRun);
0059 }
0060 
0061 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t, int run) {
0062   version_ = t.version();
0063 
0064   collectionTime_.set_tv_sec(static_cast<long>(t.collectionTime().tv_sec));
0065   collectionTime_.set_tv_nsec(t.collectionTime().tv_nsec);
0066 
0067   gtTriggersRate_ = t.gtTriggersRate();
0068   gtEventsRate_ = t.gtEventsRate();
0069 
0070   collectionTimeLumiSeg_.set_tv_sec(static_cast<long>(t.collectionTimeLumiSeg().tv_sec));
0071   collectionTimeLumiSeg_.set_tv_nsec(t.collectionTimeLumiSeg().tv_nsec);
0072 
0073   triggersPhysicsGeneratedFDLRate_ = Level1TriggerScalers::rateLS(t.triggersPhysicsGeneratedFDL(), run);
0074   triggersPhysicsLostRate_ = Level1TriggerScalers::rateLS(t.triggersPhysicsLost(), run);
0075   triggersPhysicsLostBeamActiveRate_ = Level1TriggerScalers::rateLS(t.triggersPhysicsLostBeamActive(), run);
0076   triggersPhysicsLostBeamInactiveRate_ = Level1TriggerScalers::rateLS(t.triggersPhysicsLostBeamInactive(), run);
0077 
0078   l1AsPhysicsRate_ = Level1TriggerScalers::rateLS(t.l1AsPhysics(), run);
0079   l1AsRandomRate_ = Level1TriggerScalers::rateLS(t.l1AsRandom(), run);
0080   l1AsTestRate_ = Level1TriggerScalers::rateLS(t.l1AsTest(), run);
0081   l1AsCalibrationRate_ = Level1TriggerScalers::rateLS(t.l1AsCalibration(), run);
0082 
0083   deadtimePercent_ = Level1TriggerScalers::percentLS(t.deadtime(), run);
0084   deadtimeBeamActivePercent_ = Level1TriggerScalers::percentLSActive(t.deadtimeBeamActive(), run);
0085   deadtimeBeamActiveTriggerRulesPercent_ =
0086       Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveTriggerRules(), run);
0087   deadtimeBeamActiveCalibrationPercent_ = Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveCalibration(), run);
0088   deadtimeBeamActivePrivateOrbitPercent_ =
0089       Level1TriggerScalers::percentLSActive(t.deadtimeBeamActivePrivateOrbit(), run);
0090   deadtimeBeamActivePartitionControllerPercent_ =
0091       Level1TriggerScalers::percentLSActive(t.deadtimeBeamActivePartitionController(), run);
0092   deadtimeBeamActiveTimeSlotPercent_ = Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveTimeSlot(), run);
0093 
0094   const std::vector<unsigned int> gtAlgoCounts = t.gtAlgoCounts();
0095   for (std::vector<unsigned int>::const_iterator counts = gtAlgoCounts.begin(); counts != gtAlgoCounts.end();
0096        ++counts) {
0097     gtAlgoCountsRate_.push_back(Level1TriggerScalers::rateLS(*counts, run));
0098   }
0099 
0100   const std::vector<unsigned int> gtTechCounts = t.gtTechCounts();
0101   for (std::vector<unsigned int>::const_iterator counts = gtTechCounts.begin(); counts != gtTechCounts.end();
0102        ++counts) {
0103     gtTechCountsRate_.push_back(Level1TriggerScalers::rateLS(*counts, run));
0104   }
0105 
0106   deltaNS_ = 0ULL;
0107   deltaT_ = 0.0;
0108 }
0109 
0110 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t1, Level1TriggerScalers const& t2) {
0111   computeRates(t1, t2, Level1TriggerScalers::firstShortLSRun);
0112 }
0113 
0114 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t1, Level1TriggerScalers const& t2, int run) {
0115   computeRates(t1, run);
0116 
0117   unsigned long long zeit1 = ((unsigned long long)t1.collectionTime().tv_sec * 1000000000ULL) |
0118                              ((unsigned long long)t1.collectionTime().tv_nsec);
0119   unsigned long long zeit2 = ((unsigned long long)t2.collectionTime().tv_sec * 1000000000ULL) |
0120                              ((unsigned long long)t2.collectionTime().tv_nsec);
0121 
0122   deltaT_ = 0.0;
0123   deltaNS_ = 0ULL;
0124   if (zeit2 > zeit1) {
0125     deltaNS_ = zeit2 - zeit1;
0126     deltaT_ = ((double)deltaNS_) / 1.0E9;
0127     gtTriggersRate_ = ((double)(t2.gtTriggers() - t1.gtTriggers())) / deltaT_;
0128     gtEventsRate_ = ((double)(t2.gtEvents() - t1.gtEvents())) / deltaT_;
0129   }
0130 }
0131 
0132 /// Pretty-print operator for Level1TriggerRates
0133 std::ostream& operator<<(std::ostream& s, const Level1TriggerRates& c) {
0134   constexpr size_t kLineBufferSize = 164;
0135   char line[kLineBufferSize];
0136   char zeitHeaven[128];
0137   struct tm* horaHeaven;
0138 
0139   s << "Level1TriggerRates Version: " << c.version() << " Rates in Hz, DeltaT: ";
0140 
0141   if (c.deltaNS() > 0) {
0142     s << c.deltaT() << " sec" << std::endl;
0143   } else {
0144     s << "n/a" << std::endl;
0145   }
0146 
0147   struct timespec secondsToHeaven = c.collectionTime();
0148   horaHeaven = gmtime(&secondsToHeaven.tv_sec);
0149   strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
0150   snprintf(line, kLineBufferSize, " CollectionTime:        %s.%9.9d", zeitHeaven, (int)secondsToHeaven.tv_nsec);
0151   s << line << std::endl;
0152 
0153   snprintf(line, kLineBufferSize, " GtTriggersRate:                              %22.3f Hz", c.gtTriggersRate());
0154   s << line << std::endl;
0155 
0156   snprintf(line, kLineBufferSize, " GtEventsRate:                                %22.3f Hz", c.gtEventsRate());
0157   s << line << std::endl;
0158 
0159   secondsToHeaven = c.collectionTimeLumiSeg();
0160   horaHeaven = gmtime(&secondsToHeaven.tv_sec);
0161   strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
0162   snprintf(line, kLineBufferSize, " CollectionTimeLumiSeg: %s.%9.9d", zeitHeaven, (int)secondsToHeaven.tv_nsec);
0163   s << line << std::endl;
0164 
0165   snprintf(line,
0166            kLineBufferSize,
0167            " TriggersPhysicsGeneratedFDLRate:             %22.3f Hz",
0168            c.triggersPhysicsGeneratedFDLRate());
0169   s << line << std::endl;
0170 
0171   snprintf(
0172       line, kLineBufferSize, " TriggersPhysicsLostRate:                     %22.3f Hz", c.triggersPhysicsLostRate());
0173   s << line << std::endl;
0174 
0175   snprintf(line,
0176            kLineBufferSize,
0177            " TriggersPhysicsLostBeamActiveRate:           %22.3f Hz",
0178            c.triggersPhysicsLostBeamActiveRate());
0179   s << line << std::endl;
0180 
0181   snprintf(line,
0182            kLineBufferSize,
0183            " TriggersPhysicsLostBeamInactiveRate:         %22.3f Hz",
0184            c.triggersPhysicsLostBeamInactiveRate());
0185   s << line << std::endl;
0186 
0187   snprintf(line, kLineBufferSize, " L1AsPhysicsRate:                             %22.3f Hz", c.l1AsPhysicsRate());
0188   s << line << std::endl;
0189 
0190   snprintf(line, kLineBufferSize, " L1AsRandomRate:                              %22.3f Hz", c.l1AsRandomRate());
0191   s << line << std::endl;
0192 
0193   snprintf(line, kLineBufferSize, " L1AsTestRate:                                %22.3f Hz", c.l1AsTestRate());
0194   s << line << std::endl;
0195 
0196   snprintf(line, kLineBufferSize, " L1AsCalibrationRate:                         %22.3f Hz", c.l1AsCalibrationRate());
0197   s << line << std::endl;
0198 
0199   snprintf(line, kLineBufferSize, " DeadtimePercent:                             %22.3f %%", c.deadtimePercent());
0200   s << line << std::endl;
0201 
0202   snprintf(
0203       line, kLineBufferSize, " DeadtimeBeamActivePercent:                   %22.3f %%", c.deadtimeBeamActivePercent());
0204   s << line << std::endl;
0205 
0206   snprintf(line,
0207            kLineBufferSize,
0208            " DeadtimeBeamActiveTriggerRulesPercent:       %22.3f %%",
0209            c.deadtimeBeamActiveTriggerRulesPercent());
0210   s << line << std::endl;
0211 
0212   snprintf(line,
0213            kLineBufferSize,
0214            " DeadtimeBeamActiveCalibrationPercent:        %22.3f %%",
0215            c.deadtimeBeamActiveCalibrationPercent());
0216   s << line << std::endl;
0217 
0218   snprintf(line,
0219            kLineBufferSize,
0220            " DeadtimeBeamActivePrivateOrbitPercent:       %22.3f %%",
0221            c.deadtimeBeamActivePrivateOrbitPercent());
0222   s << line << std::endl;
0223 
0224   snprintf(line,
0225            kLineBufferSize,
0226            " DeadtimeBeamActivePartitionControllerPercent:%22.3f %%",
0227            c.deadtimeBeamActivePartitionControllerPercent());
0228   s << line << std::endl;
0229 
0230   snprintf(line,
0231            kLineBufferSize,
0232            " DeadtimeBeamActiveTimeSlotPercent:           %22.3f %%",
0233            c.deadtimeBeamActiveTimeSlotPercent());
0234   s << line << std::endl;
0235 
0236   s << "Physics GtAlgoCountsRate, Hz" << std::endl;
0237   const std::vector<double> gtAlgoCountsRate = c.gtAlgoCountsRate();
0238   int length = gtAlgoCountsRate.size() / 4;
0239   for (int i = 0; i < length; i++) {
0240     snprintf(line,
0241              kLineBufferSize,
0242              " %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f",
0243              i,
0244              gtAlgoCountsRate[i],
0245              (i + length),
0246              gtAlgoCountsRate[i + length],
0247              (i + (length * 2)),
0248              gtAlgoCountsRate[i + (length * 2)],
0249              (i + (length * 3)),
0250              gtAlgoCountsRate[i + (length * 3)]);
0251     s << line << std::endl;
0252   }
0253 
0254   s << "Test GtTechCountsRate, Hz" << std::endl;
0255   const std::vector<double> gtTechCountsRate = c.gtTechCountsRate();
0256   length = gtTechCountsRate.size() / 4;
0257   for (int i = 0; i < length; i++) {
0258     snprintf(line,
0259              kLineBufferSize,
0260              " %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f",
0261              i,
0262              gtTechCountsRate[i],
0263              (i + length),
0264              gtTechCountsRate[i + length],
0265              (i + (length * 2)),
0266              gtTechCountsRate[i + (length * 2)],
0267              (i + (length * 3)),
0268              gtTechCountsRate[i + (length * 3)]);
0269     s << line << std::endl;
0270   }
0271   return s;
0272 }