Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *   File: DataFormats/Scalers/src/DcsStatus.cc   (W.Badgett)
0003  */
0004 
0005 #include "DataFormats/Scalers/interface/DcsStatus.h"
0006 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0007 #include <cstdio>
0008 #include <ostream>
0009 
0010 const int DcsStatus::partitionList[DcsStatus::nPartitions] = {EBp, EBm,  EEp,  EEm,  HBHEa, HBHEb, HBHEc,  HF,  HO,
0011                                                               RPC, DT0,  DTp,  DTm,  CSCp,  CSCm,  CASTOR, ZDC, TIBTID,
0012                                                               TOB, TECp, TECm, BPIX, FPIX,  ESp,   ESm};
0013 
0014 const char* const DcsStatus::partitionName[DcsStatus::nPartitions] = {
0015     "EBp",  "EBm",  "EEp",    "EEm", "HBHEa",  "HBHEb", "HBHEc", "HF",   "HO",   "RPC",  "DT0", "DTp", "DTm",
0016     "CSCp", "CSCm", "CASTOR", "ZDC", "TIBTID", "TOB",   "TECp",  "TECm", "BPIX", "FPIX", "ESp", "ESm"};
0017 
0018 DcsStatus::DcsStatus()
0019     : trigType_(0),
0020       eventID_(0),
0021       sourceID_(0),
0022       bunchNumber_(0),
0023       version_(0),
0024       collectionTime_(0, 0),
0025       ready_(0),
0026       magnetCurrent_((float)0.0),
0027       magnetTemperature_((float)0.0) {}
0028 
0029 DcsStatus::DcsStatus(const unsigned char* rawData) {
0030   DcsStatus();
0031 
0032   struct ScalersEventRecordRaw_v4 const* raw = reinterpret_cast<struct ScalersEventRecordRaw_v4 const*>(rawData);
0033   trigType_ = (raw->header >> 56) & 0xFULL;
0034   eventID_ = (raw->header >> 32) & 0x00FFFFFFULL;
0035   sourceID_ = (raw->header >> 8) & 0x00000FFFULL;
0036   bunchNumber_ = (raw->header >> 20) & 0xFFFULL;
0037 
0038   version_ = raw->version;
0039   if (version_ >= 4) {
0040     collectionTime_.set_tv_sec(static_cast<long>(raw->dcsStatus.collectionTime_sec));
0041     collectionTime_.set_tv_nsec(raw->dcsStatus.collectionTime_nsec);
0042     ready_ = raw->dcsStatus.ready;
0043     magnetCurrent_ = raw->dcsStatus.magnetCurrent;
0044     magnetTemperature_ = raw->dcsStatus.magnetTemperature;
0045   }
0046 }
0047 
0048 DcsStatus::~DcsStatus() {}
0049 
0050 /// Pretty-print operator for DcsStatus
0051 std::ostream& operator<<(std::ostream& s, const DcsStatus& c) {
0052   constexpr size_t kZeitBufferSize = 128;
0053   char zeit[kZeitBufferSize];
0054   constexpr size_t kLineBufferSize = 157;
0055   char line[kLineBufferSize];
0056   struct tm* hora;
0057 
0058   s << "DcsStatus    Version: " << c.version() << "   SourceID: " << c.sourceID() << std::endl;
0059 
0060   timespec ts = c.collectionTime();
0061   hora = gmtime(&ts.tv_sec);
0062   strftime(zeit, kZeitBufferSize, "%Y.%m.%d %H:%M:%S", hora);
0063   snprintf(line, kLineBufferSize, " CollectionTime: %s.%9.9d", zeit, (int)ts.tv_nsec);
0064   s << line << std::endl;
0065 
0066   snprintf(line,
0067            kLineBufferSize,
0068            " TrigType: %d   EventID: %d    BunchNumber: %d",
0069            c.trigType(),
0070            c.eventID(),
0071            c.bunchNumber());
0072   s << line << std::endl;
0073 
0074   snprintf(
0075       line, kLineBufferSize, " MagnetCurrent: %e    MagnetTemperature: %e", c.magnetCurrent(), c.magnetTemperature());
0076   s << line << std::endl;
0077 
0078   snprintf(line, kLineBufferSize, " Ready: %d  0x%8.8X", c.ready(), c.ready());
0079   s << line << std::endl;
0080 
0081   for (int i = 0; i < DcsStatus::nPartitions; i++) {
0082     if (c.ready(DcsStatus::partitionList[i])) {
0083       snprintf(line, kLineBufferSize, "  %2d %6s: READY", i, DcsStatus::partitionName[i]);
0084     } else {
0085       snprintf(line, kLineBufferSize, "  %2d %6s: NOT READY", i, DcsStatus::partitionName[i]);
0086     }
0087     s << line << std::endl;
0088   }
0089   return s;
0090 }