Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/LTCDigi/interface/LTCDigi.h"
0002 
0003 LTCDigi::LTCDigi(const unsigned char *data) {
0004   // six 64 bit words
0005   cms_uint64_t const *ld = reinterpret_cast<cms_uint64_t const *>(data);
0006 
0007   trigType_ = (ld[0] >> 56) & 0xFULL;  // 4 bits
0008 
0009   eventID_ = (ld[0] >> 32) & 0x00FFFFFFULL;    // 24 bits
0010   runNumber_ = (ld[2] >> 32) & 0xFFFFFFFFULL;  // 32 bits
0011   eventNumber_ = (ld[2]) & 0xFFFFFFFFULL;      // 32 bits
0012 
0013   sourceID_ = (ld[0] >> 8) & 0x00000FFFULL;  // 12 bits
0014   // this should always be 815?
0015   //assert(sourceID_ == 815);
0016 
0017   bunchNumber_ = (ld[0] >> 20) & 0xFFFULL;       // 12 bits
0018   orbitNumber_ = (ld[1] >> 32) & 0xFFFFFFFFULL;  // 32 bits
0019 
0020   versionNumber_ = (ld[1] >> 24) & 0xFFULL;  // 8 bits
0021 
0022   daqPartition_ = (ld[1]) & 0xFULL;  // 4 bits
0023 
0024   trigInputStat_ = (ld[3]) & 0xFFFFFFFFULL;  // 32 bits
0025 
0026   trigInhibitNumber_ = (ld[3] >> 32) & 0xFFFFFFFFULL;  // 32 bits
0027 
0028   bstGpsTime_ = ld[4];  // 64 bits
0029 }
0030 //static
0031 cms_uint32_t LTCDigi::GetEventNumberFromBuffer(const unsigned char *data) {
0032   // six 64 bit words
0033   cms_uint64_t const *ld = reinterpret_cast<cms_uint64_t const *>(data);
0034   cms_uint32_t eventNumber = (ld[2]) & 0xFFFFFFFFULL;  // 32 bits
0035   return eventNumber;
0036 }
0037 //static
0038 cms_uint32_t LTCDigi::GetRunNumberFromBuffer(const unsigned char *data) {
0039   // six 64 bit words
0040   cms_uint64_t const *ld = reinterpret_cast<cms_uint64_t const *>(data);
0041   cms_uint32_t runNumber = (ld[2] >> 32) & 0xFFFFFFFFULL;  // 32 bits
0042   return runNumber;
0043 }
0044 
0045 std::ostream &operator<<(std::ostream &stream, const LTCDigi &myDigi) {
0046   stream << "----------------------------------------" << std::endl;
0047   stream << "Dumping LTC digi. " << std::endl;
0048   stream << "Source ID: " << myDigi.sourceID() << std::endl;
0049   stream << "Run, event: " << myDigi.runNumber() << ", " << myDigi.eventNumber() << std::endl;
0050   stream << "N_Inhibit:" << myDigi.triggerInhibitNumber() << std::endl;
0051   stream << LTCDigi::utcTime(myDigi.bstGpsTime()) << std::endl;
0052   stream << LTCDigi::locTime(myDigi.bstGpsTime()) << std::endl;
0053   ///
0054   stream << "Partition: " << myDigi.daqPartition() << std::endl;
0055   stream << "Bunch #:   " << myDigi.bunchNumber() << std::endl;
0056   stream << "Orbit #:   " << myDigi.orbitNumber() << std::endl;
0057 
0058   // Trigger information
0059   stream << "Trigger Bits(0-5):";
0060   for (int i = 0; i < 6; ++i) {
0061     if (myDigi.HasTriggered(i))
0062       stream << "1";
0063     else
0064       stream << "0";
0065     stream << " ";
0066   }
0067   stream << std::endl;
0068 
0069   //
0070   stream << "Ram trigger: " << myDigi.ramTrigger() << std::endl;
0071   stream << "VME trigger: " << myDigi.vmeTrigger() << std::endl;
0072 
0073   stream << "++++++++++++++++++++++++++++++++++++++++" << std::endl;
0074 
0075   stream << "Raw Data" << std::endl;
0076   stream << "Trigger Input status: 0x" << std::hex << myDigi.triggerInputStatus() << std::endl;
0077   stream << "GPS time:             0x" << std::hex << myDigi.bstGpsTime() << std::endl;
0078 
0079   stream << "----------------------------------------" << std::endl;
0080   stream << std::dec << std::endl;
0081 
0082   return stream;
0083 }
0084 
0085 std::string LTCDigi::utcTime(cms_uint64_t t)  //const
0086 {
0087   // note that gmtime isn't reentrant and we don't own the data
0088   time_t tsmall = t / 1000000;
0089   tm *utct = gmtime(&tsmall);
0090   std::string tstr("UTC: ");
0091   tstr += asctime(utct);
0092   tstr.replace(tstr.find('\n'), tstr.size(), "");
0093   return tstr;
0094 }
0095 
0096 std::string LTCDigi::locTime(cms_uint64_t t)  //const
0097 {
0098   time_t tsmall = t / 1000000;
0099   std::string a("LOC: ");
0100   a += std::string(ctime(&tsmall));
0101   a.replace(a.find('\n'), a.size(), "");
0102   return a;
0103 }