1 #ifndef IOPool_Streamer_RecoEventOutputModuleForFU_h
2 #define IOPool_Streamer_RecoEventOutputModuleForFU_h
11 #include <boost/filesystem.hpp>
12 #include <boost/algorithm/string.hpp>
24 template<
typename Consumer>
41 virtual void start()
override;
42 virtual void stop()
override;
51 std::auto_ptr<Consumer>
c_;
74 template<
typename Consumer>
77 edm::StreamerOutputModuleBase(ps),
79 stream_label_(ps.getParameter<std::
string>(
"@module_label")),
88 transferDestination_(),
90 outBuf_(new unsigned
char[1024*1024])
94 LogDebug(
"RecoEventOutputModuleForFU") <<
"writing .dat files to -: " << baseRunDir;
105 <<
"Underscore character is reserved can not be used for stream names in FFF, but was detected in stream name -: " <<
stream_label_;
110 boost::algorithm::to_lower(stream_label_lo);
111 auto streampos = stream_label_lo.rfind(
"stream");
112 if (streampos !=0 && streampos!=std::string::npos)
114 <<
"stream (case-insensitive) sequence was found in stream suffix. This is reserved and can not be used for names in FFF based HLT, but was detected in stream name";
140 std::stringstream tmpss,
ss;
141 tmpss << baseRunDir <<
"/open/" <<
"output_" << getpid() <<
".jsd";
142 ss << baseRunDir <<
"/" <<
"output_" << getpid() <<
".jsd";
148 if (stat (outJsonDefName.c_str(), &fstat) != 0) {
149 LogDebug(
"RecoEventOutputModuleForFU") <<
"writing output definition file -: " << outJsonDefName;
153 boost::filesystem::rename(outTmpJsonDefName,outJsonDefName);
173 template<
typename Consumer>
176 template<
typename Consumer>
181 edm::LogInfo(
"RecoEventOutputModuleForFU") <<
"start() method, initializing streams. init stream -: "
183 c_->setInitMessageFile(openInitFileName);
188 template<
typename Consumer>
195 template<
typename Consumer>
199 c_->doOutputHeader(init_message);
203 stat(openIniFileName.c_str(), &istat);
206 uint32_t adlera=1,adlerb=0;
207 FILE *
src = fopen(openIniFileName.c_str(),
"r");
208 while (readInput<istat.st_size)
210 size_t toRead= readInput+1024*1024 < istat.st_size ? 1024*1024 : istat.st_size-readInput;
211 fread(outBuf_,toRead,1,src);
212 cms::Adler32((
const char*)outBuf_,toRead,adlera,adlerb);
216 uint32_t adler32c = (adlerb << 16) | adlera;
217 if (adler32c != c_->get_adler32_ini()) {
218 throw cms::Exception(
"RecoEventOutputModuleForFU") <<
"Checksum mismatch of ini file -: " << openIniFileName
219 <<
" expected:" << c_->get_adler32_ini() <<
" obtained:" << adler32c;
222 edm::LogWarning(
"RecoEventOutputModuleForFU") <<
"Ini file checksum -: "<< stream_label_ <<
" " << adler32c;
227 template<
typename Consumer>
231 c_->doOutputEvent(msg);
234 template<
typename Consumer>
239 Consumer::fillDescription(desc);
240 descriptions.
add(
"EvFOutputModule", desc);
243 template<
typename Consumer>
251 template<
typename Consumer>
257 c_->setOutputFile(openDatFilePath_.string());
258 filelist_ = openDatFilePath_.filename().string();
261 template<
typename Consumer>
266 fileAdler32_.value() = c_->get_adler32();
267 c_->closeOutputFile();
268 bool abortFlag =
false;
269 processed_.value() = fms_->getEventsProcessedForLumi(ls.
luminosityBlock(),&abortFlag);
272 edm::LogInfo(
"RecoEventOutputModuleForFU") <<
"output suppressed";
276 if(processed_.value()!=0) {
285 uint32_t mergedAdler32=1;
287 if (!stat(deschecksum.c_str(), &istat)) {
289 cf = fopen(deschecksum.c_str(),
"r");
290 if (!cf)
throw cms::Exception(
"RecoEventOutputModuleForFU") <<
"Unable to open checksum file -: " << deschecksum.c_str();
291 fscanf(cf,
"%u",&mergedAdler32);
294 else edm::LogWarning(
"RecoEventOutputModuleForFU") <<
"Checksum file size is empty -: "<< deschecksum.c_str();
297 FILE *
src = fopen(openDatFilePath_.string().c_str(),
"r");
299 stat(openDatFilePath_.string().c_str(), &istat);
303 while (readInput<istat.st_size) {
304 size_t toRead= readInput+1024*1024 < istat.st_size ? 1024*1024 : istat.st_size-readInput;
305 fread(outBuf_,toRead,1,src);
306 fwrite(outBuf_,toRead,1,des);
307 if (readAdler32Check_)
308 cms::Adler32((
const char*)outBuf_,toRead,adlera,adlerb);
321 cf = fopen(deschecksum.c_str(),
"w");
322 if (!cf)
throw cms::Exception(
"RecoEventOutputModuleForFU") <<
"Unable to open or rewind checksum file for writing -:" << deschecksum.c_str();
325 mergedAdler32 = adler32_combine(mergedAdler32,fileAdler32_.value(),filesize);
327 fprintf(cf,
"%u",mergedAdler32);
333 if (readAdler32Check_ && ((adlerb << 16) | adlera) != fileAdler32_.value()) {
335 throw cms::Exception(
"RecoEventOutputModuleForFU") <<
"Adler32 checksum mismatch after reading file -: "
336 << openDatFilePath_.string() <<
" in LS " << ls.
luminosityBlock() << std::endl;
344 fileAdler32_.value()=-1;
348 remove(openDatFilePath_.string().c_str());
354 jsonMonitor_->outputFullJSON(outputJsonNameStream,ls.
luminosityBlock());
357 accepted_.value() = 0;
virtual void start() override
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
static void fillDescription(ParameterSetDescription &desc)
jsoncollector::IntJ accepted_
static const std::string BINARYOR
boost::shared_ptr< jsoncollector::FastMonitor > jsonMonitor_
static const std::string ADLER32
jsoncollector::IntJ filesize_
static const std::string SUM
static bool serialize(JsonSerializable *pObj, std::string &output)
jsoncollector::IntJ hltErrorEvents_
virtual ~RecoEventOutputModuleForFU()
virtual void doOutputEvent(EventMsgBuilder const &msg) override
virtual void endLuminosityBlock(edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *) override
virtual void beginLuminosityBlock(edm::LuminosityBlockPrincipal const &, edm::ModuleCallingContext const *) override
RecoEventOutputModuleForFU(edm::ParameterSet const &ps)
LuminosityBlockNumber_t luminosityBlock() const
jsoncollector::IntJ fileAdler32_
virtual void setName(std::string name)
jsoncollector::StringJ filelist_
static const std::string MERGE
evf::FastMonitoringService * fms_
boost::filesystem::path openDatChecksumFilePath_
jsoncollector::StringJ transferDestination_
virtual void doOutputHeader(InitMsgBuilder const &init_message) override
static void writeStringToFile(std::string const &filename, std::string &content)
static const std::string CAT
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
std::string stream_label_
jsoncollector::IntJ errorEvents_
jsoncollector::IntJ retCodeMask_
jsoncollector::DataPointDefinition outJsonDef_
std::auto_ptr< Consumer > c_
virtual void stop() override
virtual void beginJob() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
jsoncollector::IntJ processed_
jsoncollector::StringJ inputFiles_
void setDefaultGroup(std::string const &group)
boost::filesystem::path openDatFilePath_
static const std::string SAME