CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1GtTextToRaw.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <vector>
20 #include <iostream>
21 #include <iomanip>
22 
23 // user include files
26 
29 
31 
32 // constructor(s)
34  m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
35 
36  LogDebug("L1GtTextToRaw") << "\nText file type: " << m_textFileType << "\n" << std::endl;
37 
38  m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
39 
40  LogDebug("L1GtTextToRaw") << "\nText file name: " << m_textFileName << "\n" << std::endl;
41 
42  // event size
43  m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
44 
45  LogDebug("L1GtTextToRaw") << "\nRaw data size (units of 8 bits): " << m_rawDataSize
46  << "\n If negative value, the size is retrieved from the trailer."
47  << "\n"
48  << std::endl;
49 
50  // FED Id for GT DAQ record
51  // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
52  // default value: assume the DAQ record is the last GT record
54 
55  LogDebug("L1GtTextToRaw") << "\nFED Id for DAQ GT record: " << m_daqGtFedId << " \n" << std::endl;
56 
57  // open test file
58  m_textFile.open(m_textFileName.c_str(), std::ios::in);
59  if (!m_textFile.good()) {
60  throw cms::Exception("NotFound") << "\nError: failed to open text file = " << m_textFileName << "\n" << std::endl;
61  }
62 
63  //
64  produces<FEDRawDataCollection>();
65 }
66 
67 // destructor
69  // empty now
70 }
71 
72 // member functions
73 
74 // beginning of job stuff
76 
77 // clean the text file, if needed
78 void L1GtTextToRaw::cleanTextFile() { LogDebug("L1GtTextToRaw") << "\nCleaning the text file\n" << std::endl; }
79 
80 // get the size of the record
82  LogDebug("L1GtTextToRaw") << "\nComputing raw data size with getRecordSize() method." << std::endl;
83 
84  int rawDataSize = 0;
85 
86  LogDebug("L1GtTextToRaw") << "\nComputed raw data size: " << rawDataSize << std::endl;
87 
88  return rawDataSize;
89 }
90 
91 // method called to produce the data
93  // get the size of the record
94 
95  int rawDataSize = 0;
96 
97  if (m_rawDataSize < 0) {
98  rawDataSize = getDataSize();
99  } else {
100  rawDataSize = m_rawDataSize;
101  }
102 
103  // define new FEDRawDataCollection
104  // it contains ALL FEDs in an event
105  std::unique_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
106 
107  FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
108  // resize, GT raw data record has variable length,
109  // depending on active boards (read in GTFE)
110  rawData.resize(rawDataSize);
111 
112  LogDebug("L1GtTextToRaw") << "\n Size of raw data: " << rawData.size() << "\n" << std::endl;
113 
114  // read the text file
115  // the file must have one 64 bits per line (usually in hex format)
116  // events are separated by empty lines
117 
118  std::string lineString;
119 
120  cms_uint64_t lineInt = 0ULL;
121  int sizeL = sizeof(lineInt);
122 
123  int fedBlockSize = 8; // block size in bits for FedRawData
124  int maskBlock = 0xff; // fedBlockSize and maskBlock must be consistent
125 
126  int iLine = 0;
127 
128  while (std::getline(m_textFile, lineString)) {
129  if (lineString.empty()) {
130  break;
131  }
132 
133  // convert string to int
134  std::istringstream iss(lineString);
135 
136  iss >> std::hex >> lineInt;
137 
138  LogTrace("L1GtTextToRaw") << std::dec << std::setw(4) << std::setfill('0') << iLine << ": " << std::hex
139  << std::setw(sizeL * 2) << lineInt << std::dec << std::setfill(' ') << std::endl;
140 
141  // copy data
142  for (int j = 0; j < sizeL; j++) {
143  char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
144  rawData.data()[iLine * sizeL + j] = blockContent;
145  }
146 
147  ++iLine;
148  }
149 
150  // put the raw data in the event
151  iEvent.put(std::move(fedRawColl));
152 }
153 
154 //
156  // empty now
157 }
158 
159 // static class members
virtual int getDataSize()
get the size of the record
T getUntrackedParameter(std::string const &, T const &) const
int m_daqGtFedId
FED ID for the system.
Definition: L1GtTextToRaw.h:71
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::string m_textFileName
file name for the text file
Definition: L1GtTextToRaw.h:65
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
#define LogTrace(id)
int iEvent
Definition: GenABIO.cc:224
void resize(size_t newsize)
Definition: FEDRawData.cc:28
std::string m_textFileType
file type for the text file
Definition: L1GtTextToRaw.h:62
void beginJob() override
beginning of job stuff
def move
Definition: eostools.py:511
L1GtTextToRaw(const edm::ParameterSet &)
constructor(s)
int m_rawDataSize
raw event size (including header and trailer) in units of 8 bits
Definition: L1GtTextToRaw.h:68
void produce(edm::Event &, const edm::EventSetup &) override
loop over events
virtual void cleanTextFile()
clean the text file, if needed
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
unsigned long long cms_uint64_t
Definition: typedefs.h:17
std::ifstream m_textFile
the file itself
Definition: L1GtTextToRaw.h:74
void endJob() override
end of job stuff
~L1GtTextToRaw() override
destructor
#define LogDebug(id)