ATLAS Offline Software
Loading...
Searching...
No Matches
offline_EventStorage_v5::DataWriter Class Reference

#include <v5_DataWriter.h>

Inheritance diagram for offline_EventStorage_v5::DataWriter:
Collaboration diagram for offline_EventStorage_v5::DataWriter:

Public Types

using iovec_const = offline_EventStorage_v5::iovec_const

Public Member Functions

 DataWriter (const std::string &writingPath, const std::string &fileNameCore, const run_parameters_record &rPar, const std::vector< std::string > &fmdStrings, const unsigned int startIndex=1, const CompressionType compression=NONE, const unsigned int compLevel=1)
 constructor with metadata strings
 DataWriter (const std::string &writingPath, boost::shared_ptr< EventStorage::FileNameCallback > theFNCB, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression=NONE, const unsigned int compLevel=1)
 DataWriter (const std::string &writingPath, const std::string &fileNameCore, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression=NONE, const unsigned int compLevel=1)
 ~DataWriter ()
 destructor, the way to close the sequence of files
EventStorage::DWError setMaxFileNE (const unsigned int &maxFileNE)
 max size of 1 file in number of data blocks (or events) 1 putData call is one block
EventStorage::DWError setMaxFileMB (const unsigned int &maxFileMB)
 max size of 1 file in MB.
void setGUID (const std::string &GUID)
 Set the GUID for the next file in this sequence.
bool good () const
 feedback to user
void cd (const std::string &writingPath)
 set another writing path
bool inTransition () const
 The file currently open is not closed immediately after cd() this method will return true if we are in transition phase, i.e.
EventStorage::DWError putData (const unsigned int &dataSize, const void *event)
 Write a single block of data.
EventStorage::DWError putPrecompressedData (const unsigned int &dataSize, const void *event)
 Write a single block of data already compressed.
EventStorage::DWError putPrecompressedData (const unsigned int &entries, const iovec_const *my_iovec)
 Write a single block of data already compressed.
EventStorage::DWError putData (const unsigned int &entries, const struct iovec *my_iovec)
 Write data when you have one event scattered in many blocks, in memory, like in the SFI application.
EventStorage::DWError putData (const unsigned int &dataSize, const void *event, uint32_t &sizeToDisk)
 Write a single block of data.
EventStorage::DWError putData (const unsigned int &entries, const iovec_const *my_iovec, uint32_t &sizeToDisk)
 Write data when you have one event scattered in many blocks, in memory, like in the SFI application.
EventStorage::DWError closeFile ()
 Close the currently open file.
EventStorage::DWError nextFile ()
 close the file and open next one immediately
std::string nameFile (const FileStatus &fs) const
 get the name of the current file
int64_t getPosition () const
 get the offset of the latest written event; one should call it AFTER putData(...)
unsigned int eventsInFile () const
 number of events written to the currently open file
unsigned int eventsInFileSequence () const
 number of events written to the file sequence
unsigned int dataMB_InFile () const
 number of mega bytes written to the current file
unsigned int dataMB_InFileSequence () const
 number of mega bytes written to the file sequence
void registerCallBack (EventStorage::DataWriterCallBack *pUserCBclass)
 If you want to define actions to be taken when a file is open or closed register your call-back class here with this method.
CompressionType getCompression () const
 Returns the compression type for this file.
void setGuid (const std::string &Guid)
 Externally set the GUID for the next file in this sequence.

Private Member Functions

 DataWriter ()
void initDW (const std::string &writingPath, boost::shared_ptr< EventStorage::FileNameCallback > theFNCB, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression, const unsigned int compLevel)
EventStorage::DWError putData_implementation (const unsigned int &entries, const iovec_const *my_iovec, uint32_t &sizeToDisk, bool precompressed=false)
void date_timeAsInt (uint32_t &getDate, uint32_t &getTime) const
void openNextFile ()
bool fileExists (const std::string &name) const
void setRunParamsRecord (const run_parameters_record &rPar)
void file_record (void *ri, const void *pi)
void file_record (const file_name_strings &nst)
void file_record (const freeMetaDataStrings &fmdStrings)
std::string getAppName (const std::string &fileNameCore) const
std::string getElement (const std::string &fileNameCore, const std::string &element) const
uint64_t getFileSize (const std::string &fileNameCore) const
void spaceForGuid ()
void replaceGuid ()

Private Attributes

std::fstream m_cFile
bool m_cFileOpen
bool m_openFailed
file_start_record m_file_start_record
file_name_strings m_file_name_strings
internal_run_parameters_record m_internal_run_parameters_record
file_end_record m_file_end_record
std::string m_guid
std::string m_next_guid
std::string m_writePath
std::string m_nextWritePath
std::string m_fileNameCore
std::string m_project
std::string m_streamType
std::string m_streamName
std::string m_stream
unsigned int m_lumiBlockNumber
std::string m_applicationName
CompressionType m_compression
unsigned int m_complevel
DataBufferm_compressed
double m_cFileMB
long double m_runMB
uLong m_check
int64_t m_latestPosition
EventStorage::DataWriterCallBack * m_callBack
freeMetaDataStrings m_fmdStrings
boost::shared_ptr< EventStorage::FileNameCallback > m_filenamecallback

