CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
27 
28 
29 
30 
31 
32 
35 
37 
38 
39 // constructor(s)
41 {
42 
43  m_textFileType = pSet.getUntrackedParameter<std::string>("TextFileType", "VmeSpyDump");
44 
45  LogDebug("L1GtTextToRaw")
46  << "\nText file type: " << m_textFileType << "\n"
47  << std::endl;
48 
49  m_textFileName = pSet.getUntrackedParameter<std::string>("TextFileName", "gtfe.dmp");
50 
51  LogDebug("L1GtTextToRaw")
52  << "\nText file name: " << m_textFileName << "\n"
53  << std::endl;
54 
55  // event size
56  m_rawDataSize = pSet.getUntrackedParameter<int>("RawDataSize");
57 
58  LogDebug("L1GtTextToRaw")
59  << "\nRaw data size (units of 8 bits): " << m_rawDataSize
60  << "\n If negative value, the size is retrieved from the trailer." << "\n"
61  << std::endl;
62 
63  // FED Id for GT DAQ record
64  // default value defined in DataFormats/FEDRawData/src/FEDNumbering.cc
65  // default value: assume the DAQ record is the last GT record
67  "DaqGtFedId", FEDNumbering::MAXTriggerGTPFEDID);
68 
69  LogDebug("L1GtTextToRaw")
70  << "\nFED Id for DAQ GT record: "
71  << m_daqGtFedId << " \n"
72  << std::endl;
73 
74  // open test file
75  m_textFile.open(m_textFileName.c_str(), std::ios::in);
76  if( !m_textFile.good() ) {
77  throw cms::Exception("NotFound")
78  << "\nError: failed to open text file = " << m_textFileName << "\n"
79  << std::endl;
80  }
81 
82  //
83  produces<FEDRawDataCollection>();
84 
85 }
86 
87 // destructor
89 {
90 
91  // empty now
92 
93 }
94 
95 // member functions
96 
97 // beginning of job stuff
99 {
100 
101  cleanTextFile();
102 
103 }
104 
105 // clean the text file, if needed
107 {
108 
109  LogDebug("L1GtTextToRaw")
110  << "\nCleaning the text file\n"
111  << std::endl;
112 
113 
114 
115 }
116 
117 // get the size of the record
119 {
120 
121  LogDebug("L1GtTextToRaw")
122  << "\nComputing raw data size with getRecordSize() method."
123  << std::endl;
124 
125  int rawDataSize = 0;
126 
127  LogDebug("L1GtTextToRaw")
128  << "\nComputed raw data size: " << rawDataSize
129  << std::endl;
130 
131 
132  return rawDataSize;
133 
134 }
135 
136 
137 // method called to produce the data
139 {
140 
141  // get the size of the record
142 
143  int rawDataSize = 0;
144 
145  if (m_rawDataSize < 0) {
146  rawDataSize = getDataSize();
147  } else {
148  rawDataSize = m_rawDataSize;
149 
150  }
151 
152  // define new FEDRawDataCollection
153  // it contains ALL FEDs in an event
154  std::auto_ptr<FEDRawDataCollection> fedRawColl(new FEDRawDataCollection);
155 
156  FEDRawData& rawData = fedRawColl->FEDData(m_daqGtFedId);
157  // resize, GT raw data record has variable length,
158  // depending on active boards (read in GTFE)
159  rawData.resize(rawDataSize);
160 
161 
162  LogDebug("L1GtTextToRaw")
163  << "\n Size of raw data: " << rawData.size() << "\n"
164  << std::endl;
165 
166 
167  // read the text file
168  // the file must have one 64 bits per line (usually in hex format)
169  // events are separated by empty lines
170 
171  std::string lineString;
172 
173  cms_uint64_t lineInt = 0ULL;
174  int sizeL = sizeof(lineInt);
175 
176  int fedBlockSize = 8; // block size in bits for FedRawData
177  int maskBlock = 0xff; // fedBlockSize and maskBlock must be consistent
178 
179  int iLine = 0;
180 
181  while (std::getline(m_textFile, lineString)) {
182 
183  if (lineString.empty()) {
184  break;
185  }
186 
187  // convert string to int
188  std::istringstream iss(lineString);
189 
190  iss >> std::hex >> lineInt;
191 
192  LogTrace("L1GtTextToRaw")
193  << std::dec << std::setw(4) << std::setfill('0') << iLine << ": "
194  << std::hex << std::setw(sizeL*2) << lineInt
195  << std::dec << std::setfill(' ')
196  << std::endl;
197 
198  // copy data
199  for (int j = 0; j < sizeL; j++) {
200  char blockContent = (lineInt >> (fedBlockSize * j)) & maskBlock;
201  rawData.data()[iLine*sizeL + j] = blockContent;
202  }
203 
204 
205  ++iLine;
206  }
207 
208  // put the raw data in the event
209  iEvent.put(fedRawColl);
210 }
211 
212 
213 //
215 {
216 
217  // empty now
218 }
219 
220 
221 // static class members
#define LogDebug(id)
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:76
std::string m_textFileName
file name for the text file
Definition: L1GtTextToRaw.h:70
virtual void endJob()
end of job stuff
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int iEvent
Definition: GenABIO.cc:230
void resize(size_t newsize)
Definition: FEDRawData.cc:32
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
std::string m_textFileType
file type for the text file
Definition: L1GtTextToRaw.h:67
int j
Definition: DBlmapReader.cc:9
L1GtTextToRaw(const edm::ParameterSet &)
constructor(s)
int m_rawDataSize
raw event size (including header and trailer) in units of 8 bits
Definition: L1GtTextToRaw.h:73
#define LogTrace(id)
virtual void beginJob()
beginning of job stuff
virtual void cleanTextFile()
clean the text file, if needed
virtual void produce(edm::Event &, const edm::EventSetup &)
loop over events
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
unsigned long long cms_uint64_t
Definition: typedefs.h:17
std::ifstream m_textFile
the file itself
Definition: L1GtTextToRaw.h:79
virtual ~L1GtTextToRaw()
destructor