CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
evf::RecoEventOutputModuleForFU< Consumer > Class Template Reference

#include <RecoEventOutputModuleForFU.h>

Inheritance diagram for evf::RecoEventOutputModuleForFU< Consumer >:
edm::StreamerOutputModuleBase edm::OutputModule edm::EDConsumerBase

Public Member Functions

 RecoEventOutputModuleForFU (edm::ParameterSet const &ps)
 
virtual ~RecoEventOutputModuleForFU ()
 
- Public Member Functions inherited from edm::StreamerOutputModuleBase
 StreamerOutputModuleBase (ParameterSet const &ps)
 
virtual ~StreamerOutputModuleBase ()
 
- Public Member Functions inherited from edm::OutputModule
BranchChildren const & branchChildren () const
 
BranchIDLists const * branchIDLists () const
 
std::array< bool,
NumBranchTypes > const & 
hasNewlyDroppedBranch () const
 
SelectedProductsForBranchType
const & 
keptProducts () const
 
int maxEvents () const
 
OutputModuleoperator= (OutputModule const &)=delete
 
 OutputModule (ParameterSet const &pset)
 
 OutputModule (OutputModule const &)=delete
 
std::string const & processName () const
 
int remainingEvents () const
 
bool selected (BranchDescription const &desc) const
 
void selectProducts (ProductRegistry const &preg)
 
bool wantAllEvents () const
 
virtual ~OutputModule ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

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

Private Member Functions

virtual void beginLuminosityBlock (edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *)
 
virtual void doOutputEvent (EventMsgBuilder const &msg) const
 
virtual void doOutputHeader (InitMsgBuilder const &init_message) const
 
virtual void endLuminosityBlock (edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *)
 
virtual void start () const
 
virtual void stop () const
 

Private Attributes

IntJ accepted_
 
std::auto_ptr< Consumer > c_
 
IntJ errorEvents_
 
IntJ fileAdler32_
 
StringJ filelist_
 
IntJ filesize_
 
evf::FastMonitoringServicefms_
 
StringJ inputFiles_
 
boost::shared_ptr< FastMonitorjsonMonitor_
 
boost::filesystem::path openDatChecksumFilePath_
 
boost::filesystem::path openDatFilePath_
 
unsigned char * outBuf_ =0
 
DataPointDefinition outJsonDef_
 
IntJ processed_
 
bool readAdler32Check_ =false
 
IntJ retCodeMask_
 
std::string stream_label_
 

Additional Inherited Members

- Public Types inherited from edm::OutputModule
typedef OutputModule ModuleType
 
- Protected Member Functions inherited from edm::OutputModule
void configure (OutputModuleDescription const &desc)
 
ModuleDescription const & description () const
 
void doBeginJob ()
 