Detailed Description

Definition at line 44 of file v5_DataWriter.h.

Member Typedef Documentation

◆ iovec_const

Constructor & Destructor Documentation

◆ DataWriter() [1/4]

DataWriter::DataWriter ( const std::string & writingPath,
const std::string & fileNameCore,
const run_parameters_record & rPar,
const std::vector< std::string > & fmdStrings,
const unsigned int startIndex = 1,
const CompressionType compression = NONE,
const unsigned int compLevel = 1 )

constructor with metadata strings

Parameters
writingPathdirectory where to write data
fileNameCorefile name not including the ending "._NNNN.data"
run_parameters_recordrPar other parameters from IS including the run number
fmdStringsoptional vector of strings containing metadata
startIndexinitial file sequence index
compressionCompression type
compLevelCompression level

Definition at line 73 of file v5_DataWriter.cxx.

81{
82 boost::shared_ptr<daq::RawFileName>
83 fileName(new daq::RawFileName(fileNameCore));
84
85 if ( fileName->hasValidCore() ) {
86 m_project = fileName->project();
87 m_streamType = fileName->streamType();
88 m_streamName = fileName->streamName();
89 m_stream = fileName->stream();
90 m_lumiBlockNumber = fileName->lumiBlockNumber();
91 m_applicationName = fileName->applicationName();
92 } else {
93 std::stringstream mystream;
94 mystream << "FileName " << fileName->fileName()
95 << " has failed interpretation."
96 << " The file header will have no values for "
97 << " project, stream, lumiBlock and appName";
98 ERS_DEBUG(1,mystream.str());
99 // EventStorage::RawFileNameIssue myissue(ERS_HERE, mystream.str().c_str() );
100 // ers::warning(myissue);
101 m_project = "";
102 m_streamType = "";
103 m_streamName = "";
104 m_stream = "";
107 }
108
109 fileName->setFileSequenceNumber(startIndex);
110
111 initDW(writingPath, fileName, rPar, m_project, m_streamType, m_streamName,
113 fmdStrings, compression,compLevel);
114
115}
void initDW(const std::string &writingPath, boost::shared_ptr< EventStorage::FileNameCallback > theFNCB, const run_parameters_record &rPar, const std::string &project, const std::string &streamType, const std::string &streamName, const std::string &stream, const unsigned int lumiBlockNumber, const std::string &applicationName, const std::vector< std::string > &fmdStrings, const CompressionType compression, const unsigned int compLevel)

◆ DataWriter() [2/4]

offline_EventStorage_v5::DataWriter::DataWriter ( const std::string & writingPath,
boost::shared_ptr< EventStorage::FileNameCallback > theFNCB,
const run_parameters_record & rPar,
const std::string & project,
const std::string & streamType,
const std::string & streamName,
const std::string & stream,
const unsigned int lumiBlockNumber,
const std::string & applicationName,
const std::vector< std::string > & fmdStrings,
const CompressionType compression = NONE,
const unsigned int compLevel = 1 )

◆ DataWriter() [3/4]

DataWriter::DataWriter ( const std::string & writingPath,
const std::string & fileNameCore,
const run_parameters_record & rPar,
const std::string & project,
const std::string & streamType,
const std::string & streamName,
const std::string & stream,
const unsigned int lumiBlockNumber,
const std::string & applicationName,
const std::vector< std::string > & fmdStrings,
const CompressionType compression = NONE,
const unsigned int compLevel = 1 )

Definition at line 118 of file v5_DataWriter.cxx.

131{
132 boost::shared_ptr<FileNameCallback> fileName(new SimpleFileName(fileNameCore));
133 initDW(writingPath, fileName, rPar, project, streamType, streamName, stream, lumiBlockNumber, applicationName, fmdStrings, compression, compLevel);
134
135}
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)

◆ DataWriter() [4/4]

offline_EventStorage_v5::DataWriter::DataWriter ( )
private

◆ ~DataWriter()

DataWriter::~DataWriter ( )

destructor, the way to close the sequence of files

Definition at line 138 of file v5_DataWriter.cxx.

139{
140 ERS_DEBUG(1,"DataWriter::~DataWriter() called.");
141
142 m_file_end_record.status = 1; // This identifies the end of the sequence.
144
145 delete m_compressed;
146
147 ERS_DEBUG(1,"DataWriter::~DataWriter() finished.");
148}
EventStorage::DWError closeFile()
Close the currently open file.

Member Function Documentation

◆ cd()

void DataWriter::cd ( const std::string & writingPath)

set another writing path

Definition at line 651 of file v5_DataWriter.cxx.

651 {
652 m_nextWritePath = writingPath;
653 ERS_DEBUG(3,"Directory changed to "<<m_nextWritePath
654 <<" (effective for hext file).");
655}

◆ closeFile()

DWError DataWriter::closeFile ( )

Close the currently open file.

Next file will be open anyway if you try to write again afterwards.

Definition at line 465 of file v5_DataWriter.cxx.

