CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
evf::EvFOutputModule Class Reference

#include <EvFOutputModule.h>

Inheritance diagram for evf::EvFOutputModule:
edm::one::OutputModule< T > edm::one::OutputModuleBase edm::EDConsumerBase

Public Member Functions

 EvFOutputModule (edm::ParameterSet const &ps)
 
 ~EvFOutputModule () override
 
- Public Member Functions inherited from edm::one::OutputModule< T >
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
 OutputModule (edm::ParameterSet const &iPSet)
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::OutputModuleBase
BranchIDLists const * branchIDLists ()
 
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch () const
 
SelectedProductsForBranchType const & keptProducts () const
 
int maxEvents () const
 
const ModuleDescriptionmoduleDescription () const
 
OutputModuleBaseoperator= (OutputModuleBase const &)=delete
 
 OutputModuleBase (ParameterSet const &pset)
 
 OutputModuleBase (OutputModuleBase const &)=delete
 
std::string const & processName () const
 
int remainingEvents () const
 
bool selected (BranchDescription const &desc) const
 
void selectProducts (ProductRegistry const &preg, ThinnedAssociationsHelper const &)
 
SharedResourcesAcquirersharedResourcesAcquirer ()
 
SubProcessParentageHelper const * subProcessParentageHelper () const
 
ThinnedAssociationsHelper const * thinnedAssociationsHelper () const
 
bool wantAllEvents () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~OutputModuleBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::OutputModuleBase
static const std::string & baseType ()
 
static void fillDescription (ParameterSetDescription &desc)
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 

Private Member Functions

void beginRun (edm::RunForOutput const &run) override
 
void endRun (edm::RunForOutput const &) override
 
Trig getTriggerResults (edm::EDGetTokenT< edm::TriggerResults > const &token, edm::EventForOutput const &e) const
 
std::shared_ptr< EvFOutputEventWriterglobalBeginLuminosityBlock (edm::LuminosityBlockForOutput const &iLB) const override
 
void globalEndLuminosityBlock (edm::LuminosityBlockForOutput const &iLB) override
 
void write (edm::EventForOutput const &e) override
 
void writeLuminosityBlock (edm::LuminosityBlockForOutput const &) override
 
void writeRun (edm::RunForOutput const &) override
 

Private Attributes

evf::FastMonitoringServicefms_
 
std::unique_ptr< evf::EvFOutputJSONWriterjsonWriter_
 
edm::ParameterSet const & ps_
 
std::string streamLabel_
 
edm::EDGetTokenT< edm::TriggerResultstrToken_
 

Additional Inherited Members

- Public Types inherited from edm::one::OutputModuleBase
typedef OutputModuleBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::one::OutputModuleBase
void configure (OutputModuleDescription const &desc)
 
ModuleDescription const & description () const
 
void doBeginJob ()
 
bool doBeginLuminosityBlock (LuminosityBlockPrincipal const &lbp, EventSetupImpl const &c, ModuleCallingContext const *)
 
bool doBeginRun (RunPrincipal const &rp, EventSetupImpl const &c, ModuleCallingContext const *)
 
void doEndJob ()
 
bool doEndLuminosityBlock (LuminosityBlockPrincipal const &lbp, EventSetupImpl const &c, ModuleCallingContext const *)
 
bool doEndRun (RunPrincipal const &rp, EventSetupImpl const &c, ModuleCallingContext const *)
 
bool doEvent (EventPrincipal const &ep, EventSetupImpl const &c, ActivityRegistry *, ModuleCallingContext const *)
 
void doPreallocate (PreallocationConfiguration const &)
 
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID ()
 
virtual void preallocLumis (unsigned int)
 
ParameterSetID selectorConfig () const
 
void setEventSelectionInfo (std::map< std::string, std::vector< std::pair< std::string, int >>> const &outputModulePathPositions, bool anyProductProduced)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 72 of file EvFOutputModule.h.

Constructor & Destructor Documentation

evf::EvFOutputModule::EvFOutputModule ( edm::ParameterSet const &  ps)
explicit

Definition at line 107 of file EvFOutputModule.cc.

References Exception, fms_, streamLabel_, and AlCaHLTBitMon_QueryRunRegistry::string.

