12 #include "boost/shared_array.hpp"
32 fileRecord_(fileRecord),
33 dbFileHandler_(dbFileHandler),
35 lastEntry_(firstEntry_),
36 diskWritingParams_(dwParams),
37 maxFileSize_(maxFileSize),
41 if(cmsver_[0]==
'"') cmsver_=cmsver_.substr(1,cmsver_.size()-2);
45 insertFileInDatabase();
52 std::ostringstream
msg;
53 msg <<
"Tried to write an event to "
55 <<
"which has already been closed.";
56 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
73 std::ostringstream oss;
74 oss <<
"./closeFile.pl "
77 <<
" --NEVENTS " <<
events()
81 <<
" --STATUS " <<
"closed"
94 <<
" --CHECKSUM " << std::hex <<
fileRecord_->adler32
104 std::ostringstream oss;
105 oss <<
"./insertFile.pl "
108 <<
" --NEVENTS " <<
events()
122 <<
" --APPNAME CMSSW"
123 <<
" --TYPE streamer"
125 <<
" --CHECKSUMIND 0"
200 const uint64_t openFileSize = checkFileSizeMatch(openFileName, fileSize());
202 makeFileReadOnly(openFileName);
205 renameFile(openFileName, closedFileName);
207 catch (stor::exception::DiskWriting& e)
209 XCEPT_RETHROW(stor::exception::DiskWriting,
210 "Could not move streamer file to closed area.", e);
212 fileRecord_->isOpen =
false;
213 fileRecord_->whyClosed = reason;
214 checkFileSizeMatch(closedFileName, openFileSize);
215 checkAdler32(closedFileName);
222 struct stat64 statBuff;
223 int statStatus = stat64(fileName.c_str(), &statBuff);
225 struct stat statBuff;
226 int statStatus = stat(fileName.c_str(), &statBuff);
228 if ( statStatus != 0 )
231 std::ostringstream
msg;
232 msg <<
"Error checking the status of file "
234 <<
": " << strerror(errno);
235 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
241 std::ostringstream
msg;
242 msg <<
"Found an unexpected file size when trying to move"
243 <<
" the file to the closed state. File " << fileName
244 <<
" has an actual size of " << statBuff.st_size
245 <<
" (" << statBuff.st_blocks <<
" blocks)"
246 <<
" instead of the expected size of " << size
247 <<
" (" << (size/512)+1 <<
" blocks).";
248 XCEPT_RAISE(stor::exception::FileTruncation, msg.str());
251 return static_cast<uint64_t>(statBuff.st_size);
257 double pctDiff =
calcPctDiff(initialSize, finalSize);
264 int ronly = chmod(fileName.c_str(), S_IREAD|S_IRGRP|S_IROTH);
266 std::ostringstream
msg;
267 msg <<
"Unable to change permissions of " << fileName
268 <<
" to read only: " << strerror(errno);
269 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
278 std::ifstream
file(fileName.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
281 std::ostringstream
msg;
282 msg <<
"File " << fileName <<
" could not be opened.\n";
283 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
286 std::ifstream::pos_type
size =
file.tellg();
287 file.seekg (0, std::ios::beg);
289 boost::shared_array<char> ptr(
new char[1024*1024]);
290 uint32_t
a = 1,
b = 0;
292 std::ifstream::pos_type rsize = 0;
295 file.read(ptr.get(), 1024*1024);
304 const uint32 adler = (
b << 16) | a;
307 std::ostringstream
msg;
308 msg <<
"Disk resident file " << fileName <<
309 " has Adler32 checksum " << std::hex << adler <<
310 ", while the expected checkum is " << std::hex <<
fileRecord_->adler32;
311 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
318 const std::string& openFileName,
319 const std::string& closedFileName
322 int result = rename( openFileName.c_str(), closedFileName.c_str() );
325 std::ostringstream
msg;
326 msg <<
"Unable to move " << openFileName <<
" to "
327 << closedFileName <<
": " << strerror(errno);
328 XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
344 if (value1 == value2)
return 0;
347 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_
FileHandler(FilesMonitorCollection::FileRecordPtr, const DbFileHandlerPtr, const DiskWritingParams &, 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
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