466{
467 ERS_DEBUG(3,"DataWriter::closeFile() called.");
468
469 // do statistics
470 m_file_end_record.data_in_file = static_cast<unsigned int>(m_cFileMB+0.5);
471 m_file_end_record.data_in_run = static_cast<unsigned int>(m_runMB+0.5);
472
474
475 // write eof record
477
478 m_cFile.close();
479 std::ostringstream oss;
480 oss.width(8);
481 (void)oss.fill('0');
482 oss << std::hex << std::uppercase <<m_check;
483 std::string checksum = oss.str();
484 m_check = ::adler32(0L, Z_NULL, 0);
485
486 // rename the file
487 ERS_DEBUG(3,"Rename file " << nameFile(UNFINISHED) << endl
488 << "to " << nameFile(FINISHED));
489 if (::rename(nameFile(UNFINISHED).c_str(), nameFile(FINISHED).c_str()) == -1) {
490
491 EventStorage::WritingIssue ci(ERS_HERE, "Rename failed.");
492 ers::error(ci);
493 return EventStorage::DWNOOK;
494 }
495
496 // check if the file is there
498 {
499 ERS_DEBUG(2,"Finished file "<<nameFile(FINISHED));
500 if(m_callBack != NULL) {
501 ERS_DEBUG(3,"Execute callback from DataWriter.");
502 m_callBack->FileWasClosed(
503 m_filenamecallback->getCurrentFileName(),
508 m_guid,
509 std::move(checksum),
510 m_file_end_record.events_in_file,
512 m_file_start_record.file_number,
515 );
516 }
517
518 // now we can substitute new directory, if specified
519 if(m_nextWritePath != "") {
522 ERS_DEBUG(3,"New writing path became effective. The path is "
523 <<m_writePath);
524 }
525 m_cFileOpen = false;
526
527 try{
528 m_filenamecallback->advance();
529 }catch(EventStorage::ES_SingleFile &e){
530 //If opennext file is called, it
531 // will fail there
532 }
533 return EventStorage::DWOK;
534 }
535 return EventStorage::DWNOOK;
536}
void date_timeAsInt(uint32_t &getDate, uint32_t &getTime) const
internal_run_parameters_record m_internal_run_parameters_record
void file_record(void *ri, const void *pi)
std::string nameFile(const FileStatus &fs) const
get the name of the current file
EventStorage::DataWriterCallBack * m_callBack
bool fileExists(const std::string &name) const
uint64_t getFileSize(const std::string &fileNameCore) const
boost::shared_ptr< EventStorage::FileNameCallback > m_filenamecallback
const file_end_record file_end_pattern

◆ dataMB_InFile()

unsigned int DataWriter::dataMB_InFile ( ) const

number of mega bytes written to the current file

Definition at line 454 of file v5_DataWriter.cxx.

455{
456 return static_cast<unsigned int>(m_cFileMB+0.5);
457}

◆ dataMB_InFileSequence()

unsigned int DataWriter::dataMB_InFileSequence ( ) const

number of mega bytes written to the file sequence

Definition at line 459 of file v5_DataWriter.cxx.

460{
461 return static_cast<unsigned int>(m_runMB+0.5);
462}

◆ date_timeAsInt()

void DataWriter::date_timeAsInt ( uint32_t & getDate,
uint32_t & getTime ) const
private

Definition at line 233 of file v5_DataWriter.cxx.

234{
235 long a_time;
236 time(&a_time);
237
238 struct tm t;
239 localtime_r( &a_time, &t);
240
241 getDate= 1000000*t.tm_mday+
242 10000*(1+t.tm_mon)+
243 1900+t.tm_year;
244
245 getTime= 10000*t.tm_hour+
246 100*t.tm_min+
247 t.tm_sec ;
248}
time(flags, cells_name, *args, **kw)
float getTime(const xAOD::TrackParticle &p)
Accessor utility function for getting the track time.

◆ eventsInFile()

unsigned int DataWriter::eventsInFile ( ) const

number of events written to the currently open file

Definition at line 444 of file v5_DataWriter.cxx.

445{
446 return m_file_end_record.events_in_file;
447}

◆ eventsInFileSequence()

unsigned int DataWriter::eventsInFileSequence ( ) const

number of events written to the file sequence

Definition at line 449 of file v5_DataWriter.cxx.

450{
451 return m_file_end_record.events_in_run;
452}

◆ file_record() [1/3]

void DataWriter::file_record ( const file_name_strings & nst)
private

Definition at line 684 of file v5_DataWriter.cxx.

684 {
685
686 const char *cName = nst.appName.c_str();
687 const char *cTag = nst.fileNameCore.c_str();
688
689 uint32_t sizeName = nst.appName.size();
690 uint32_t sizeTag = nst.fileNameCore.size();
691
692 m_cFile.write(ccharAddress(offline_EventStorage_v5::file_name_strings_marker),sizeof(uint32_t));
693 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>
695 sizeof(uint32_t));
696
697 m_cFile.write(charAddress(sizeName),sizeof(uint32_t));
698 m_check = ::adler32(m_check,cbytefAddress(sizeName),sizeof(uint32_t));
699 m_cFile.write(cName,sizeName);
700 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(cName),sizeName);
701
702 char ns = sizeName % 4;
703 if(ns){
704 m_cFile.write(" ",4-ns);
705 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(" "),4-ns);
706 }
707
708 m_cFile.write(charAddress(sizeTag),sizeof(uint32_t));
709 m_check = ::adler32(m_check,bytefAddress(sizeTag),sizeof(uint32_t));
710 m_cFile.write(cTag,sizeTag);
711 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(cTag),sizeTag);
712
713 ns = sizeTag % 4;
714 if(ns){
715 m_cFile.write(" ",4-ns);
716 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(" "),4-ns);
717 }
718
719}
setEventNumber uint32_t

