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/LumiScalers.cc   (W.Badgett)
0004  */
0005 
0006 #include "DataFormats/Scalers/interface/LumiScalers.h"
0007 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0008 #include <cstdio>
0009 #include <ostream>
0010 
0011 LumiScalers::LumiScalers()
0012     : trigType_(0),
0013       eventID_(0),
0014       sourceID_(0),
0015       bunchNumber_(0),
0016       version_(0),
0017       normalization_(0.0),
0018       deadTimeNormalization_(0.0),
0019       lumiFill_(0.0),
0020       lumiRun_(0.0),
0021       liveLumiFill_(0.0),
0022       liveLumiRun_(0.0),
0023       instantLumi_(0.0),
0024       instantLumiErr_(0.0),
0025       instantLumiQlty_(0),
0026       lumiETFill_(0.0),
0027       lumiETRun_(0.0),
0028       liveLumiETFill_(0.0),
0029       liveLumiETRun_(0.0),
0030       instantETLumi_(0.0),
0031       instantETLumiErr_(0.0),
0032       instantETLumiQlty_(0),
0033       lumiOccFill_(nOcc),
0034       lumiOccRun_(nOcc),
0035       liveLumiOccFill_(nOcc),
0036       liveLumiOccRun_(nOcc),
0037       instantOccLumi_(nOcc),
0038       instantOccLumiErr_(nOcc),
0039       instantOccLumiQlty_(nOcc),
0040       lumiNoise_(nOcc),
0041       sectionNumber_(0),
0042       startOrbit_(0),
0043       numOrbits_(0),
0044       pileup_(0.0),
0045       pileupRMS_(0.0),
0046       bunchLumi_(0.0),
0047       spare_(0.0) {}
0048 
0049 LumiScalers::LumiScalers(const unsigned char* rawData) {
0050   LumiScalers();
0051 
0052   struct ScalersEventRecordRaw_v1 const* raw = reinterpret_cast<struct ScalersEventRecordRaw_v1 const*>(rawData);
0053   trigType_ = (raw->header >> 56) & 0xFULL;
0054   eventID_ = (raw->header >> 32) & 0x00FFFFFFULL;
0055   sourceID_ = (raw->header >> 8) & 0x00000FFFULL;
0056   bunchNumber_ = (raw->header >> 20) & 0xFFFULL;
0057   version_ = raw->version;
0058 
0059   struct LumiScalersRaw_v1 const* lumi = nullptr;
0060 
0061   if (version_ >= 1) {
0062     if (version_ <= 2) {
0063       lumi = &(raw->lumi);
0064     } else {
0065       struct ScalersEventRecordRaw_v3 const* raw3 = reinterpret_cast<struct ScalersEventRecordRaw_v3 const*>(rawData);
0066       lumi = &(raw3->lumi);
0067     }
0068     collectionTime_.set_tv_sec(static_cast<long>(lumi->collectionTime_sec));
0069     collectionTime_.set_tv_nsec(lumi->collectionTime_nsec);
0070     deadTimeNormalization_ = lumi->DeadtimeNormalization;
0071     normalization_ = lumi->Normalization;
0072     lumiFill_ = lumi->LumiFill;
0073     lumiRun_ = lumi->LumiRun;
0074     liveLumiFill_ = lumi->LiveLumiFill;
0075     liveLumiRun_ = lumi->LiveLumiRun;
0076     instantLumi_ = lumi->InstantLumi;
0077     instantLumiErr_ = lumi->InstantLumiErr;
0078     instantLumiQlty_ = lumi->InstantLumiQlty;
0079     lumiETFill_ = lumi->LumiETFill;
0080     lumiETRun_ = lumi->LumiETRun;
0081     liveLumiETFill_ = lumi->LiveLumiETFill;
0082     liveLumiETRun_ = lumi->LiveLumiETRun;
0083     instantETLumi_ = lumi->InstantETLumi;
0084     instantETLumiErr_ = lumi->InstantETLumiErr;
0085     instantETLumiQlty_ = lumi->InstantETLumiQlty;
0086     for (int i = 0; i < ScalersRaw::N_LUMI_OCC_v1; i++) {
0087       lumiOccFill_.push_back(lumi->LumiOccFill[i]);
0088       lumiOccRun_.push_back(lumi->LumiOccRun[i]);
0089       liveLumiOccFill_.push_back(lumi->LiveLumiOccFill[i]);
0090       liveLumiOccRun_.push_back(lumi->LiveLumiOccRun[i]);
0091       instantOccLumi_.push_back(lumi->InstantOccLumi[i]);
0092       instantOccLumiErr_.push_back(lumi->InstantOccLumiErr[i]);
0093       instantOccLumiQlty_.push_back(lumi->InstantOccLumiQlty[i]);
0094       lumiNoise_.push_back(lumi->lumiNoise[i]);
0095     }
0096     sectionNumber_ = lumi->sectionNumber;
0097     startOrbit_ = lumi->startOrbit;
0098     numOrbits_ = lumi->numOrbits;
0099 
0100     if (version_ >= 7) {
0101       struct ScalersEventRecordRaw_v6 const* raw6 = (struct ScalersEventRecordRaw_v6 const*)rawData;
0102       float const* fspare = reinterpret_cast<float const*>(raw6->spare);
0103       pileup_ = fspare[ScalersRaw::I_SPARE_PILEUP_v7];
0104       pileupRMS_ = fspare[ScalersRaw::I_SPARE_PILEUPRMS_v7];
0105       if (version_ >= 8) {
0106         bunchLumi_ = fspare[ScalersRaw::I_SPARE_BUNCHLUMI_v8];
0107         spare_ = fspare[ScalersRaw::I_SPARE_SPARE_v8];
0108       } else {
0109         bunchLumi_ = (float)0.0;
0110         spare_ = (float)0.0;
0111       }
0112     } else {
0113       pileup_ = (float)0.0;
0114       pileupRMS_ = (float)0.0;
0115       bunchLumi_ = (float)0.0;
0116       spare_ = (float)0.0;
0117     }
0118   }
0119 }
0120 
0121 LumiScalers::~LumiScalers() {}
0122 
0123 /// Pretty-print operator for LumiScalers
0124 std::ostream& operator<<(std::ostream& s, const LumiScalers& c) {
0125   char zeit[128];
0126   constexpr size_t kLineBufferSize = 157;
0127   char line[kLineBufferSize];
0128   struct tm* hora;
0129 
0130   s << "LumiScalers    Version: " << c.version() << "   SourceID: " << c.sourceID() << std::endl;
0131 
0132   timespec ts = c.collectionTime();
0133   hora = gmtime(&ts.tv_sec);
0134   strftime(zeit, sizeof(zeit), "%Y.%m.%d %H:%M:%S", hora);
0135   snprintf(line, kLineBufferSize, " CollectionTime: %s.%9.9d", zeit, (int)ts.tv_nsec);
0136   s << line << std::endl;
0137 
0138   snprintf(line,
0139            kLineBufferSize,
0140            " TrigType: %d   EventID: %d    BunchNumber: %d",
0141            c.trigType(),
0142            c.eventID(),
0143            c.bunchNumber());
0144   s << line << std::endl;
0145 
0146   snprintf(line,
0147            kLineBufferSize,
0148            " SectionNumber: %10d   StartOrbit: %10d  NumOrbits: %10d",
0149            c.sectionNumber(),
0150            c.startOrbit(),
0151            c.numOrbits());
0152   s << line << std::endl;
0153 
0154   snprintf(line,
0155            kLineBufferSize,
0156            " Normalization: %e  DeadTimeNormalization: %e",
0157            c.normalization(),
0158            c.deadTimeNormalization());
0159   s << line << std::endl;
0160 
0161   // Integrated Luminosity
0162 
0163   snprintf(line, kLineBufferSize, " LumiFill:            %e   LumiRun:            %e", c.lumiFill(), c.lumiRun());
0164   s << line << std::endl;
0165   snprintf(
0166       line, kLineBufferSize, " LiveLumiFill:        %e   LiveLumiRun:        %e", c.liveLumiFill(), c.liveLumiRun());
0167   s << line << std::endl;
0168 
0169   snprintf(line, kLineBufferSize, " LumiETFill:          %e   LumiETRun:          %e", c.lumiFill(), c.lumiRun());
0170   s << line << std::endl;
0171 
0172   snprintf(
0173       line, kLineBufferSize, " LiveLumiETFill:      %e   LiveLumETiRun:      %e", c.liveLumiETFill(), c.liveLumiETRun());
0174   s << line << std::endl;
0175 
0176   int length = c.instantOccLumi().size();
0177   for (int i = 0; i < length; i++) {
0178     snprintf(line,
0179              kLineBufferSize,
0180              " LumiOccFill[%d]:      %e   LumiOccRun[%d]:      %e",
0181              i,
0182              c.lumiOccFill()[i],
0183              i,
0184              c.lumiOccRun()[i]);
0185     s << line << std::endl;
0186 
0187     snprintf(line,
0188              kLineBufferSize,
0189              " LiveLumiOccFill[%d]:  %e   LiveLumiOccRun[%d]:  %e",
0190              i,
0191              c.liveLumiOccFill()[i],
0192              i,
0193              c.liveLumiOccRun()[i]);
0194     s << line << std::endl;
0195   }
0196 
0197   // Instantaneous Luminosity
0198 
0199   snprintf(line,
0200            kLineBufferSize,
0201            " InstantLumi:       %e  Err: %e  Qlty: %d",
0202            c.instantLumi(),
0203            c.instantLumiErr(),
0204            c.instantLumiQlty());
0205   s << line << std::endl;
0206 
0207   snprintf(line,
0208            kLineBufferSize,
0209            " InstantETLumi:     %e  Err: %e  Qlty: %d",
0210            c.instantETLumi(),
0211            c.instantETLumiErr(),
0212            c.instantETLumiQlty());
0213   s << line << std::endl;
0214 
0215   for (int i = 0; i < length; i++) {
0216     snprintf(line,
0217              kLineBufferSize,
0218              " InstantOccLumi[%d]: %e  Err: %e  Qlty: %d",
0219              i,
0220              c.instantOccLumi()[i],
0221              c.instantOccLumiErr()[i],
0222              c.instantOccLumiQlty()[i]);
0223     s << line << std::endl;
0224     snprintf(line, kLineBufferSize, "      LumiNoise[%d]: %e", i, c.lumiNoise()[i]);
0225     s << line << std::endl;
0226   }
0227 
0228   snprintf(line, kLineBufferSize, " Pileup: %f       PileupRMS: %f", c.pileup(), c.pileupRMS());
0229   s << line << std::endl;
0230 
0231   snprintf(line, kLineBufferSize, " BunchLumi: %f    Spare: %f", c.bunchLumi(), c.spare());
0232   s << line << std::endl;
0233 
0234   return s;
0235 }