33 unsigned int fileLimit,
const std::string& outputDir,
bool forceMakeOutputDir,
bool removeInputFile):
42 if(!inpDir.exists()||!inpDir.isDir()||!inpDir.isReadable()||!inpDir.isWritable()) {
43 std::string errMessage = std::string(
"VP1FileUtilities: ERROR!! The directory ") + inputDirectory + std::string(
" either does not exist or is not writable");
44 throw std::runtime_error(errMessage.c_str());
50 if(!inpDir.exists()||!inpDir.isDir()||!inpDir.isReadable()||!inpDir.isWritable()) {
51 std::string errMessage = std::string(
"VP1FileUtilities: ERROR!! The directory ") +
m_outputDirectory + std::string(
" does not exist.");
53 errMessage +=
"\nforceMakeOutputDir=True --> Creating the output folder now...";
56 throw std::runtime_error(errMessage.c_str());
68 unsigned int runNumber,
69 unsigned long long eventNumber,
70 unsigned int timeStamp,
71 const std::string& textLabel)
74 QString srcName(sourceFile.c_str());
75 QFile srcFile(srcName);
78 throw std::runtime_error(
"Source file does not exist!");
84 QString newFileName = inpDirName;
85 std::ostringstream newFileStr;
92 QString latestEventFileName = inpDirName + QString(newFileStr.str().c_str()) + QString(
"latest_vp1event");
94 if (textLabel !=
"" ) {
95 newFileStr <<
"vp1_r" << runNumber <<
"_ev" << eventNumber <<
"_u" << timeStamp <<
"_t" << textLabel <<
".pool.root";
97 newFileStr <<
"vp1_r" << runNumber <<
"_ev" << eventNumber <<
"_u" << timeStamp <<
".pool.root";
100 newFileName += QString(newFileStr.str().c_str());
104 if (outDirName !=
"")
105 newFileName = outDirName + QDir::separator() + newFileName;
108 std::cout <<
"VP1FileUtilities -- copying '" << (srcFile.fileName()).toStdString() <<
"' to: '" << newFileName.toStdString() <<
"'..." << std::endl;
112 qint64 inputSize = srcFile.size();
113 std::cout <<
"VP1FileUtilities -- Size of the input file to be copied: " << inputSize << std::endl;
116 if(!srcFile.copy(newFileName)) {
117 throw std::runtime_error(
"VP1FileUtilities -- Unable to copy the temp file to the new file, so unable to produce the new vp1 event file");
121 std::cout <<
"VP1FileUtilities -- delete temp file? --> " <<
m_removeInputFile << std::endl;
123 bool copyDone =
false;
124 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now() ;
125 typedef std::chrono::duration<int,std::milli> millisecs_t ;
135 std::cout <<
"VP1FileUtilities -- Size of the file to be deleted: " <<
checkFile.size() << std::endl;
137 if(!srcFile.remove())
138 std::cerr <<
"VP1FileUtilities -- WARNING! Unable to delete " << sourceFile << std::endl;
142 std::cout <<
"VP1FileUtilities -- I could not find the output file, so probably the copy action is not finished yet. I'll wait for a short while and I will retry..." << std::endl;
143 std::this_thread::sleep_for(std::chrono::milliseconds(500));
144 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now() ;
145 millisecs_t duration( std::chrono::duration_cast<millisecs_t>(end-start) ) ;
146 if (duration.count() > 2000.0 )
148 std::cout <<
"VP1FileUtilities -- WARNING!!! " << duration.count() <<
" milliseconds passed and still I cannot find the output file. Probably there was a problem. Giving up with the removal of the source file...\n" ;
156 QFile latestEvent(latestEventFileName);
157 if(latestEvent.exists() && !latestEvent.remove())
158 throw std::runtime_error(
"VP1FileUtilities -- Unable to overwrite the existing latest event file");
160 if(!latestEvent.open(QIODevice::WriteOnly | QIODevice::Text))
161 throw std::runtime_error(
"VP1FileUtilities -- Unable to create new latest event file");
162 latestEvent.write(newFileName.toStdString().c_str());
167 std::cout <<
"VP1FileUtilities -- cleaning up..." << std::endl;
182 QStringList nameFilters;
183 nameFilters <<
"vp1_*.pool.root";
185 dir.setFilter(QDir::Files);
186 dir.setNameFilters(nameFilters);
187 dir.setSorting(QDir::Time|QDir::Reversed);
188 QFileInfoList list = dir.entryInfoList();
192 const QFileInfo& fileInfo = list.at(0);
194 if(!dir.remove(fileInfo.fileName()))
195 throw std::runtime_error(
"VP1FileUtilities::cleanup() - WARNING: Unable to do the clean up!");
198 QString poolCatalog(
"PoolFileCatalog.xml");
199 std::string poolCatalogStr = poolCatalog.toStdString();
200 std::cout <<
"looking for " << poolCatalogStr <<
" in " << QDir::currentPath().toStdString() << std::endl;
201 if ( QDir::current().entryList().
contains( poolCatalog ) ) {
202 std::cout <<
"VP1FileUtilities::cleanUp() - removing the file '" << poolCatalogStr <<
"' because it causes problems for subsequent Athena commands opening the copied file." << std::endl;
203 QDir
cwd = QDir::currentPath();
204 if ( !
cwd.remove( poolCatalog ) )
205 std::cerr <<
"VP1FileUtilities WARNING! Unable to delete " << poolCatalogStr << std::endl;