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/BeamSpotOnline.cc   (W.Badgett)
0003  */
0004 
0005 #include "DataFormats/Scalers/interface/BeamSpotOnline.h"
0006 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0007 #include <cstdio>
0008 #include <ostream>
0009 
0010 BeamSpotOnline::BeamSpotOnline()
0011     : trigType_(0),
0012       eventID_(0),
0013       sourceID_(0),
0014       bunchNumber_(0),
0015       version_(0),
0016       collectionTime_(0, 0),
0017       x_((float)0.0),
0018       y_((float)0.0),
0019       z_((float)0.0),
0020       dxdz_((float)0.0),
0021       dydz_((float)0.0),
0022       err_x_((float)0.0),
0023       err_y_((float)0.0),
0024       err_z_((float)0.0),
0025       err_dxdz_((float)0.0),
0026       err_dydz_((float)0.0),
0027       width_x_((float)0.0),
0028       width_y_((float)0.0),
0029       sigma_z_((float)0.0),
0030       err_width_x_((float)0.0),
0031       err_width_y_((float)0.0),
0032       err_sigma_z_((float)0.0) {}
0033 
0034 BeamSpotOnline::BeamSpotOnline(const unsigned char* rawData) {
0035   BeamSpotOnline();
0036 
0037   struct ScalersEventRecordRaw_v4 const* raw = reinterpret_cast<struct ScalersEventRecordRaw_v4 const*>(rawData);
0038   trigType_ = (raw->header >> 56) & 0xFULL;
0039   eventID_ = (raw->header >> 32) & 0x00FFFFFFULL;
0040   sourceID_ = (raw->header >> 8) & 0x00000FFFULL;
0041   bunchNumber_ = (raw->header >> 20) & 0xFFFULL;
0042 
0043   version_ = raw->version;
0044   if (version_ >= 4) {
0045     collectionTime_.set_tv_sec(static_cast<long>(raw->beamSpotOnline.collectionTime_sec));
0046     collectionTime_.set_tv_nsec(raw->beamSpotOnline.collectionTime_nsec);
0047     x_ = raw->beamSpotOnline.x;
0048     y_ = raw->beamSpotOnline.y;
0049     z_ = raw->beamSpotOnline.z;
0050     dxdz_ = raw->beamSpotOnline.dxdz;
0051     dydz_ = raw->beamSpotOnline.dydz;
0052     err_x_ = raw->beamSpotOnline.err_x;
0053     err_y_ = raw->beamSpotOnline.err_y;
0054     err_z_ = raw->beamSpotOnline.err_z;
0055     err_dxdz_ = raw->beamSpotOnline.err_dxdz;
0056     err_dydz_ = raw->beamSpotOnline.err_dydz;
0057     width_x_ = raw->beamSpotOnline.width_x;
0058     width_y_ = raw->beamSpotOnline.width_y;
0059     sigma_z_ = raw->beamSpotOnline.sigma_z;
0060     err_width_x_ = raw->beamSpotOnline.err_width_x;
0061     err_width_y_ = raw->beamSpotOnline.err_width_y;
0062     err_sigma_z_ = raw->beamSpotOnline.err_sigma_z;
0063   }
0064 }
0065 
0066 BeamSpotOnline::~BeamSpotOnline() {}
0067 
0068 /// Pretty-print operator for BeamSpotOnline
0069 std::ostream& operator<<(std::ostream& s, const BeamSpotOnline& c) {
0070   char zeit[128];
0071   constexpr size_t kLineBufferSize = 157;
0072   char line[kLineBufferSize];
0073   struct tm* hora;
0074 
0075   s << "BeamSpotOnline    Version: " << c.version() << "   SourceID: " << c.sourceID() << std::endl;
0076 
0077   timespec ts = c.collectionTime();
0078   hora = gmtime(&ts.tv_sec);
0079   strftime(zeit, sizeof(zeit), "%Y.%m.%d %H:%M:%S", hora);
0080   snprintf(line, kLineBufferSize, " CollectionTime: %s.%9.9d", zeit, (int)ts.tv_nsec);
0081   s << line << std::endl;
0082 
0083   snprintf(line,
0084            kLineBufferSize,
0085            " TrigType: %d   EventID: %d    BunchNumber: %d",
0086            c.trigType(),
0087            c.eventID(),
0088            c.bunchNumber());
0089   s << line << std::endl;
0090 
0091   snprintf(
0092       line, kLineBufferSize, "    x: %e +/- %e   width: %e +/- %e", c.x(), c.err_x(), c.width_x(), c.err_width_x());
0093   s << line << std::endl;
0094 
0095   snprintf(
0096       line, kLineBufferSize, "    y: %e +/- %e   width: %e +/- %e", c.y(), c.err_y(), c.width_y(), c.err_width_y());
0097   s << line << std::endl;
0098 
0099   snprintf(
0100       line, kLineBufferSize, "    z: %e +/- %e   sigma: %e +/- %e", c.z(), c.err_z(), c.sigma_z(), c.err_sigma_z());
0101   s << line << std::endl;
0102 
0103   snprintf(
0104       line, kLineBufferSize, " dxdy: %e +/- %e    dydz: %e +/- %e", c.dxdz(), c.err_dxdz(), c.dydz(), c.err_dydz());
0105   s << line << std::endl;
0106   return s;
0107 }