12 #include "boost/shared_array.hpp"
31 fileRecord_(fileRecord),
32 dbFileHandler_(dbFileHandler),
34 lastEntry_(firstEntry_),
35 diskWritingParams_(dbFileHandler->getDiskWritingParams()),
36 maxFileSize_(maxFileSize),
40 if(cmsver_[0]==
'"') cmsver_=cmsver_.substr(1,cmsver_.size()-2);
44 insertFileInDatabase();
51 std::ostringstream
msg;
52 msg <<
"Tried to write an event to "
54 <<
"which has already been closed.";
55 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
72 std::ostringstream oss;
73 oss <<
"./closeFile.pl "
76 <<
" --NEVENTS " <<
events()
80 <<
" --STATUS " <<
"closed"
93 <<
" --CHECKSUM " << std::hex <<
fileRecord_->adler32
94 <<
" --CHECKSUMIND 0";
102 std::ostringstream oss;
103 oss <<
"./insertFile.pl "
106 <<
" --NEVENTS " <<
events()
120 <<
" --APPNAME CMSSW"
121 <<
" --TYPE streamer"
123 <<
" --CHECKSUMIND 0";
197 const uint64_t openFileSize = checkFileSizeMatch(openFileName, fileSize());
199 makeFileReadOnly(openFileName);
202 renameFile(openFileName, closedFileName);
204 catch (stor::exception::DiskWriting&
e)
206 XCEPT_RETHROW(stor::exception::DiskWriting,
207 "Could not move streamer file to closed area.", e);
209 fileRecord_->isOpen =
false;
210 fileRecord_->whyClosed =
reason;
211 checkFileSizeMatch(closedFileName, openFileSize);
212 checkAdler32(closedFileName);
219 struct stat64 statBuff;
220 int statStatus = stat64(fileName.c_str(), &statBuff);
222 struct stat statBuff;
223 int statStatus = stat(fileName.c_str(), &statBuff);
225 if ( statStatus != 0 )
228 std::ostringstream
msg;
229 msg <<
"Error checking the status of file "
231 <<
": " << strerror(errno);
232 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
238 std::ostringstream
msg;
239 msg <<
"Found an unexpected file size when trying to move"
240 <<
" the file to the closed state. File " << fileName
241 <<
" has an actual size of " << statBuff.st_size
242 <<
" (" << statBuff.st_blocks <<
" blocks)"
243 <<
" instead of the expected size of " << size
244 <<
" (" << (size/512)+1 <<
" blocks).";
245 XCEPT_RAISE(stor::exception::FileTruncation, msg.str());
248 return static_cast<uint64_t>(statBuff.st_size);
254 double pctDiff =
calcPctDiff(initialSize, finalSize);
261 int ronly = chmod(fileName.c_str(), S_IREAD|S_IRGRP|S_IROTH);
263 std::ostringstream
msg;
264 msg <<
"Unable to change permissions of " << fileName
265 <<
" to read only: " << strerror(errno);
266 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
275 std::ifstream
file(fileName.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
278 std::ostringstream
msg;
279 msg <<
"File " << fileName <<
" could not be opened.\n";
280 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
283 std::ifstream::pos_type
size =
file.tellg();
284 file.seekg (0, std::ios::beg);
286 boost::shared_array<char> ptr(
new char[1024*1024]);
287 uint32_t
a = 1,
b = 0;
289 std::ifstream::pos_type rsize = 0;
292 file.read(ptr.get(), 1024*1024);
301 const uint32 adler = (
b << 16) | a;
304 std::ostringstream
msg;
305 msg <<
"Disk resident file " << fileName <<
306 " has Adler32 checksum " << std::hex << adler <<
307 ", while the expected checkum is " << std::hex <<
fileRecord_->adler32;
308 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
319 int result = rename( openFileName.c_str(), closedFileName.c_str() );
322 std::ostringstream
msg;
323 msg <<
"Unable to move " << openFileName <<
" to "
324 << closedFileName <<
": " << strerror(errno);
325 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
341 if (value1 == value2)
return 0;
344 return ( largerValue > 0 ? (largerValue - smallerValue) / largerValue : 0 );
TimePoint_t getCurrentTime()
uint64_t fileSize() const
void moveFileToClosed(const FilesMonitorCollection::FileRecord::ClosingReason &)
virtual void closeFile(const FilesMonitorCollection::FileRecord::ClosingReason &)=0
utils::Duration_t lumiSectionTimeOut_
double fileSizeTolerance_
const uint64_t maxFileSize_
std::string smInstanceString_
void insertFileInDatabase() const
boost::shared_ptr< FileRecord > FileRecordPtr
long secondsSinceEpoch(TimePoint_t const &)
utils::TimePoint_t firstEntry_
const T & max(const T &a, const T &b)
bool sizeMismatch(const uint64_t &initialSize, const uint64_t &finalSize) const
boost::shared_ptr< DbFileHandler > DbFileHandlerPtr
FileHandler(FilesMonitorCollection::FileRecordPtr, const DbFileHandlerPtr, const uint64_t &maxFileSize)
utils::TimePoint_t lastEntry_
void updateDatabase() const
boost::posix_time::ptime TimePoint_t
void writeEvent(const I2OChain &)
const DiskWritingParams & diskWritingParams_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void checkDirectory(const std::string &)
void makeFileReadOnly(const std::string &fileName) const
bool tooOld(const utils::TimePoint_t currentTime=utils::getCurrentTime())
void renameFile(const std::string &openFileName, const std::string &closedFileName) const
std::string getReleaseVersion()
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
unsigned long long uint64_t
virtual void do_writeEvent(const I2OChain &event)=0
FilesMonitorCollection::FileRecordPtr fileRecord_
uint64_t checkFileSizeMatch(const std::string &fileName, const uint64_t &size) const
void checkDirectories() const
bool tooLarge(const uint64_t &dataSize)
const DbFileHandlerPtr dbFileHandler_
tuple size
Write out results.
double calcPctDiff(const uint64_t &, const uint64_t &) const
bool isFromLumiSection(const uint32_t lumiSection)
void checkAdler32(const std::string &fileName) const