CMS 3D CMS Logo

SiStripSpyIdentifyRuns.cc
Go to the documentation of this file.
1 // Original Author: Anne-Marie Magnan
2 // Created: 2010/02/25
3 //
4 
5 #include <sstream>
6 #include <fstream>
7 #include <iostream>
8 #include <memory>
9 #include <list>
10 #include <algorithm>
11 #include <cassert>
12 
24 
29 
31 
32 //
33 // Class declaration
34 //
35 namespace sistrip {
36 
38  public:
40  ~SpyIdentifyRunsModule() override;
41 
42  private:
43  void beginJob() override;
44  void analyze(const edm::Event&, const edm::EventSetup&) override;
45  void endJob() override;
46 
47  void writeRunInFile(const unsigned int aRunNumber);
48 
49  //name of the output file containing the run numbers
50  //of spy runs
52  std::ofstream outFile_;
53 
54  //tag of spydata source collection
57  uint32_t prevRun_;
58  };
59 } // namespace sistrip
60 
61 using edm::LogError;
62 using edm::LogInfo;
63 using edm::LogWarning;
64 //
65 // Constructors and destructor
66 //
67 namespace sistrip {
68 
70  : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
71  srcTag_(iConfig.getParameter<edm::InputTag>("InputProductLabel")),
72  prevRun_(0) {
73  srcToken_ = consumes<FEDRawDataCollection>(srcTag_);
74  }
75 
77 
79  outFile_.open(fileName_.c_str(), std::ios::out);
80  if (!outFile_.is_open()) {
81  edm::LogError("SiStripSpyIdentifyRuns")
82  << " -- Cannot open file : " << fileName_ << " for writting." << std::endl;
83  edm::LogInfo("SiStripSpyIdentifyRuns") << " *** SPY RUNS *** " << std::endl;
84 
85  } else {
86  outFile_ << " *** SPY RUNS *** " << std::endl;
87  }
88  }
89 
90  void SpyIdentifyRunsModule::analyze(const edm::Event& aEvt, const edm::EventSetup& aSetup) {
91  //static bool lFirstEvent = true;
92  //if (!lFirstEvent) return;
93  uint32_t lRunNum = aEvt.id().run();
94  if (lRunNum == prevRun_)
95  return;
96 
98  aEvt.getByToken(srcToken_, lHandle);
99  const FEDRawDataCollection& buffers = *lHandle;
100 
101  for (unsigned int iFed(FEDNumbering::MINSiStripFEDID); iFed <= FEDNumbering::MAXSiStripFEDID; iFed++) {
102  //retrieve FED raw data for given FED
103  const FEDRawData& input = buffers.FEDData(static_cast<int>(iFed));
104  //check on FEDRawData pointer and size
105  if (!input.data() || !input.size())
106  continue;
107  //construct FEDBuffer
108  const auto st_buffer = preconstructCheckFEDSpyBuffer(input);
109  if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
110  edm::LogWarning("SiStripSpyIdentifyRuns")
111  << "Exception caught when creating FEDSpyBuffer object for FED " << iFed << ": "
112  << "An exception of category 'FEDBuffer' occurred.\n"
113  << st_buffer;
115  break;
116  }
118  edm::LogWarning("SiStripSpyIdentifyRuns") << " -- this is a spy file, run " << lRunNum << std::endl;
119  writeRunInFile(lRunNum);
120  break;
121  }
122  //lFirstEvent = false;
123  prevRun_ = lRunNum;
124  }
125 
126  void SpyIdentifyRunsModule::writeRunInFile(const unsigned int aRunNumber) {
127  if (!outFile_.is_open()) {
128  edm::LogInfo("SiStripSpyIdentifyRuns") << aRunNumber << std::endl;
129  } else {
130  outFile_ << aRunNumber << std::endl;
131  }
132  }
133 
135  //save global run number in text file in local directory
136  //output loginfo with number of errors
137  //or throw exception ?
138  if (outFile_.is_open())
139  outFile_.close();
140  }
141 
142 } // namespace sistrip
143 
edm::EDGetTokenT< FEDRawDataCollection > srcToken_
FEDBufferStatusCode preconstructCheckFEDSpyBuffer(const FEDRawData &fedBuffer)
void writeRunInFile(const unsigned int aRunNumber)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
Log< level::Error, false > LogError
sistrip classes
void analyze(const edm::Event &, const edm::EventSetup &) override
static std::string const input
Definition: EdmProvDump.cc:50
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
Constants and enumerated types for FED/FEC systems.
sistrip::SpyIdentifyRunsModule SiStripSpyIdentifyRuns
HLT enums.
SpyIdentifyRunsModule(const edm::ParameterSet &)
Log< level::Warning, false > LogWarning