◆ file_record() [2/3]

void DataWriter::file_record ( const freeMetaDataStrings & fmdStrings)
private

Definition at line 721 of file v5_DataWriter.cxx.

722{
723 ERS_DEBUG(2,"Writing the metadata strings.");
724
725 m_cFile.write(ccharAddress(offline_EventStorage_v5::free_strings_marker),sizeof(uint32_t));
726 m_check = ::adler32(m_check, reinterpret_cast<const Bytef*>
728 sizeof(uint32_t));
729
730 uint32_t nstrings = fmdStrings.size();
731 m_cFile.write(charAddress(nstrings),sizeof(uint32_t));
732 m_check = ::adler32(m_check, bytefAddress(nstrings),
733 sizeof(uint32_t));
734
735 vector<string>::const_iterator it;
736 for(it=fmdStrings.begin(); it!=fmdStrings.end(); ++it) {
737
738 const char *cst = it->c_str();
739 uint32_t slen = it->size();
740
741 m_cFile.write(charAddress(slen),sizeof(uint32_t));
742 m_check = ::adler32(m_check,bytefAddress(slen),sizeof(uint32_t));
743 m_cFile.write(cst,slen);
744 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(cst),slen);
745 char ns = slen % 4;
746 if(ns){
747 m_cFile.write(" ",4-ns);
748 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(" "),4-ns);
749 }
750 }
751}

◆ file_record() [3/3]

void DataWriter::file_record ( void * ri,
const void * pi )
private

Definition at line 666 of file v5_DataWriter.cxx.

666 {
667
668 uint32_t *record = reinterpret_cast<uint32_t *>(ri);
669 const uint32_t *pattern = reinterpret_cast<const uint32_t *>(pi);
670 int size=pattern[1];
671
672 for(int i=0; i<size; i++) {
673 if(pattern[i] != 0) {
674 m_cFile.write(reinterpret_cast<const char*>(pattern+i),sizeof(uint32_t));
675 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(pattern+i),sizeof(uint32_t));
676 } else {
677 m_cFile.write(reinterpret_cast<char*>(record+i),sizeof(uint32_t));
678 m_check = ::adler32(m_check,reinterpret_cast<const Bytef*>(record+i),sizeof(uint32_t));
679 }
680 }
681}
#define pi

◆ fileExists()

bool DataWriter::fileExists ( const std::string & name) const
private

Definition at line 556 of file v5_DataWriter.cxx.

557{
558 ifstream test(name.c_str(),ios::binary | ios::in);
559 bool isThere = test.good();
560 test.close();
561
562 return isThere;
563}

◆ getAppName()

std::string offline_EventStorage_v5::DataWriter::getAppName ( const std::string & fileNameCore) const
private

◆ getCompression()

offline_EventStorage_v5::CompressionType DataWriter::getCompression ( ) const

Returns the compression type for this file.

Definition at line 807 of file v5_DataWriter.cxx.

808{
809 return m_compression;
810}

◆ getElement()

std::string offline_EventStorage_v5::DataWriter::getElement ( const std::string & fileNameCore,
const std::string & element ) const
private

◆ getFileSize()

uint64_t DataWriter::getFileSize ( const std::string & fileNameCore) const
private

Definition at line 794 of file v5_DataWriter.cxx.

795{
796 struct stat64 tmp;
797 if (::stat64(fileNameCore.c_str(), &tmp) == -1) {
798 EventStorage::WritingIssue ci(ERS_HERE, "stat64 failed.");
799 ers::error(ci);
800 return 0;
801 }
802
803 return tmp.st_size;
804}

◆ getPosition()

int64_t DataWriter::getPosition ( ) const

get the offset of the latest written event; one should call it AFTER putData(...)

Definition at line 438 of file v5_DataWriter.cxx.

439{
440 return m_latestPosition;
441}

◆ good()

bool DataWriter::good ( ) const

feedback to user

Definition at line 251 of file v5_DataWriter.cxx.

252{
253
254 if(m_openFailed) return false;
255
256 if(m_cFileOpen)
257 {
258 return m_cFile.good();
259 }
260 else
261 {
262 return true;
263 }
264
265}

◆ initDW()

void DataWriter::initDW ( const std::string & writingPath,
boost::shared_ptr< EventStorage::FileNameCallback > theFNCB,
const run_parameters_record & rPar,
const std::string & project,
const std::string & streamType,
const std::string & streamName,
const std::string & stream,
const unsigned int lumiBlockNumber,
const std::string & applicationName,
const std::vector< std::string > & fmdStrings,
const CompressionType compression,
const unsigned int compLevel )
private

Definition at line 151 of file v5_DataWriter.cxx.