110  ps_(ps),
111  streamLabel_(ps.getParameter<std::string>("@module_label")),
112  trToken_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults"))) {
113  //replace hltOutoputA with stream if the HLT menu uses this convention
114  std::string testPrefix = "hltOutput";
115  if (streamLabel_.find(testPrefix) == 0)
116  streamLabel_ = std::string("stream") + streamLabel_.substr(testPrefix.size());
117 
118  if (streamLabel_.find("_") != std::string::npos) {
119  throw cms::Exception("EvFOutputModule") << "Underscore character is reserved can not be used for stream names in "
120  "FFF, but was detected in stream name -: "
121  << streamLabel_;
122  }
123 
124  std::string streamLabelLow = streamLabel_;
125  boost::algorithm::to_lower(streamLabelLow);
126  auto streampos = streamLabelLow.rfind("stream");
127  if (streampos != 0 && streampos != std::string::npos)
128  throw cms::Exception("EvFOutputModule")
129  << "stream (case-insensitive) sequence was found in stream suffix. This is reserved and can not be used for "
130  "names in FFF based HLT, but was detected in stream name";
131 
133  }
edm::ParameterSet const & ps_
std::string streamLabel_
edm::one::OutputModule< edm::one::WatchRuns, edm::LuminosityBlockCache< evf::EvFOutputEventWriter > > EvFOutputModuleType
edm::EDGetTokenT< edm::TriggerResults > trToken_
evf::FastMonitoringService * fms_
evf::EvFOutputModule::~EvFOutputModule ( )
override

Definition at line 135 of file EvFOutputModule.cc.

135 {}

Member Function Documentation

void evf::EvFOutputModule::beginRun ( edm::RunForOutput const &  run)
overrideprivate

Definition at line 144 of file EvFOutputModule.cc.

References cms::Adler32(), StreamerOutputFile::adler32(), edm::one::OutputModuleBase::branchIDLists(), StreamerOutputFile::close(), edm::one::OutputModuleBase::description(), Exception, edm::InEvent, jsonWriter_, edm::one::OutputModuleBase::keptProducts(), LogDebug, edm::ModuleDescription::mainParameterSetID(), edm::one::OutputModuleBase::moduleDescription(), edm::ModuleDescription::moduleLabel(), SimL1EmulatorRepack_CalouGT_cff::processName, ps_, TrackRefitter_38T_cff::src, hgcalPlots::stat, streamLabel_, AlCaHLTBitMon_QueryRunRegistry::string, edm::one::OutputModuleBase::thinnedAssociationsHelper(), and StreamerOutputFile::write().