bool doBeginLuminosityBlock (LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
 
bool doBeginRun (RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
 
void doEndJob ()
 
bool doEndLuminosityBlock (LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
 
bool doEndRun (RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
 
bool doEvent (EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *act, ModuleCallingContext const *mcc)
 
void doPreallocate (PreallocationConfiguration const &)
 
std::map< BranchID::value_type,
BranchID::value_type > const & 
droppedBranchIDToKeptBranchID ()
 
Trig getTriggerResults (EventPrincipal const &ep, ModuleCallingContext const *) const
 
ModuleDescription const & moduleDescription () const
 
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 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

template<typename Consumer>
class evf::RecoEventOutputModuleForFU< Consumer >

Definition at line 24 of file RecoEventOutputModuleForFU.h.

Constructor & Destructor Documentation

template<typename Consumer >
evf::RecoEventOutputModuleForFU< Consumer >::RecoEventOutputModuleForFU ( edm::ParameterSet const &  ps)
explicit
Consumers are supposed to provide

void doOutputHeader(InitMsgBuilder const& init_message) void doOutputEvent(EventMsgBuilder const& msg) void start() void stop() static void fillDescription(ParameterSetDescription&)

Definition at line 71 of file RecoEventOutputModuleForFU.h.

References evf::RecoEventOutputModuleForFU< Consumer >::accepted_, jsoncollector::DataPointDefinition::addLegendItem(), ws_sso_content_reader::content, evf::RecoEventOutputModuleForFU< Consumer >::errorEvents_, evf::RecoEventOutputModuleForFU< Consumer >::fileAdler32_, evf::RecoEventOutputModuleForFU< Consumer >::filelist_, evf::RecoEventOutputModuleForFU< Consumer >::filesize_, evf::RecoEventOutputModuleForFU< Consumer >::fms_, evf::RecoEventOutputModuleForFU< Consumer >::inputFiles_, evf::RecoEventOutputModuleForFU< Consumer >::jsonMonitor_, LogDebug, evf::RecoEventOutputModuleForFU< Consumer >::outJsonDef_, evf::RecoEventOutputModuleForFU< Consumer >::processed_, evf::RecoEventOutputModuleForFU< Consumer >::readAdler32Check_, evf::RecoEventOutputModuleForFU< Consumer >::retCodeMask_, cond::serialize(), jsoncollector::DataPointDefinition::setDefaultGroup(), jsoncollector::JsonMonitorable::setName(), contentValuesCheck::ss, evf::RecoEventOutputModuleForFU< Consumer >::stream_label_, AlCaHLTBitMon_QueryRunRegistry::string, and SUM.

71  :
73  c_(new Consumer(ps)),
74  stream_label_(ps.getParameter<std::string>("@module_label")),
75  processed_(0),
76  accepted_(0),
77  errorEvents_(0),
78  retCodeMask_(0),
79  filelist_(),
80  filesize_(0),
81  inputFiles_(),
82  fileAdler32_(1),
83  outBuf_(new unsigned char[1024*1024])
84  {
85  std::string baseRunDir = edm::Service<evf::EvFDaqDirector>()->baseRunDir();
86  readAdler32Check_ = edm::Service<evf::EvFDaqDirector>()->outputAdler32Recheck();
87  LogDebug("RecoEventOutputModuleForFU") << "writing .dat files to -: " << baseRunDir;
88  // create open dir if not already there
89  edm::Service<evf::EvFDaqDirector>()->createRunOpendirMaybe();
90 
91  //replace hltOutoputA with stream if the HLT menu uses this convention
92  std::string testPrefix="hltOutput";
93  if (stream_label_.find(testPrefix)==0)
94  stream_label_=std::string("stream")+stream_label_.substr(testPrefix.size());
95 
97 
98  processed_.setName("Processed");
99  accepted_.setName("Accepted");
100  errorEvents_.setName("ErrorEvents");
101  retCodeMask_.setName("ReturnCodeMask");
102  filelist_.setName("Filelist");
103  filesize_.setName("Filesize");
104  inputFiles_.setName("InputFiles");
105  fileAdler32_.setName("FileAdler32");
106 
108  outJsonDef_.addLegendItem("Processed","integer",DataPointDefinition::SUM);
109  outJsonDef_.addLegendItem("Accepted","integer",DataPointDefinition::SUM);
110  outJsonDef_.addLegendItem("ErrorEvents","integer",DataPointDefinition::SUM);
111  outJsonDef_.addLegendItem("ReturnCodeMask","integer",DataPointDefinition::BINARYOR);
112  outJsonDef_.addLegendItem("Filelist","string",DataPointDefinition::MERGE);
113  outJsonDef_.addLegendItem("Filesize","integer",DataPointDefinition::SUM);
114  outJsonDef_.addLegendItem("InputFiles","string",DataPointDefinition::CAT);
115  outJsonDef_.addLegendItem("FileAdler32","integer",DataPointDefinition::ADLER32);
116  std::stringstream tmpss,ss;
117  tmpss << baseRunDir << "/open/" << "output_" << getpid() << ".jsd";
118  ss << baseRunDir << "/" << "output_" << getpid() << ".jsd";
119  std::string outTmpJsonDefName = tmpss.str();
120  std::string outJsonDefName = ss.str();
121 
122  edm::Service<evf::EvFDaqDirector>()->lockInitLock();
123  struct stat fstat;
124  if (stat (outJsonDefName.c_str(), &fstat) != 0) { //file does not exist
125  LogDebug("RecoEventOutputModuleForFU") << "writing output definition file -: " << outJsonDefName;
128  FileIO::writeStringToFile(outTmpJsonDefName, content);
129  boost::filesystem::rename(outTmpJsonDefName,outJsonDefName);
130  }
131  edm::Service<evf::EvFDaqDirector>()->unlockInitLock();
132 
133  jsonMonitor_.reset(new FastMonitor(&outJsonDef_,true));
134  jsonMonitor_->setDefPath(outJsonDefName);
135  jsonMonitor_->registerGlobalMonitorable(&processed_,false);
136  jsonMonitor_->registerGlobalMonitorable(&accepted_,false);
137  jsonMonitor_->registerGlobalMonitorable(&errorEvents_,false);
138  jsonMonitor_->registerGlobalMonitorable(&retCodeMask_,false);
139  jsonMonitor_->registerGlobalMonitorable(&filelist_,false);
140  jsonMonitor_->registerGlobalMonitorable(&filesize_,false);
141  jsonMonitor_->registerGlobalMonitorable(&inputFiles_,false);
142  jsonMonitor_->registerGlobalMonitorable(&fileAdler32_,false);
143  jsonMonitor_->commit(nullptr);
144  }
#define LogDebug(id)
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
boost::shared_ptr< FastMonitor > jsonMonitor_
virtual void setName(std::string name)
#define SUM(A, B)
std::pair< Binary, Binary > serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:92
void setDefaultGroup(std::string const &group)
template<typename Consumer >
evf::RecoEventOutputModuleForFU< Consumer >::~RecoEventOutputModuleForFU ( )
virtual

Definition at line 147 of file RecoEventOutputModuleForFU.h.

147 {}

Member Function Documentation

template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::beginLuminosityBlock ( edm::LuminosityBlockPrincipal const &  ls,
edm::ModuleCallingContext const *   
)
privatevirtual

Reimplemented from edm::OutputModule.

Definition at line 191 of file RecoEventOutputModuleForFU.h.

References edm::LuminosityBlockPrincipal::luminosityBlock().

192  {
193  //edm::LogInfo("RecoEventOutputModuleForFU") << "begin lumi";
194  openDatFilePath_ = edm::Service<evf::EvFDaqDirector>()->getOpenDatFilePath(ls.luminosityBlock(),stream_label_);
195  openDatChecksumFilePath_ = edm::Service<evf::EvFDaqDirector>()->getOpenDatFilePath(ls.luminosityBlock(),stream_label_);
196  c_->setOutputFile(openDatFilePath_.string());
197  filelist_ = openDatFilePath_.filename().string();
198  }
boost::filesystem::path openDatChecksumFilePath_
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::doOutputEvent ( EventMsgBuilder const &  msg) const
privatevirtual

Implements edm::StreamerOutputModuleBase.

Definition at line 176 of file RecoEventOutputModuleForFU.h.

176  {
177  accepted_.value()++;
178  c_->doOutputEvent(msg); // You can't use msg in RecoEventOutputModuleForFU after this point
179  }
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::doOutputHeader ( InitMsgBuilder const &  init_message) const
privatevirtual

Implements edm::StreamerOutputModuleBase.

Definition at line 169 of file RecoEventOutputModuleForFU.h.

170  {
171  c_->doOutputHeader(init_message);
172  }
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::endLuminosityBlock ( edm::LuminosityBlockPrincipal const &  ls,
edm::ModuleCallingContext const *   
)
privatevirtual

Reimplemented from edm::OutputModule.

Definition at line 201 of file RecoEventOutputModuleForFU.h.

References cms::Adler32(), edm::hlt::Exception, edm::LuminosityBlockPrincipal::luminosityBlock(), NULL, alcazmumu_cfi::src, and AlCaHLTBitMon_QueryRunRegistry::string.

202  {
203  //edm::LogInfo("RecoEventOutputModuleForFU") << "end lumi";
204  long filesize=0;
205  fileAdler32_.value() = c_->get_adler32();
206  c_->closeOutputFile();
207  processed_.value() = fms_->getEventsProcessedForLumi(ls.luminosityBlock());
208 
209 
210  if(processed_.value()!=0){
211 
212  //lock
213  FILE *des = edm::Service<evf::EvFDaqDirector>()->maybeCreateAndLockFileHeadForStream(ls.luminosityBlock(),stream_label_);
214 
215  std::string deschecksum = edm::Service<evf::EvFDaqDirector>()->getMergedDatChecksumFilePath(ls.luminosityBlock(), stream_label_);
216 
217  struct stat istat;
218  FILE * cf = NULL;
219  uint32_t mergedAdler32=1;
220  //get adler32 accumulated checksum for the merged file
221  if (!stat(deschecksum.c_str(), &istat)) {
222  if (istat.st_size) {
223  cf = fopen(deschecksum.c_str(),"r");
224  if (!cf) throw cms::Exception("RecoEventOutputModuleForFU") << "Unable to open checksum file -: " << deschecksum.c_str();
225  fscanf(cf,"%u",&mergedAdler32);
226  fclose(cf);
227  }
228  else edm::LogWarning("RecoEventOutputModuleForFU") << "Checksum file size is empty -: "<< deschecksum.c_str();
229  }
230 
231  FILE *src = fopen(openDatFilePath_.string().c_str(),"r");
232 
233  stat(openDatFilePath_.string().c_str(), &istat);
234  off_t readInput=0;
235  uint32_t adlera=1;
236  uint32_t adlerb=0;
237  while (readInput<istat.st_size) {
238  size_t toRead= readInput+1024*1024 < istat.st_size ? 1024*1024 : istat.st_size-readInput;
239  fread(outBuf_,toRead,1,src);
240  fwrite(outBuf_,toRead,1,des);
241  if (readAdler32Check_)
242  cms::Adler32((const char*)outBuf_,toRead,adlera,adlerb);
243  readInput+=toRead;
244  filesize+=toRead;
245  }
246 
247  //if(des != 0 && src !=0){
248  // while((b=fgetc(src))!= EOF){
249  // fputc((unsigned char)b,des);
250  // filesize++;
251  // }
252  //}
253 
254  //write new string representation of the checksum value
255  cf = fopen(deschecksum.c_str(),"w");
256  if (!cf) throw cms::Exception("RecoEventOutputModuleForFU") << "Unable to open or rewind checksum file for writing -:" << deschecksum.c_str();
257 
258  //write adler32 combine to checksum file
259  mergedAdler32 = adler32_combine(mergedAdler32,fileAdler32_.value(),filesize);
260 
261  fprintf(cf,"%u",mergedAdler32);
262  fclose(cf);
263 
264  edm::Service<evf::EvFDaqDirector>()->unlockAndCloseMergeStream();
265  fclose(src);
266 
267  if (readAdler32Check_ && ((adlerb << 16) | adlera) != fileAdler32_.value()) {
268 
269  throw cms::Exception("RecoEventOutputModuleForFU") << "Adler32 checksum mismatch after reading file -: "
270  << openDatFilePath_.string() <<" in LS " << ls.luminosityBlock() << std::endl;
271  }
272 
273  }
274  //remove file
275  remove(openDatFilePath_.string().c_str());
276  filesize_=filesize;
277 
278  // output jsn file
279  if(processed_.value()!=0){
280  jsonMonitor_->snap(ls.luminosityBlock());
281  const std::string outputJsonNameStream =
282  edm::Service<evf::EvFDaqDirector>()->getOutputJsonFilePath(ls.luminosityBlock(),stream_label_);
283  jsonMonitor_->outputFullJSON(outputJsonNameStream,ls.luminosityBlock());
284  }
285 
286  // reset monitoring params
287  accepted_.value() = 0;
288  filelist_ = "";
289  }
#define NULL
Definition: scimark2.h:8
unsigned int getEventsProcessedForLumi(unsigned int lumi)
boost::shared_ptr< FastMonitor > jsonMonitor_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 183 of file RecoEventOutputModuleForFU.h.

References edm::ConfigurationDescriptions::add(), and edm::StreamerOutputModuleBase::fillDescription().

183  {
186  Consumer::fillDescription(desc);
187  descriptions.add("streamerOutput", desc);
188  }
static void fillDescription(ParameterSetDescription &desc)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::start ( void  ) const
privatevirtual

Implements edm::StreamerOutputModuleBase.

Definition at line 151 of file RecoEventOutputModuleForFU.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by progressbar.ProgressBar::__next__(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

152  {
153  const std::string initFileName = edm::Service<evf::EvFDaqDirector>()->getInitFilePath(stream_label_);
154  edm::LogInfo("RecoEventOutputModuleForFU") << "start() method, initializing streams. init stream -: "
155  << initFileName;
156  c_->setInitMessageFile(initFileName);
157  c_->start();
158  }
template<typename Consumer >
void evf::RecoEventOutputModuleForFU< Consumer >::stop ( ) const
privatevirtual

Implements edm::StreamerOutputModuleBase.

Definition at line 162 of file RecoEventOutputModuleForFU.h.

163  {
164  c_->stop();
165  }

Member Data Documentation

template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::accepted_
mutableprivate
template<typename Consumer >
std::auto_ptr<Consumer> evf::RecoEventOutputModuleForFU< Consumer >::c_
private

Definition at line 49 of file RecoEventOutputModuleForFU.h.

template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::errorEvents_
private
template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::fileAdler32_
private
template<typename Consumer >
StringJ evf::RecoEventOutputModuleForFU< Consumer >::filelist_
private
template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::filesize_
private
template<typename Consumer >
evf::FastMonitoringService* evf::RecoEventOutputModuleForFU< Consumer >::fms_
private
template<typename Consumer >
StringJ evf::RecoEventOutputModuleForFU< Consumer >::inputFiles_
private
template<typename Consumer >
boost::shared_ptr<FastMonitor> evf::RecoEventOutputModuleForFU< Consumer >::jsonMonitor_
private
template<typename Consumer >
boost::filesystem::path evf::RecoEventOutputModuleForFU< Consumer >::openDatChecksumFilePath_
private

Definition at line 52 of file RecoEventOutputModuleForFU.h.

template<typename Consumer >
boost::filesystem::path evf::RecoEventOutputModuleForFU< Consumer >::openDatFilePath_
private

Definition at line 51 of file RecoEventOutputModuleForFU.h.

template<typename Consumer >
unsigned char* evf::RecoEventOutputModuleForFU< Consumer >::outBuf_ =0
private

Definition at line 64 of file RecoEventOutputModuleForFU.h.

template<typename Consumer >
DataPointDefinition evf::RecoEventOutputModuleForFU< Consumer >::outJsonDef_
private
template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::processed_
private
template<typename Consumer >
bool evf::RecoEventOutputModuleForFU< Consumer >::readAdler32Check_ =false
private
template<typename Consumer >
IntJ evf::RecoEventOutputModuleForFU< Consumer >::retCodeMask_
private
template<typename Consumer >
std::string evf::RecoEventOutputModuleForFU< Consumer >::stream_label_
private