CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCFileDumper.cc
Go to the documentation of this file.
1 #include <iomanip>
2 
3 #include "CSCFileDumper.h"
4 
5 //Framework stuff
9 
10 //FEDRawData
14 
16 
18 
19 #include <cstdio>
20 #include <iostream>
21 #include <sstream>
22 
24  i_token = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("source"));
25  // source_ = pset.getUntrackedParameter<std::string>("source","rawDataCollector");
26  output = pset.getUntrackedParameter<std::string>("output");
27  events = pset.getUntrackedParameter<std::string>("events", "");
28 
29  cscFEDids.clear();
30  /*
31  for (unsigned int id=FEDNumbering::MINCSCFEDID;
32  id<=FEDNumbering::MAXCSCFEDID; ++id) // loop over DCCs
33  {
34  cscFEDids.push_back(id);
35  }
36  */
37  for (unsigned int id = FEDNumbering::MINCSCDDUFEDID; id <= FEDNumbering::MAXCSCDDUFEDID; ++id) // loop over DDUs
38  {
39  cscFEDids.push_back(id);
40  }
41  /*
42  for (unsigned int id=FEDNumbering::MINCSCTFFEDID; id<=FEDNumbering::MAXCSCTFFEDID; id++)
43  {
44  cscFEDids.push_back(id);
45  }
46  */
47 
48  if (events.length()) {
49  for (size_t pos1 = 0, pos2 = events.find(',');; pos1 = pos2 + 1, pos2 = events.find(',', pos2 + 1)) {
50  if (pos2 != std::string::npos) {
51  long event = 0;
52  if (sscanf(events.substr(pos1, pos2 - pos1).c_str(), "%ld", &event) == 1 && event >= 0)
53  eventsToDump.insert((unsigned long)event);
54  else
55  edm::LogError("CSCFileDumper") << " cannot parse events (" << events
56  << ") parameter: " << events.substr(pos1, pos2 - pos1);
57  } else {
58  long event = 0;
59  if (sscanf(events.substr(pos1, events.length() - pos1).c_str(), "%ld", &event) == 1 && event >= 0)
60  eventsToDump.insert((unsigned long)event);
61  else
62  edm::LogError("CSCFileDumper") << " cannot parse events (" << events
63  << ") parameter: " << events.substr(pos1, events.length() - pos1);
64  break;
65  }
66  }
67  std::ostringstream tmp;
68  for (std::set<unsigned long>::const_iterator evt = eventsToDump.begin(); evt != eventsToDump.end(); evt++)
69  tmp << *evt << " ";
70  edm::LogInfo("CSCFileDumper") << " Following events will be dumped: " << tmp.str();
71  } else
72  edm::LogInfo("CSCFileDumper") << " All events will be dumped";
73 }
74 
76  std::map<int, FILE *>::const_iterator stream = dump_files.begin();
77  while (stream != dump_files.end()) {
78  fclose(stream->second);
79  stream++;
80  }
81 }
82 
84  // Get a handle to the FED data collection
86  e.getByToken(i_token, rawdata);
87 
88  // Get a handle to the FED data collection
89 
90  for (unsigned int i = 0; i < cscFEDids.size(); i++) //for each of our DCCs
91  {
92  unsigned int id = cscFEDids[i];
93  std::map<int, FILE *>::const_iterator stream = dump_files.find(id);
95  const FEDRawData &fedData = rawdata->FEDData(id);
96  unsigned short int length = fedData.size();
97 
98  if (length && (eventsToDump.empty() || (eventsToDump.find((unsigned long)e.id().event()) != eventsToDump.end()))) {
99  if (stream == dump_files.end()) {
100  std::ostringstream name;
101  name << output << "_FED" << id << ".raw" << std::ends;
102  FILE *file;
103  if ((file = fopen(name.str().c_str(), "wt")) == nullptr) {
104  edm::LogError("CSCFileDumper") << "Cannot open the file: " << name.str();
105  continue;
106  } else
107  dump_files[id] = file;
108  stream = dump_files.find(id);
109  }
110 
111  // Event buffer
112  size_t size = length / 2;
113  const unsigned short *buf = (unsigned short *)fedData.data();
114  fwrite(buf, 2, size, stream->second);
115  }
116  }
117 }
CSCFileDumper(edm::ParameterSet const &pset)
edm::EDGetTokenT< FEDRawDataCollection > i_token
Token for consumes interface &amp; access to data.
Definition: CSCFileDumper.h:35
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
std::string events
Definition: CSCFileDumper.h:20
const edm::EventSetup & c
uint16_t *__restrict__ id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Log< level::Error, false > LogError
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
std::string output
Definition: CSCFileDumper.h:20
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
std::set< unsigned long > eventsToDump
Definition: CSCFileDumper.h:17
std::vector< unsigned int > cscFEDids
Definition: CSCFileDumper.h:28
std::map< int, FILE * > dump_files
Definition: CSCFileDumper.h:16
Log< level::Info, false > LogInfo
~CSCFileDumper(void) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EventID id() const
Definition: EventBase.h:59
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
tmp
align.sh
Definition: createJobs.py:716
tuple size
Write out results.