CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/EventFilter/L1GlobalTriggerRawToDigi/src/L1GtTextToRaw.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GtTextToRaw.h"
00019 
00020 // system include files
00021 #include <vector>
00022 #include <iostream>
00023 #include <iomanip>
00024 
00025 // user include files
00026 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00027 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00037 
00038 #include "FWCore/Utilities/interface/typedefs.h"
00039 
00040 
00041 // constructor(s)
00042 L1GtTextToRaw::L1GtTextToRaw(const edm::ParameterSet& pSet)
00043 {
00044 
00045     m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
00046 
00047     LogDebug("L1GtTextToRaw")
00048     << "\nText file type: " << m_textFileType << "\n"
00049     << std::endl;
00050 
00051     m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
00052 
00053     LogDebug("L1GtTextToRaw")
00054     << "\nText file name: " << m_textFileName << "\n"
00055     << std::endl;
00056 
00057     // event size
00058     m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
00059 
00060     LogDebug("L1GtTextToRaw")
00061     << "\nRaw data size (units of 8 bits): " << m_rawDataSize
00062     << "\n  If negative value, the size is retrieved from the trailer." << "\n"
00063     << std::endl;
00064 
00065     // FED Id for GT DAQ record
00066     // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
00067     // default value: assume the DAQ record is the last GT record 
00068     m_daqGtFedId = pSet.getUntrackedParameter<int>(
00069                        "DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID);
00070 
00071     LogDebug("L1GtTextToRaw")
00072     << "\nFED Id for DAQ GT record: "
00073     << m_daqGtFedId << " \n"
00074     << std::endl;
00075 
00076     // open test file
00077     m_textFile.open(m_textFileName.c_str(), std::ios::in);
00078     if( !m_textFile.good() ) {
00079         throw cms::Exception("NotFound")
00080         << "\nError: failed to open text file = " << m_textFileName << "\n"
00081         << std::endl;
00082     }
00083 
00084     //
00085     produces<FEDRawDataCollection>();
00086 
00087 }
00088 
00089 // destructor
00090 L1GtTextToRaw::~L1GtTextToRaw()
00091 {
00092 
00093     // empty now
00094 
00095 }
00096 
00097 // member functions
00098 
00099 // beginning of job stuff
00100 void L1GtTextToRaw::beginJob()
00101 {
00102 
00103     cleanTextFile();
00104 
00105 }
00106 
00107 // clean the text file, if needed
00108 void L1GtTextToRaw::cleanTextFile()
00109 {
00110 
00111     LogDebug("L1GtTextToRaw")
00112     << "\nCleaning the text file\n"
00113     << std::endl;
00114 
00115 
00116 
00117 }
00118 
00119 // get the size of the record
00120 int L1GtTextToRaw::getDataSize()
00121 {
00122 
00123     LogDebug("L1GtTextToRaw")
00124     << "\nComputing raw data size with getRecordSize() method."
00125     << std::endl;
00126 
00127     int rawDataSize = 0;
00128 
00129     LogDebug("L1GtTextToRaw")
00130     << "\nComputed raw data size: " << rawDataSize
00131     << std::endl;
00132 
00133 
00134     return rawDataSize;
00135 
00136 }
00137 
00138 
00139 // method called to produce the data
00140 void L1GtTextToRaw::produce(edm::Event& iEvent, const edm::EventSetup& evSetup)
00141 {
00142 
00143     // get the size of the record
00144 
00145     int rawDataSize = 0;
00146 
00147     if (m_rawDataSize < 0) {
00148         rawDataSize = getDataSize();
00149     } else {
00150         rawDataSize = m_rawDataSize;
00151 
00152     }
00153 
00154     // define new FEDRawDataCollection
00155     // it contains ALL FEDs in an event
00156     std::auto_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
00157 
00158     FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
00159     // resize, GT raw data record has variable length,
00160     // depending on active boards (read in GTFE)
00161     rawData.resize(rawDataSize);
00162 
00163 
00164     LogDebug("L1GtTextToRaw")
00165     << "\n Size of raw data: " << rawData.size() << "\n"
00166     << std::endl;
00167 
00168 
00169     // read the text file
00170     // the file must have one 64 bits per line (usually in hex format)
00171     // events are separated by empty lines
00172     
00173     std::string lineString;
00174 
00175     cms_uint64_t lineInt = 0ULL;
00176     int sizeL = sizeof(lineInt);
00177 
00178     int fedBlockSize = 8; // block size in bits for FedRawData
00179     int maskBlock = 0xff; // fedBlockSize and maskBlock must be consistent
00180 
00181     int iLine = 0;
00182 
00183     while (std::getline(m_textFile, lineString)) {
00184 
00185         if (lineString.empty()) {
00186             break;
00187         }
00188 
00189         // convert string to int
00190         std::istringstream iss(lineString);
00191 
00192         iss >> std::hex >> lineInt;
00193 
00194         LogTrace("L1GtTextToRaw")
00195         << std::dec << std::setw(4) << std::setfill('0') << iLine << ": " 
00196         << std::hex << std::setw(sizeL*2) << lineInt 
00197         << std::dec << std::setfill(' ')
00198         << std::endl;
00199 
00200         // copy data
00201         for (int j = 0; j < sizeL; j++) {
00202             char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
00203             rawData.data()[iLine*sizeL + j] = blockContent;
00204         }
00205 
00206 
00207         ++iLine;
00208     }
00209 
00210     // put the raw data in the event
00211     iEvent.put(fedRawColl);
00212 }
00213 
00214 
00215 //
00216 void L1GtTextToRaw::endJob()
00217 {
00218 
00219     // empty now
00220 }
00221 
00222 
00223 // static class members