DQM
SiStripMonitorHardware
src
SiStripSpyExtractRunModule.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
13
#include "
FWCore/Utilities/interface/EDGetToken.h
"
14
#include "
FWCore/Framework/interface/Frameworkfwd.h
"
15
#include "
FWCore/Framework/interface/EDAnalyzer.h
"
16
#include "
FWCore/Framework/interface/Event.h
"
17
#include "
FWCore/Framework/interface/EventSetup.h
"
18
#include "
FWCore/Framework/interface/ESHandle.h
"
19
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
20
#include "
FWCore/Utilities/interface/InputTag.h
"
21
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
22
#include "
FWCore/ServiceRegistry/interface/Service.h
"
23
#include "
FWCore/Utilities/interface/Exception.h
"
24
25
#include "
DataFormats/FEDRawData/interface/FEDNumbering.h
"
26
#include "
DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h
"
27
28
#include "
DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h
"
29
30
//
31
// Class declaration
32
//
33
namespace
sistrip
{
34
35
class
SpyExtractRunModule
:
public
edm::EDAnalyzer
{
36
public
:
37
explicit
SpyExtractRunModule
(
const
edm::ParameterSet
&);
38
~SpyExtractRunModule
()
override
;
39
40
private
:
41
void
beginJob
()
override
;
42
void
analyze
(
const
edm::Event
&,
const
edm::EventSetup
&)
override
;
43
void
endJob
()
override
;
44
45
//check when the current run changes
46
const
bool
updateRun
(
const
uint32_t aRun);
47
48
//name of the output file containing the run number
49
//get it from the input file
50
std::string
fileName_
;
51
52
//tag of spydata run number collection
53
edm::InputTag
runTag_
;
54
edm::EDGetTokenT<uint32_t>
runToken_
;
55
56
//cache of the current and previous run number
57
uint32_t
currentRun_
;
58
uint32_t
previousRun_
;
59
60
//error counter for number of times the run number changes
61
uint32_t
errCounter_
;
62
};
63
}
// namespace sistrip
64
65
using
edm::LogError
;
66
using
edm::LogInfo
;
67
using
edm::LogWarning
;
68
//
69
// Constructors and destructor
70
//
71
namespace
sistrip
{
72
73
SpyExtractRunModule::SpyExtractRunModule
(
const
edm::ParameterSet
& iConfig)
74
: fileName_(iConfig.getParameter<
std
::
string
>(
"OutputTextFile"
)),
75
runTag_(iConfig.getParameter<
edm
::
InputTag
>(
"RunNumberTag"
)),
76
currentRun_(0),
77
previousRun_(0),
78
errCounter_(0) {
79
runToken_
= consumes<uint32_t>(
runTag_
);
80
}
81
82
SpyExtractRunModule::~SpyExtractRunModule
() {}
83
84
void
SpyExtractRunModule::beginJob
() {
85
currentRun_
= 0;
86
previousRun_
= 0;
87
errCounter_
= 0;
88
}
89
90
void
SpyExtractRunModule::analyze
(
const
edm::Event
& aEvt,
const
edm::EventSetup
& aSetup) {
91
static
bool
lFirstEvent =
true
;
92
edm::Handle<uint32_t>
lRun;
93
aEvt.
getByToken
(
runToken_
, lRun);
94
95
const
bool
isUpdated =
updateRun
(*lRun);
96
97
if
(isUpdated && !lFirstEvent) {
98
edm::LogError
(
"SpyExtractRunModule"
)
99
<<
" -- Run number changed for event : "
<< aEvt.
id
().
event
() <<
" (id().run() = "
<< aEvt.
id
().
run
()
100
<<
") from "
<<
previousRun_
<<
" to "
<<
currentRun_
<< std::endl;
101
}
102
103
lFirstEvent =
false
;
104
}
105
106
void
SpyExtractRunModule::endJob
() {
107
//save global run number in text file in local directory
108
//output loginfo with number of errors
109
//or throw exception ?
110
111
if
(
errCounter_
== 1) {
112
edm::LogInfo
(
"SiStripSpyExtractRun"
)
113
<<
" -- Writting run number "
<<
currentRun_
<<
" into file "
<<
fileName_
<< std::endl;
114
std::ofstream lOutFile;
115
lOutFile.open(
fileName_
.c_str(),
std::ios::out
);
116
if
(!lOutFile.is_open()) {
117
edm::LogError
(
"SiStripSpyExtractRun"
)
118
<<
" -- Cannot open file : "
<<
fileName_
<<
" for writting run number "
<<
currentRun_
<< std::endl;
119
}
else
{
120
lOutFile <<
currentRun_
<< std::endl;
121
lOutFile.close();
122
}
123
124
}
else
{
125
edm::LogError
(
"SiStripSpyExtractRun"
)
126
<<
" -- Number of times the run number changed in this job = "
<<
errCounter_
127
<<
", currentRun = "
<<
currentRun_
<<
", previousRun = "
<<
previousRun_
<< std::endl;
128
}
129
}
130
131
const
bool
SpyExtractRunModule::updateRun
(
const
uint32_t aRun) {
132
if
(aRun !=
currentRun_
) {
133
previousRun_
=
currentRun_
;
134
currentRun_
= aRun;
135
errCounter_
++;
136
return
true
;
137
}
138
return
false
;
139
}
140
141
}
// namespace sistrip
142
143
#include "
FWCore/Framework/interface/MakerMacros.h
"
144
typedef
sistrip::SpyExtractRunModule
SiStripSpyExtractRunModule
;
145
DEFINE_FWK_MODULE
(
SiStripSpyExtractRunModule
);
FEDNumbering.h
sistrip::SpyExtractRunModule::previousRun_
uint32_t previousRun_
Definition:
SiStripSpyExtractRunModule.cc:58
MessageLogger.h
ESHandle.h
sistrip::SpyExtractRunModule::endJob
void endJob() override
Definition:
SiStripSpyExtractRunModule.cc:106
edm::EDGetTokenT< uint32_t >
edm
HLT enums.
Definition:
AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition:
HLT_FULL_cff.py:89285
sistrip::SpyExtractRunModule::runTag_
edm::InputTag runTag_
Definition:
SiStripSpyExtractRunModule.cc:53
sistrip::SpyExtractRunModule::SpyExtractRunModule
SpyExtractRunModule(const edm::ParameterSet &)
Definition:
SiStripSpyExtractRunModule.cc:73
EDAnalyzer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition:
MessageLogger.h:125
ConstantsForHardwareSystems.h
Constants and enumerated types for FED/FEC systems.
edm::Handle
Definition:
AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition:
MessageLogger.h:122
edm::EDAnalyzer
Definition:
EDAnalyzer.h:28
MakerMacros.h
sistrip::SpyExtractRunModule::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition:
SiStripSpyExtractRunModule.cc:90
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
Service.h
sistrip::SpyExtractRunModule
Definition:
SiStripSpyExtractRunModule.cc:35
sistrip::SpyExtractRunModule::runToken_
edm::EDGetTokenT< uint32_t > runToken_
Definition:
SiStripSpyExtractRunModule.cc:54
SiStripSpyExtractRunModule
sistrip::SpyExtractRunModule SiStripSpyExtractRunModule
Definition:
SiStripSpyExtractRunModule.cc:144
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:535
EDGetToken.h
edm::EventID::run
RunNumber_t run() const
Definition:
EventID.h:38
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition:
ParameterSet.h:47
Event.h
sistrip::SpyExtractRunModule::currentRun_
uint32_t currentRun_
Definition:
SiStripSpyExtractRunModule.cc:57
edm::EventID::event
EventNumber_t event() const
Definition:
EventID.h:40
sistrip::SpyExtractRunModule::errCounter_
uint32_t errCounter_
Definition:
SiStripSpyExtractRunModule.cc:61
edm::EventSetup
Definition:
EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition:
MessageLogger.h:123
InputTag.h
std
Definition:
JetResolutionObject.h:76
sistrip::SpyExtractRunModule::fileName_
std::string fileName_
Definition:
SiStripSpyExtractRunModule.cc:50
Frameworkfwd.h
edm::EventBase::id
edm::EventID id() const
Definition:
EventBase.h:59
sistrip::SpyExtractRunModule::updateRun
const bool updateRun(const uint32_t aRun)
Definition:
SiStripSpyExtractRunModule.cc:131
sistrip::SpyExtractRunModule::beginJob
void beginJob() override
Definition:
SiStripSpyExtractRunModule.cc:84
sistrip::SpyExtractRunModule::~SpyExtractRunModule
~SpyExtractRunModule() override
Definition:
SiStripSpyExtractRunModule.cc:82
EventSetup.h
Exception.h
MillePedeFileConverter_cfg.out
out
Definition:
MillePedeFileConverter_cfg.py:31
ParameterSet.h
sistrip
sistrip classes
Definition:
SiStripQualityHelpers.h:14
edm::Event
Definition:
Event.h:73
SiStripFEDSpyBuffer.h
edm::InputTag
Definition:
InputTag.h:15
Generated for CMSSW Reference Manual by
1.8.16