164{
169 m_lumiBlockNumber = lumiBlockNumber;
170 m_applicationName = applicationName;
171
172 m_filenamecallback = theFNCB;
173
177 m_cFileMB = 0.0;
178 m_runMB = 0.0;
179 m_latestPosition = -1;
180
181 m_writePath = writingPath;
182 m_nextWritePath = "";
183 //m_fileNameCore = fileNameCore;
184
186 // m_file_name_strings.appName = getAppName(fileNameCore);
187 m_file_name_strings.fileNameCore = m_filenamecallback->getCoreName();
188
189 setRunParamsRecord(rPar);
190
191 m_file_start_record.sizeLimit_MB = 0;
192 m_file_start_record.sizeLimit_dataBlocks = 0;
194
195 m_cFileOpen=false;
196 m_openFailed = false;
197
198 m_callBack = NULL;
199
200 m_fmdStrings = fmdStrings;
201
202 m_compression = compression;
203 m_complevel = compLevel;
204 m_compressed = new DataBuffer();
205
206 // add stream, project, compression, lumiBlock
207 // (if they are valid) to meta-data:
208 m_fmdStrings.push_back("Stream=" + m_stream );
209 m_fmdStrings.push_back("Project=" + m_project );
210 std::ostringstream o;
212 m_fmdStrings.push_back("LumiBlock=" + o.str());
213
215 m_fmdStrings.push_back(offline_EventStorage_v5::compressiontag +
216 "=" + offline_EventStorage_v5::type_to_string(m_compression));
217 }
218
219 m_check = ::adler32(0L, Z_NULL, 0);
220
221 m_guid = "";
222 m_next_guid = "";
223 this->spaceForGuid();
224 this->openNextFile();
225
226}
void setRunParamsRecord(const run_parameters_record &rPar)
void reset_record(void *ri, const void *pi)
const internal_run_parameters_record run_parameters_pattern
const file_start_record file_start_pattern

◆ inTransition()

bool DataWriter::inTransition ( ) const

The file currently open is not closed immediately after cd() this method will return true if we are in transition phase, i.e.

the file has not yet been closed after a cd()

Definition at line 657 of file v5_DataWriter.cxx.

657 {
658
659 bool inT=false;
660 if((m_nextWritePath != "") &&
661 (m_nextWritePath != m_writePath)) inT=true;
662 return inT;
663
664}

◆ nameFile()

string DataWriter::nameFile ( const FileStatus & fs) const

get the name of the current file

Definition at line 642 of file v5_DataWriter.cxx.

643{
644 ostringstream n;
645 n << m_writePath << "/";
646 n << m_filenamecallback->getCurrentFileName((FINISHED == fs)?false:true);
647 string name = n.str();
648 return name;
649}
static Double_t fs

◆ nextFile()

DWError DataWriter::nextFile ( )

close the file and open next one immediately

Definition at line 539 of file v5_DataWriter.cxx.

540{
541 ERS_DEBUG(2,"DataWriter::nextFile() called.");
542
543 DWError we=closeFile();
544
545/* if (m_freename)
546 {
547 EventStorage::ES_SingleFile ci(ERS_HERE, "DataWriter called with freename = 1. DataWriter wants to go to next file, but cannot, since indexing is forbidden. Either deactive freename (so files can be indexed, or increase the file size limit (or turn it off)");
548 throw ci;
549 }*/
550
551 openNextFile();
552 if(m_openFailed) we=EventStorage::DWNOOK;
553 return we;
554}

◆ openNextFile()

void DataWriter::openNextFile ( )
private

Definition at line 565 of file v5_DataWriter.cxx.

566{
567 m_cFileMB=0.0;
568 m_file_end_record.events_in_file=0;
569
570 try{
571 m_file_start_record.file_number = m_filenamecallback->getIndex();
572 }catch(EventStorage::ES_SingleFile &e){
573 m_file_start_record.file_number++;
574 }
576
577 ERS_DEBUG(2,"Trying to open file "<<nameFile(UNFINISHED));
578
581 {
582
584 string err = "found an existing file with name " + nameFile(UNFINISHED);
585 EventStorage::WritingIssue ci(ERS_HERE, err.c_str());
586 ers::warning(ci);
587
588 } else {
589
590 string err = "found an existing file with name " + nameFile(FINISHED);
591 EventStorage::WritingIssue ci(ERS_HERE, err.c_str());
592 ers::warning(ci);
593 }
594 m_filenamecallback->fileAlreadyExists();
595
596 m_file_start_record.file_number = m_filenamecallback->getIndex();
597
598 ostringstream oss;
599 oss << "increase file number to ";
600 oss << m_file_start_record.file_number;
601 EventStorage::WritingIssue ci(ERS_HERE, oss.str().c_str());
602 ers::warning(ci);
603 }
604 ERS_DEBUG(2,"OK to write file with number "<<m_file_start_record.file_number);
605
606 ERS_DEBUG(2,"Opening file: " << nameFile(UNFINISHED));
607
608 m_cFile.clear();
609 m_cFile.open(nameFile(UNFINISHED).c_str(),
610 ios::out | ios::app | ios::binary);
611
612 m_check = ::adler32(0L, Z_NULL, 0);
613
616
617 this->replaceGuid();
618
619 ERS_DEBUG(3,"Writing "<<m_fmdStrings.size()<<" metadata strings.");
622 ERS_DEBUG(3,"Status of the file. good() returns "<<m_cFile.good());
623 m_cFileOpen = m_cFile.good();
624 m_openFailed = !m_cFile.good();
625
626 if((m_callBack != NULL) && m_cFileOpen) {
627 ERS_DEBUG(3,"Execute callback from DataWriter.");
628 m_callBack->FileWasOpened(
629 m_filenamecallback->getCurrentFileName(),
634 m_guid,
636 m_file_start_record.file_number,
638 );
639 }
640}