144  {
145  //create run Cache holding JSON file writer and variables
146  jsonWriter_ = std::make_unique<EvFOutputJSONWriter>(ps_, &keptProducts()[edm::InEvent], streamLabel_);
147 
148  //output INI file (non-const). This doesn't require globalBeginRun to be finished
149  const std::string openIniFileName = edm::Service<evf::EvFDaqDirector>()->getOpenInitFilePath(streamLabel_);
150  edm::LogInfo("EvFOutputModule") << "beginRun init stream -: " << openIniFileName;
151 
152  StreamerOutputFile stream_writer_preamble(openIniFileName);
153  uint32 preamble_adler32 = 1;
154  edm::BranchIDLists const* bidlPtr = branchIDLists();
155 
156  std::unique_ptr<InitMsgBuilder> init_message =
157  jsonWriter_->streamerCommon_.serializeRegistry(*jsonWriter_->streamerCommon_.getSerializerBuffer(),
158  *bidlPtr,
163 
164  //Let us turn it into a View
165  InitMsgView view(init_message->startAddress());
166 
167  //output header
168  stream_writer_preamble.write(view);
169  preamble_adler32 = stream_writer_preamble.adler32();
170  stream_writer_preamble.close();
171 
172  struct stat istat;
173  stat(openIniFileName.c_str(), &istat);
174  //read back file to check integrity of what was written
175  off_t readInput = 0;
176  uint32_t adlera = 1, adlerb = 0;
177  FILE* src = fopen(openIniFileName.c_str(), "r");
178 
179  //allocate buffer to write INI file
180  unsigned char* outBuf = new unsigned char[1024 * 1024];
181  while (readInput < istat.st_size) {
182  size_t toRead = readInput + 1024 * 1024 < istat.st_size ? 1024 * 1024 : istat.st_size - readInput;
183  fread(outBuf, toRead, 1, src);
184  cms::Adler32((const char*)outBuf, toRead, adlera, adlerb);
185  readInput += toRead;
186  }
187  fclose(src);
188 
189  //clear serialization buffers
190  jsonWriter_->streamerCommon_.getSerializerBuffer()->clearHeaderBuffer();
191 
192  //free output buffer needed only for the file write
193  delete[] outBuf;
194  outBuf = nullptr;
195 
196  uint32_t adler32c = (adlerb << 16) | adlera;
197  if (adler32c != preamble_adler32) {
198  throw cms::Exception("EvFOutputModule") << "Checksum mismatch of ini file -: " << openIniFileName
199  << " expected:" << preamble_adler32 << " obtained:" << adler32c;
200  } else {
201  LogDebug("EvFOutputModule") << "Ini file checksum -: " << streamLabel_ << " " << adler32c;
202  boost::filesystem::rename(openIniFileName, edm::Service<evf::EvFDaqDirector>()->getInitFilePath(streamLabel_));
203  }
204  }
#define LogDebug(id)
ParameterSetID const & mainParameterSetID() const
std::unique_ptr< evf::EvFOutputJSONWriter > jsonWriter_
ModuleDescription const & description() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
edm::ParameterSet const & ps_
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
std::string const & moduleLabel() const
std::string streamLabel_
SelectedProductsForBranchType const & keptProducts() const
unsigned int uint32
Definition: MsgTools.h:13
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
const ModuleDescription & moduleDescription() const
BranchIDLists const * branchIDLists()
void evf::EvFOutputModule::endRun ( edm::RunForOutput const &  )
inlineoverrideprivate
void evf::EvFOutputModule::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static
Trig evf::EvFOutputModule::getTriggerResults ( edm::EDGetTokenT< edm::TriggerResults > const &  token,
edm::EventForOutput const &  e 
) const
private
std::shared_ptr< EvFOutputEventWriter > evf::EvFOutputModule::globalBeginLuminosityBlock ( edm::LuminosityBlockForOutput const &  iLB) const
overrideprivate

Definition at line 213 of file EvFOutputModule.cc.

References edm::LuminosityBlockForOutput::luminosityBlock(), and streamLabel_.

214  {
215  auto openDatFilePath = edm::Service<evf::EvFDaqDirector>()->getOpenDatFilePath(iLB.luminosityBlock(), streamLabel_);
216 
217  return std::make_shared<EvFOutputEventWriter>(openDatFilePath);
218  }
std::string streamLabel_
void evf::EvFOutputModule::globalEndLuminosityBlock ( edm::LuminosityBlockForOutput const &  iLB)
overrideprivate

Definition at line 231 of file EvFOutputModule.cc.

References fms_, evf::FastMonitoringService::getEventsProcessedForLumi(), edm::LuminosityBlockForOutput::index(), jsonWriter_, edm::LuminosityBlockForOutput::luminosityBlock(), castor_dqm_sourceclient_file_cfg::path, hgcalPlots::stat, streamLabel_, and AlCaHLTBitMon_QueryRunRegistry::string.

231  {
232  auto lumiWriter = luminosityBlockCache(iLB.index());
233  //close dat file
234  lumiWriter->close();
235 
236  jsonWriter_->fileAdler32_.value() = lumiWriter->get_adler32();
237  jsonWriter_->accepted_.value() = lumiWriter->getAccepted();
238 
239  bool abortFlag = false;
240  jsonWriter_->processed_.value() = fms_->getEventsProcessedForLumi(iLB.luminosityBlock(), &abortFlag);
241  if (abortFlag) {
242  edm::LogInfo("EvFOutputModule") << "Abort flag has been set. Output is suppressed";
243  return;
244  }
245 
246  if (jsonWriter_->processed_.value() != 0) {
247  struct stat istat;
248  boost::filesystem::path openDatFilePath = lumiWriter->getFilePath();
249  stat(openDatFilePath.string().c_str(), &istat);
250  jsonWriter_->filesize_ = istat.st_size;
251  boost::filesystem::rename(
252  openDatFilePath.string().c_str(),
253  edm::Service<evf::EvFDaqDirector>()->getDatFilePath(iLB.luminosityBlock(), streamLabel_));
254  jsonWriter_->filelist_ = openDatFilePath.filename().string();
255  } else {
256  //remove empty file when no event processing has occurred
257  remove(lumiWriter->getFilePath().c_str());
258  jsonWriter_->filesize_ = 0;
259  jsonWriter_->filelist_ = "";
260  jsonWriter_->fileAdler32_.value() = -1; //no files in signed long
261  }
262 
263  //produce JSON file
264  jsonWriter_->jsonMonitor_->snap(iLB.luminosityBlock());
265  const std::string outputJsonNameStream =
266  edm::Service<evf::EvFDaqDirector>()->getOutputJsonFilePath(iLB.luminosityBlock(), streamLabel_);
267  jsonWriter_->jsonMonitor_->outputFullJSON(outputJsonNameStream, iLB.luminosityBlock());
268  }
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=0)
std::unique_ptr< evf::EvFOutputJSONWriter > jsonWriter_
std::string streamLabel_
evf::FastMonitoringService * fms_
void evf::EvFOutputModule::write ( edm::EventForOutput const &  e)
overrideprivatevirtual

