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 
FEDNumbering.h
sistrip::preconstructCheckFEDSpyBuffer
FEDBufferStatusCode preconstructCheckFEDSpyBuffer(const FEDRawData &fedBuffer)
Definition: SiStripFEDSpyBuffer.h:108
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
ESHandle.h
edm::EDGetTokenT< FEDRawDataCollection >
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogInfo
Definition: MessageLogger.h:254
EDAnalyzer.h
ConstantsForHardwareSystems.h
Constants and enumerated types for FED/FEC systems.
FEDRawData.h
edm::Handle
Definition: AssociativeIterator.h:50
FEDRawData
Definition: FEDRawData.h:19
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
sistrip::SpyIdentifyRunsModule
Definition: SiStripSpyIdentifyRuns.cc:37
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
sistrip::SpyIdentifyRunsModule::srcTag_
edm::InputTag srcTag_
Definition: SiStripSpyIdentifyRuns.cc:55
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
sistrip::SpyIdentifyRunsModule::writeRunInFile
void writeRunInFile(const unsigned int aRunNumber)
Definition: SiStripSpyIdentifyRuns.cc:126
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
sistrip::SpyIdentifyRunsModule::fileName_
std::string fileName_
Definition: SiStripSpyIdentifyRuns.cc:51
sistrip::SpyIdentifyRunsModule::endJob
void endJob() override
Definition: SiStripSpyIdentifyRuns.cc:134
SiStripSpyIdentifyRuns
sistrip::SpyIdentifyRunsModule SiStripSpyIdentifyRuns
Definition: SiStripSpyIdentifyRuns.cc:145
EDGetToken.h
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
sistrip::SpyIdentifyRunsModule::beginJob
void beginJob() override
Definition: SiStripSpyIdentifyRuns.cc:78
FEDNumbering::MAXSiStripFEDID
Definition: FEDNumbering.h:30
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
sistrip::SpyIdentifyRunsModule::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SiStripSpyIdentifyRuns.cc:90
sistrip::FEDBufferStatusCode::SUCCESS
FEDRawDataCollection.h
edm::EventSetup
Definition: EventSetup.h:57
sistrip::SpyIdentifyRunsModule::outFile_
std::ofstream outFile_
Definition: SiStripSpyIdentifyRuns.cc:52
InputTag.h
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
sistrip::FEDBufferStatusCode::EXPECT_SPY
EventSetup.h
Exception.h
sistrip::FEDSpyBuffer
Definition: SiStripFEDSpyBuffer.h:33
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
sistrip::SpyIdentifyRunsModule::SpyIdentifyRunsModule
SpyIdentifyRunsModule(const edm::ParameterSet &)
Definition: SiStripSpyIdentifyRuns.cc:69
sistrip::SpyIdentifyRunsModule::srcToken_
edm::EDGetTokenT< FEDRawDataCollection > srcToken_
Definition: SiStripSpyIdentifyRuns.cc:56
ParameterSet.h
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
sistrip::SpyIdentifyRunsModule::~SpyIdentifyRunsModule
~SpyIdentifyRunsModule() override
Definition: SiStripSpyIdentifyRuns.cc:76
edm::Event
Definition: Event.h:73
sistrip::SpyIdentifyRunsModule::prevRun_
uint32_t prevRun_
Definition: SiStripSpyIdentifyRuns.cc:57
SiStripFEDSpyBuffer.h
edm::InputTag
Definition: InputTag.h:15
FEDNumbering::MINSiStripFEDID
Definition: FEDNumbering.h:29