◆ putData() [1/4]

DWError DataWriter::putData ( const unsigned int & dataSize,
const void * event )

Write a single block of data.

If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
dataSizesize of the event in bytes
*eventstart of the event data in memory

Definition at line 298 of file v5_DataWriter.cxx.

299{
300
301 uint32_t todisk;
303 iov.iov_base = event;
304 iov.iov_len = dataSize;
305 return this->putData(1, &iov, todisk);
306}
offline_EventStorage_v5::iovec_const iovec_const
EventStorage::DWError putData(const unsigned int &dataSize, const void *event)
Write a single block of data.
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.

◆ putData() [2/4]

DWError DataWriter::putData ( const unsigned int & dataSize,
const void * event,
uint32_t & sizeToDisk )

Write a single block of data.

If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
dataSizesize of the eveny in bytes
*eventstart of the event data in memory
&sizeToDiskwill be update with the actual chunck size on disk

Definition at line 315 of file v5_DataWriter.cxx.

315 {
316
318 iov.iov_base = event;
319 iov.iov_len = dataSize;
320 return this->putData(1, &iov, sizeToDisk);
321}

◆ putData() [3/4]

DWError DataWriter::putData ( const unsigned int & entries,
const iovec_const * my_iovec,
uint32_t & sizeToDisk )

Write data when you have one event scattered in many blocks, in memory, like in the SFI application.

If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
entriesnumber of the data chunks
my_ioveclocations of the data chunks
&sizeToDiskwill be update with the actual chunck size on disk

Definition at line 323 of file v5_DataWriter.cxx.

323 {
324 return this->putData_implementation(entries, my_iovec, sizeToDisk);
325}
EventStorage::DWError putData_implementation(const unsigned int &entries, const iovec_const *my_iovec, uint32_t &sizeToDisk, bool precompressed=false)
double entries
Definition listroot.cxx:49

◆ putData() [4/4]

DWError DataWriter::putData ( const unsigned int & entries,
const struct iovec * my_iovec )

Write data when you have one event scattered in many blocks, in memory, like in the SFI application.

If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
numberof the data chunks
locationsof the data chunks

Definition at line 309 of file v5_DataWriter.cxx.

310{
311 uint32_t todisk;
312 return this->putData(entries, my_iovec, todisk);
313}

◆ putData_implementation()

DWError DataWriter::putData_implementation ( const unsigned int & entries,
const iovec_const * my_iovec,
uint32_t & sizeToDisk,
bool precompressed = false )
private

Definition at line 346 of file v5_DataWriter.cxx.

346 {
347
348 ERS_DEBUG(3,"DataWriter::putData called for an iovec.");
350
351 if(!m_cFileOpen) return EventStorage::DWNOOK;
352
353 if(!m_cFile.good()) return EventStorage::DWNOOK;
354
355 // calculate events size
356 unsigned int dataSize = 0;
357 for(unsigned int i = 0; i<entries; i++) {
358 dataSize += my_iovec[i].iov_len;
359 }
360
361
362
363 sizeToDisk = dataSize;
364
365
366 // apply limits
367 if(m_file_start_record.sizeLimit_MB>0) {
368 double eventMB=static_cast<double>(dataSize)/(1024*1024);
369 double dataMB=m_cFileMB+eventMB;
370 if(static_cast<unsigned int>(dataMB+0.5) >
371 m_file_start_record.sizeLimit_MB) {
372 ERS_DEBUG(3,"Approaching file size limit in MB.");
373 nextFile();
374 }
375 }
376
377 if((m_file_start_record.sizeLimit_dataBlocks>0) &&
378 (m_file_end_record.events_in_file >= m_file_start_record.sizeLimit_dataBlocks)){
379 ERS_DEBUG(3,"Approaching file size limit in number of events.");
380 nextFile();
381 }
382
383 //Here we should compress, so that we have the effective size
384 //for the event record
385 if(m_compression == ZLIB && !precompressed){
386 try{
387 offline_EventStorage_v5::zlibcompress(*m_compressed, sizeToDisk,
388 entries, my_iovec, dataSize, m_complevel);
389 }catch(offline_EventStorage_v5::CompressionIssue& ex){
390 EventStorage::WritingIssue ci(ERS_HERE, "Data compression failed.", ex);
391 ers::error(ci);
392 return EventStorage::DWNOOK;
393 }
394 }
395
396 // prepare the event record
397 data_separator_record dsR = data_separator_pattern;
398 dsR.data_block_number = m_file_end_record.events_in_run + 1;
399 dsR.data_block_size = sizeToDisk;
400
401 // remember the position
402 m_latestPosition = m_cFile.tellg();
403
404 // write the event record followed by event data
406
407
408 if(m_compression != ZLIB || precompressed){
409 for (unsigned int i =0; i<entries; i++){
410 m_cFile.write(static_cast<const char*>(my_iovec[i].iov_base),
411 my_iovec[i].iov_len);
412
413 m_check = ::adler32(m_check,
414 static_cast<const Bytef *>(my_iovec[i].iov_base),
415 my_iovec[i].iov_len);
416 }
417 }else{
418 m_cFile.write(static_cast<const char *>(m_compressed->handle()), sizeToDisk);
419 m_check = ::adler32(m_check,
420 static_cast<const Bytef *>(m_compressed->handle()),
421 sizeToDisk);
422 }
423
424 // update statistics
425 m_cFileMB += static_cast<double>(sizeToDisk)/(1024*1024);
426 m_runMB += static_cast<double>(sizeToDisk)/(1024*1024);
427 m_file_end_record.events_in_file++;
428 m_file_end_record.events_in_run++;
429
430 ERS_DEBUG(3,"Event "<< m_file_end_record.events_in_run<<" is written at offset "<<m_latestPosition);
431
432 if(!m_cFile.good()) return EventStorage::DWNOOK;
433
434 return EventStorage::DWOK;
435}
EventStorage::DWError nextFile()
close the file and open next one immediately
const data_separator_record data_separator_pattern

