Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 /*
0003  *   File: DataFormats/Scalers/src/L1TriggerScalers.cc   (W.Badgett)
0004  */
0005 
0006 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
0007 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0008 
0009 #include <iostream>
0010 #include <cstdio>
0011 
0012 L1TriggerScalers::L1TriggerScalers()
0013     : version_(0),
0014       collectionTimeSpecial_(0, 0),
0015       orbitNumber_(0),
0016       luminositySection_(0),
0017       bunchCrossingErrors_(0),
0018       collectionTimeSummary_(0, 0),
0019       triggerNumber_(0),
0020       eventNumber_(0),
0021       finalTriggersDistributed_(0),
0022       calibrationTriggers_(0),
0023       randomTriggers_(0),
0024       totalTestTriggers_(0),
0025       finalTriggersGenerated_(0),
0026       finalTriggersInvalidBC_(0),
0027       deadTime_(0),
0028       lostFinalTriggers_(0),
0029       deadTimeActive_(0),
0030       lostFinalTriggersActive_(0),
0031       deadTimeActivePrivate_(0),
0032       deadTimeActivePartition_(0),
0033       deadTimeActiveThrottle_(0),
0034       deadTimeActiveCalibration_(0),
0035       deadTimeActiveTimeSlot_(0),
0036       numberResets_(0),
0037       collectionTimeDetails_(0, 0),
0038       triggers_(nL1Triggers),
0039       testTriggers_(nL1TestTriggers) {}
0040 
0041 L1TriggerScalers::L1TriggerScalers(const unsigned char* rawData) {
0042   L1TriggerScalers();
0043 
0044   struct ScalersEventRecordRaw_v1 const* raw = reinterpret_cast<struct ScalersEventRecordRaw_v1 const*>(rawData);
0045 
0046   trigType_ = (raw->header >> 56) & 0xFULL;
0047   eventID_ = (raw->header >> 32) & 0x00FFFFFFULL;
0048   sourceID_ = (raw->header >> 8) & 0x00000FFFULL;
0049   bunchNumber_ = (raw->header >> 20) & 0xFFFULL;
0050 
0051   version_ = raw->version;
0052   if ((version_ == 1) || (version_ == 2)) {
0053     collectionTimeSpecial_.set_tv_sec(static_cast<long>(raw->trig.collectionTimeSpecial_sec));
0054     collectionTimeSpecial_.set_tv_nsec(raw->trig.collectionTimeSpecial_nsec);
0055     orbitNumber_ = raw->trig.ORBIT_NUMBER;
0056     luminositySection_ = raw->trig.LUMINOSITY_SEGMENT;
0057     bunchCrossingErrors_ = raw->trig.BC_ERRORS;
0058 
0059     collectionTimeSummary_.set_tv_sec(static_cast<long>(raw->trig.collectionTimeSummary_sec));
0060     collectionTimeSummary_.set_tv_nsec(raw->trig.collectionTimeSummary_nsec);
0061 
0062     triggerNumber_ = raw->trig.TRIGGER_NR;
0063     eventNumber_ = raw->trig.EVENT_NR;
0064     finalTriggersDistributed_ = raw->trig.FINOR_DISTRIBUTED;
0065     calibrationTriggers_ = raw->trig.CAL_TRIGGER;
0066     randomTriggers_ = raw->trig.RANDOM_TRIGGER;
0067     totalTestTriggers_ = raw->trig.TEST_TRIGGER;
0068 
0069     finalTriggersGenerated_ = raw->trig.FINOR_GENERATED;
0070     finalTriggersInvalidBC_ = raw->trig.FINOR_IN_INVALID_BC;
0071 
0072     deadTime_ = raw->trig.DEADTIME;
0073     lostFinalTriggers_ = raw->trig.LOST_FINOR;
0074     deadTimeActive_ = raw->trig.DEADTIMEA;
0075     lostFinalTriggersActive_ = raw->trig.LOST_FINORA;
0076     deadTimeActivePrivate_ = raw->trig.PRIV_DEADTIMEA;
0077     deadTimeActivePartition_ = raw->trig.PTCSTATUS_DEADTIMEA;
0078     deadTimeActiveThrottle_ = raw->trig.THROTTLE_DEADTIMEA;
0079     deadTimeActiveCalibration_ = raw->trig.CALIBRATION_DEADTIMEA;
0080     deadTimeActiveTimeSlot_ = raw->trig.TIMESLOT_DEADTIMEA;
0081     numberResets_ = raw->trig.NR_OF_RESETS;
0082 
0083     collectionTimeDetails_.set_tv_sec(static_cast<long>(raw->trig.collectionTimeDetails_sec));
0084     collectionTimeDetails_.set_tv_nsec(raw->trig.collectionTimeDetails_nsec);
0085 
0086     for (int i = 0; i < ScalersRaw::N_L1_TRIGGERS_v1; i++) {
0087       triggers_.push_back(raw->trig.ALGO_RATE[i]);
0088     }
0089 
0090     for (int i = 0; i < ScalersRaw::N_L1_TEST_TRIGGERS_v1; i++) {
0091       testTriggers_.push_back(raw->trig.TEST_RATE[i]);
0092     }
0093   }
0094 }
0095 
0096 L1TriggerScalers::~L1TriggerScalers() {}
0097 
0098 /// Pretty-print operator for L1TriggerScalers
0099 std::ostream& operator<<(std::ostream& s, L1TriggerScalers const& c) {
0100   s << "L1TriggerScalers    Version:" << c.version() << "   SourceID: " << c.sourceID() << std::endl;
0101   constexpr size_t kLineBufferSize = 164;
0102   char line[kLineBufferSize];
0103   char zeitHeaven[128];
0104   char zeitHell[128];
0105   char zeitLimbo[128];
0106   struct tm* horaHeaven;
0107   struct tm* horaHell;
0108   struct tm* horaLimbo;
0109 
0110   sprintf(line, " TrigType: %d   EventID: %d    BunchNumber: %d", c.trigType(), c.eventID(), c.bunchNumber());
0111   s << line << std::endl;
0112 
0113   timespec secondsToHeaven = c.collectionTimeSummary();
0114   horaHeaven = gmtime(&secondsToHeaven.tv_sec);
0115   strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
0116   snprintf(line, kLineBufferSize, " CollectionTimeSummary: %s.%9.9d", zeitHeaven, (int)secondsToHeaven.tv_nsec);
0117   s << line << std::endl;
0118 
0119   timespec secondsToHell = c.collectionTimeSpecial();
0120   horaHell = gmtime(&secondsToHell.tv_sec);
0121   strftime(zeitHell, sizeof(zeitHell), "%Y.%m.%d %H:%M:%S", horaHell);
0122   snprintf(line, kLineBufferSize, " CollectionTimeSpecial: %s.%9.9d", zeitHell, (int)secondsToHell.tv_nsec);
0123   s << line << std::endl;
0124 
0125   timespec secondsToLimbo = c.collectionTimeDetails();
0126   horaLimbo = gmtime(&secondsToLimbo.tv_sec);
0127   strftime(zeitLimbo, sizeof(zeitLimbo), "%Y.%m.%d %H:%M:%S", horaLimbo);
0128   snprintf(line, kLineBufferSize, " CollectionTimeDetails: %s.%9.9d", zeitLimbo, (int)secondsToLimbo.tv_nsec);
0129   s << line << std::endl;
0130 
0131   snprintf(line,
0132            kLineBufferSize,
0133            " LuminositySection: %15d  BunchCrossingErrors:      %15d",
0134            c.luminositySection(),
0135            c.bunchCrossingErrors());
0136   s << line << std::endl;
0137 
0138   snprintf(line,
0139            kLineBufferSize,
0140            " TriggerNumber:     %15d  EventNumber:              %15d",
0141            c.triggerNumber(),
0142            c.eventNumber());
0143   s << line << std::endl;
0144 
0145   snprintf(line,
0146            kLineBufferSize,
0147            " TriggersDistributed:    %10d  TriggersGenerated:        %15d",
0148            c.finalTriggersDistributed(),
0149            c.finalTriggersGenerated());
0150   s << line << std::endl;
0151 
0152   snprintf(line,
0153            kLineBufferSize,
0154            " TriggersInvalidBC: %15d  CalibrationTriggers:      %15d",
0155            c.finalTriggersInvalidBC(),
0156            c.calibrationTriggers());
0157   s << line << std::endl;
0158 
0159   snprintf(line,
0160            kLineBufferSize,
0161            " TestTriggers:      %15d  RandomTriggers:           %15d",
0162            c.totalTestTriggers(),
0163            c.randomTriggers());
0164   s << line << std::endl;
0165 
0166   snprintf(line,
0167            kLineBufferSize,
0168            " DeadTime:          %15d  DeadTimeActiveTimeSlot:   %15ld",
0169            c.numberResets(),
0170            (long int)c.deadTime());
0171   s << line << std::endl;
0172 
0173   snprintf(line,
0174            kLineBufferSize,
0175            " DeadTimeActive:    %15ld  DeadTimeActiveCalibration:%15ld",
0176            (long int)c.deadTimeActive(),
0177            (long int)c.deadTimeActiveCalibration());
0178   s << line << std::endl;
0179 
0180   snprintf(line,
0181            kLineBufferSize,
0182            " LostTriggers:      %15ld  DeadTimeActivePartition:  %15ld",
0183            (long int)c.lostFinalTriggers(),
0184            (long int)c.deadTimeActivePartition());
0185   s << line << std::endl;
0186 
0187   snprintf(line,
0188            kLineBufferSize,
0189            " LostTriggersActive:%15ld  DeadTimeActiveThrottle:   %15ld",
0190            (long int)c.lostFinalTriggersActive(),
0191            (long int)c.deadTimeActiveThrottle());
0192   s << line << std::endl;
0193 
0194   snprintf(line,
0195            kLineBufferSize,
0196            " NumberResets:      %15d  DeadTimeActivePrivate:    %15ld",
0197            c.numberResets(),
0198            (long int)c.deadTimeActivePrivate());
0199   s << line << std::endl;
0200 
0201   s << "Physics Triggers" << std::endl;
0202   std::vector<unsigned int> triggers = c.triggers();
0203   int length = triggers.size() / 4;
0204   for (int i = 0; i < length; i++) {
0205     snprintf(line,
0206              kLineBufferSize,
0207              " %3.3d: %10d    %3.3d: %10d    %3.3d: %10d    %3.3d: %10d",
0208              i,
0209              triggers[i],
0210              (i + length),
0211              triggers[i + length],
0212              (i + (length * 2)),
0213              triggers[i + (length * 2)],
0214              (i + (length * 3)),
0215              triggers[i + (length * 3)]);
0216     s << line << std::endl;
0217   }
0218 
0219   s << "Test Triggers" << std::endl;
0220   std::vector<unsigned int> testTriggers = c.testTriggers();
0221   length = testTriggers.size() / 4;
0222   for (int i = 0; i < length; i++) {
0223     snprintf(line,
0224              kLineBufferSize,
0225              " %3.3d: %10d    %3.3d: %10d    %3.3d: %10d    %3.3d: %10d",
0226              i,
0227              testTriggers[i],
0228              (i + length),
0229              testTriggers[i + length],
0230              (i + (length * 2)),
0231              testTriggers[i + (length * 2)],
0232              (i + (length * 3)),
0233              testTriggers[i + (length * 3)]);
0234     s << line << std::endl;
0235   }
0236   return s;
0237 }