Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:08

0001 /**
0002  * \class L1GtTextToRaw
0003  * 
0004  * 
0005  * Description: generate raw data from dumped text file.  
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *   
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna 
0011  * 
0012  *
0013  */
0014 
0015 // this class header
0016 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GtTextToRaw.h"
0017 
0018 // system include files
0019 #include <vector>
0020 #include <iostream>
0021 #include <iomanip>
0022 
0023 // user include files
0024 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0025 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0026 
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0029 
0030 #include "FWCore/Utilities/interface/typedefs.h"
0031 
0032 // constructor(s)
0033 L1GtTextToRaw::L1GtTextToRaw(const edm::ParameterSet& pSet) {
0034   m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
0035 
0036   LogDebug("L1GtTextToRaw") << "\nText file type: " << m_textFileType << "\n" << std::endl;
0037 
0038   m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
0039 
0040   LogDebug("L1GtTextToRaw") << "\nText file name: " << m_textFileName << "\n" << std::endl;
0041 
0042   // event size
0043   m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
0044 
0045   LogDebug("L1GtTextToRaw") << "\nRaw data size (units of 8 bits): " << m_rawDataSize
0046                             << "\n  If negative value, the size is retrieved from the trailer."
0047                             << "\n"
0048                             << std::endl;
0049 
0050   // FED Id for GT DAQ record
0051   // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
0052   // default value: assume the DAQ record is the last GT record
0053   m_daqGtFedId = pSet.getUntrackedParameter<int>("DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID);
0054 
0055   LogDebug("L1GtTextToRaw") << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n" << std::endl;
0056 
0057   // open test file
0058   m_textFile.open(m_textFileName.c_str(), std::ios::in);
0059   if (!m_textFile.good()) {
0060     throw cms::Exception("NotFound") << "\nError: failed to open text file = " << m_textFileName << "\n" << std::endl;
0061   }
0062 
0063   //
0064   produces<FEDRawDataCollection>();
0065 }
0066 
0067 // destructor
0068 L1GtTextToRaw::~L1GtTextToRaw() {
0069   // empty now
0070 }
0071 
0072 // member functions
0073 
0074 // beginning of job stuff
0075 void L1GtTextToRaw::beginJob() { cleanTextFile(); }
0076 
0077 // clean the text file, if needed
0078 void L1GtTextToRaw::cleanTextFile() { LogDebug("L1GtTextToRaw") << "\nCleaning the text file\n" << std::endl; }
0079 
0080 // get the size of the record
0081 int L1GtTextToRaw::getDataSize() {
0082   LogDebug("L1GtTextToRaw") << "\nComputing raw data size with getRecordSize() method." << std::endl;
0083 
0084   int rawDataSize = 0;
0085 
0086   LogDebug("L1GtTextToRaw") << "\nComputed raw data size: " << rawDataSize << std::endl;
0087 
0088   return rawDataSize;
0089 }
0090 
0091 // method called to produce the data
0092 void L1GtTextToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
0093   // get the size of the record
0094 
0095   int rawDataSize = 0;
0096 
0097   if (m_rawDataSize < 0) {
0098     rawDataSize = getDataSize();
0099   } else {
0100     rawDataSize = m_rawDataSize;
0101   }
0102 
0103   // define new FEDRawDataCollection
0104   // it contains ALL FEDs in an event
0105   std::unique_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
0106 
0107   FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
0108   // resize, GT raw data record has variable length,
0109   // depending on active boards (read in GTFE)
0110   rawData.resize(rawDataSize);
0111 
0112   LogDebug("L1GtTextToRaw") << "\n Size of raw data: " << rawData.size() << "\n" << std::endl;
0113 
0114   // read the text file
0115   // the file must have one 64 bits per line (usually in hex format)
0116   // events are separated by empty lines
0117 
0118   std::string lineString;
0119 
0120   cms_uint64_t lineInt = 0ULL;
0121   int sizeL = sizeof(lineInt);
0122 
0123   int fedBlockSize = 8;  // block size in bits for FedRawData
0124   int maskBlock = 0xff;  // fedBlockSize and maskBlock must be consistent
0125 
0126   int iLine = 0;
0127 
0128   while (std::getline(m_textFile, lineString)) {
0129     if (lineString.empty()) {
0130       break;
0131     }
0132 
0133     // convert string to int
0134     std::istringstream iss(lineString);
0135 
0136     iss >> std::hex >> lineInt;
0137 
0138     LogTrace("L1GtTextToRaw") << std::dec << std::setw(4) << std::setfill('0') << iLine << ": " << std::hex
0139                               << std::setw(sizeL * 2) << lineInt << std::dec << std::setfill(' ') << std::endl;
0140 
0141     // copy data
0142     for (int j = 0; j < sizeL; j++) {
0143       char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
0144       rawData.data()[iLine * sizeL + j] = blockContent;
0145     }
0146 
0147     ++iLine;
0148   }
0149 
0150   // put the raw data in the event
0151   iEvent.put(std::move(fedRawColl));
0152 }
0153 
0154 //
0155 void L1GtTextToRaw::endJob() {
0156   // empty now
0157 }
0158 
0159 // static class members