◆ putPrecompressedData() [1/2]

DWError DataWriter::putPrecompressedData ( const unsigned int & dataSize,
const void * event )

Write a single block of data already compressed.

WARNING* the library has now way to check if the compression algorithm matches the declared file type. The data is directly written to the file without check, completely trusting the caller. Use with care! If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
dataSizesize of the eveny in bytes
*eventstart of the event data in memory

Definition at line 328 of file v5_DataWriter.cxx.

329 {
330
332 iov.iov_base = event;
333 iov.iov_len = dataSize;
334 return this->putPrecompressedData(1, &iov);
335}
EventStorage::DWError putPrecompressedData(const unsigned int &dataSize, const void *event)
Write a single block of data already compressed.

◆ putPrecompressedData() [2/2]

DWError DataWriter::putPrecompressedData ( const unsigned int & entries,
const iovec_const * my_iovec )

Write a single block of data already compressed.

WARNING* the library has now way to check if the compression algorithm matches the declared file type. The data is directly written to the file without check, completely trusting the caller. Use with care! If one of the size limits would be exceeded, the current file will be closed and another one will be opened automatically.

Parameters
numberof the data chunks
locationsof the data chunks

Definition at line 338 of file v5_DataWriter.cxx.

339 {
340
341 uint32_t todisk;
342 return this->putData_implementation(entries, my_iovec, todisk, true);
343}

◆ registerCallBack()

void DataWriter::registerCallBack ( EventStorage::DataWriterCallBack * pUserCBclass)

If you want to define actions to be taken when a file is open or closed register your call-back class here with this method.

Definition at line 753 of file v5_DataWriter.cxx.

753 {
754 m_callBack = pUserCBclass;
755 if(m_callBack != NULL) {
756 m_callBack->FileWasOpened(
757 m_filenamecallback->getCurrentFileName(),
762 m_guid,
764 m_file_start_record.file_number,
766 );
767 }
768}

◆ replaceGuid()

void DataWriter::replaceGuid ( )
private

Definition at line 775 of file v5_DataWriter.cxx.

775 {
776 using namespace std;
777
778 if (m_next_guid == ""){
779 offline_poolCopy_v5::Guid g(true);
780 m_guid = g.toString();
781 }else{
783 m_next_guid = "";
784 }
785
786 m_fmdStrings[0] = "GUID=" + m_guid;
787}

◆ setGUID()

void offline_EventStorage_v5::DataWriter::setGUID ( const std::string & GUID)

Set the GUID for the next file in this sequence.

◆ setGuid()

void DataWriter::setGuid ( const std::string & Guid)

Externally set the GUID for the next file in this sequence.

Definition at line 789 of file v5_DataWriter.cxx.

789 {
791}

◆ setMaxFileMB()

DWError DataWriter::setMaxFileMB ( const unsigned int & maxFileMB)

max size of 1 file in MB.

The file is closed before this limit is overrun.

Definition at line 269 of file v5_DataWriter.cxx.

270{
271 m_file_start_record.sizeLimit_MB = maxFileMB;
272 return EventStorage::DWOK;
273}

◆ setMaxFileNE()

DWError DataWriter::setMaxFileNE ( const unsigned int & maxFileNE)

max size of 1 file in number of data blocks (or events) 1 putData call is one block

Definition at line 275 of file v5_DataWriter.cxx.

276{
277 m_file_start_record.sizeLimit_dataBlocks = maxFileNE;
278 return EventStorage::DWOK;
279}

◆ setRunParamsRecord()

void DataWriter::setRunParamsRecord ( const run_parameters_record & rPar)
private

Definition at line 281 of file v5_DataWriter.cxx.