Implements edm::one::OutputModuleBase.

Definition at line 220 of file EvFOutputModule.cc.

References MillePedeFileConverter_cfg::e, edm::EventForOutput::getLuminosityBlock(), getTriggerResults(), edm::LuminosityBlockForOutput::index(), jsonWriter_, mps_check::msg, edm::one::OutputModuleBase::selectorConfig(), triggerResults, and trToken_.

Referenced by pkg.AbstractPkg::generate().

220  {
222 
223  //auto lumiWriter = const_cast<EvFOutputEventWriter*>(luminosityBlockCache(e.getLuminosityBlock().index() ));
224  auto lumiWriter = luminosityBlockCache(e.getLuminosityBlock().index());
225  std::unique_ptr<EventMsgBuilder> msg = jsonWriter_->streamerCommon_.serializeEvent(
226  *jsonWriter_->streamerCommon_.getSerializerBuffer(), e, triggerResults, selectorConfig());
227  lumiWriter->incAccepted();
228  lumiWriter->doOutputEvent(*msg); //msg is written and discarded at this point
229  }
std::unique_ptr< evf::EvFOutputJSONWriter > jsonWriter_
ParameterSetID selectorConfig() const
static std::string const triggerResults
Definition: EdmProvDump.cc:45
edm::EDGetTokenT< edm::TriggerResults > trToken_
tuple msg
Definition: mps_check.py:285
Trig getTriggerResults(edm::EDGetTokenT< edm::TriggerResults > const &token, edm::EventForOutput const &e) const
void evf::EvFOutputModule::writeLuminosityBlock ( edm::LuminosityBlockForOutput const &  )
inlineoverrideprivatevirtual

Implements edm::one::OutputModuleBase.

Definition at line 83 of file EvFOutputModule.h.

83 {}
void evf::EvFOutputModule::writeRun ( edm::RunForOutput const &  )
inlineoverrideprivatevirtual

Implements edm::one::OutputModuleBase.

Definition at line 84 of file EvFOutputModule.h.

84 {}

Member Data Documentation

evf::FastMonitoringService* evf::EvFOutputModule::fms_
private

Definition at line 97 of file EvFOutputModule.h.

Referenced by EvFOutputModule(), and globalEndLuminosityBlock().

std::unique_ptr<evf::EvFOutputJSONWriter> evf::EvFOutputModule::jsonWriter_
private

Definition at line 99 of file EvFOutputModule.h.

Referenced by beginRun(), globalEndLuminosityBlock(), and write().

edm::ParameterSet const& evf::EvFOutputModule::ps_
private

Definition at line 93 of file EvFOutputModule.h.

Referenced by beginRun().

std::string evf::EvFOutputModule::streamLabel_
private
edm::EDGetTokenT<edm::TriggerResults> evf::EvFOutputModule::trToken_
private

Definition at line 95 of file EvFOutputModule.h.

Referenced by write().