HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCalTBTextSource.h
Go to the documentation of this file.
1 #include "FWCore/Framework/interface/Event.h"
2 #include "FWCore/ParameterSet/interface/ParameterSet.h"
3 #include "FWCore/Sources/interface/ProducerSourceFromFiles.h"
4 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
5 
6 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
7 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
8 #include <iostream>
9 #include <stdio.h>
10 #include <fstream>
11 
12 /**
13  * \class HGCalTBTextSource HGCal/RawToDigi/plugins/HGCalTBTextSource.h
14  *
15  * \brief convert data from txt file to FEDRawData
16  *
17  * \todo replace c-like scanf with c++ versions
18  * \todo change run and fed IDs (now are hardcoded)
19  */
20 class HGCalTBTextSource : public edm::ProducerSourceFromFiles
21 {
22 
23 public:
24  explicit HGCalTBTextSource(const edm::ParameterSet & pset, edm::InputSourceDescription const& desc) : edm::ProducerSourceFromFiles(pset, desc, true),
25  m_file(0),
26  m_run(pset.getUntrackedParameter<int>("run", 101)) /// \todo check and read from file?
27  {
28 
29  m_sourceId = pset.getUntrackedParameter<int>("fed", 1000); /// \todo check and read from file?
30  produces<FEDRawDataCollection>();
31  }
32 
34  {
35  if (m_file != 0) fclose(m_file);
36  m_file = 0;
37  }
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  virtual bool setRunAndEventInfo(edm::EventID& id, edm::TimeValue_t& time, edm::EventAuxiliary::ExperimentType&)
43  {
44 
45  if (!(fileNames().size())) return false; // need a file...
46  if (m_file == 0) {
47  std::string name = fileNames()[0].c_str(); /// \todo FIX in order to take several files
48  if (name.find("file:") == 0) name = name.substr(5);
49  m_file = fopen(name.c_str(), "r");
50  if (m_file == 0) {
51  throw cms::Exception("FileNotFound") << "Unable to open file " << name;
52  }
53  m_event = 0;
54  }
55  if (feof(m_file)) return false;
56  if (!readLines()) return false;
57 
58  m_event++; /// \todo get eventID from file?
59  id = edm::EventID(m_run, 1, m_event);
60  // time is a hack
61  edm::TimeValue_t present_time = presentTime(); ///\todo take time from file? how to define the time?
62  unsigned long time_between_events = timeBetweenEvents();
63 
64  time = present_time + time_between_events;
65  return true;
66  }
67  virtual void produce(edm::Event & e);
68  bool readLines();
69 
70  std::vector<std::string> m_lines;
71  FILE* m_file;
72  unsigned int m_time_tmp, m_run_tmp;
73  int m_event, m_run;
74  int m_sourceId;
75 };
virtual ~HGCalTBTextSource()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
convert data from txt file to FEDRawData
HGCalTBTextSource(const edm::ParameterSet &pset, edm::InputSourceDescription const &desc)