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