282{
283 // accept the params, whatever they are
284 // run number is in this record (and only there)
291 m_internal_run_parameters_record.detector_mask_1of2 = rPar.detector_mask & 0xFFFFFFFF;
292 m_internal_run_parameters_record.detector_mask_2of2 = (rPar.detector_mask>> 32);
295}

◆ spaceForGuid()

void DataWriter::spaceForGuid ( )
private

Definition at line 770 of file v5_DataWriter.cxx.

770 {
771 string e("");
772 m_fmdStrings.insert(m_fmdStrings.begin(),e);
773}

Member Data Documentation

◆ m_applicationName

std::string offline_EventStorage_v5::DataWriter::m_applicationName
private

Definition at line 326 of file v5_DataWriter.h.

◆ m_callBack

EventStorage::DataWriterCallBack* offline_EventStorage_v5::DataWriter::m_callBack
private

Definition at line 338 of file v5_DataWriter.h.

◆ m_cFile

std::fstream offline_EventStorage_v5::DataWriter::m_cFile
private

Definition at line 304 of file v5_DataWriter.h.

◆ m_cFileMB

double offline_EventStorage_v5::DataWriter::m_cFileMB
private

Definition at line 332 of file v5_DataWriter.h.

◆ m_cFileOpen

bool offline_EventStorage_v5::DataWriter::m_cFileOpen
private

Definition at line 306 of file v5_DataWriter.h.

◆ m_check

uLong offline_EventStorage_v5::DataWriter::m_check
private

Definition at line 334 of file v5_DataWriter.h.

◆ m_complevel

unsigned int offline_EventStorage_v5::DataWriter::m_complevel
private

Definition at line 329 of file v5_DataWriter.h.

◆ m_compressed

DataBuffer* offline_EventStorage_v5::DataWriter::m_compressed
private

Definition at line 330 of file v5_DataWriter.h.

◆ m_compression

CompressionType offline_EventStorage_v5::DataWriter::m_compression
private

Definition at line 328 of file v5_DataWriter.h.

◆ m_file_end_record

file_end_record offline_EventStorage_v5::DataWriter::m_file_end_record
private

Definition at line 312 of file v5_DataWriter.h.

◆ m_file_name_strings

file_name_strings offline_EventStorage_v5::DataWriter::m_file_name_strings
private

Definition at line 310 of file v5_DataWriter.h.

◆ m_file_start_record

file_start_record offline_EventStorage_v5::DataWriter::m_file_start_record
private

Definition at line 309 of file v5_DataWriter.h.

◆ m_filenamecallback

boost::shared_ptr<EventStorage::FileNameCallback> offline_EventStorage_v5::DataWriter::m_filenamecallback
private

Definition at line 342 of file v5_DataWriter.h.

◆ m_fileNameCore

std::string offline_EventStorage_v5::DataWriter::m_fileNameCore
private

Definition at line 319 of file v5_DataWriter.h.

◆ m_fmdStrings

freeMetaDataStrings offline_EventStorage_v5::DataWriter::m_fmdStrings
private

Definition at line 340 of file v5_DataWriter.h.

◆ m_guid

std::string offline_EventStorage_v5::DataWriter::m_guid
private

Definition at line 314 of file v5_DataWriter.h.

◆ m_internal_run_parameters_record

internal_run_parameters_record offline_EventStorage_v5::DataWriter::m_internal_run_parameters_record
private

Definition at line 311 of file v5_DataWriter.h.

◆ m_latestPosition

int64_t offline_EventStorage_v5::DataWriter::m_latestPosition
private

Definition at line 336 of file v5_DataWriter.h.

◆ m_lumiBlockNumber

unsigned int offline_EventStorage_v5::DataWriter::m_lumiBlockNumber
private

Definition at line 325 of file v5_DataWriter.h.

◆ m_next_guid

std::string offline_EventStorage_v5::DataWriter::m_next_guid
private

Definition at line 315 of file v5_DataWriter.h.

◆ m_nextWritePath

std::string offline_EventStorage_v5::DataWriter::m_nextWritePath
private

Definition at line 318 of file v5_DataWriter.h.

◆ m_openFailed

bool offline_EventStorage_v5::DataWriter::m_openFailed
private

Definition at line 307 of file v5_DataWriter.h.

◆ m_project

std::string offline_EventStorage_v5::DataWriter::m_project
private

Definition at line 321 of file v5_DataWriter.h.

◆ m_runMB

long double offline_EventStorage_v5::DataWriter::m_runMB
private

Definition at line 333 of file v5_DataWriter.h.

◆ m_stream

std::string offline_EventStorage_v5::DataWriter::m_stream
private

Definition at line 324 of file v5_DataWriter.h.

◆ m_streamName

std::string offline_EventStorage_v5::DataWriter::m_streamName
private

Definition at line 323 of file v5_DataWriter.h.

◆ m_streamType

std::string offline_EventStorage_v5::DataWriter::m_streamType
private

Definition at line 322 of file v5_DataWriter.h.

◆ m_writePath

std::string offline_EventStorage_v5::DataWriter::m_writePath
private

Definition at line 317 of file v5_DataWriter.h.


The documentation for this class was generated from the following files: