72{
73
74 QString srcName(sourceFile.c_str());
76
78 throw std::runtime_error("Source file does not exist!");
79
82
83
84 QString newFileName = inpDirName;
85 std::ostringstream newFileStr;
86
87
88
90 newFileStr << "/";
91
92 QString latestEventFileName = inpDirName + QString(newFileStr.str().c_str()) + QString("latest_vp1event");
93
94 if (textLabel != "" ) {
96 } else {
98 }
99
100 newFileName += QString(newFileStr.str().c_str());
101
102
103
104 if (outDirName != "")
105 newFileName = outDirName + QDir::separator() + newFileName;
106
107
108 std::cout <<
"VP1FileUtilities -- copying '" << (
srcFile.fileName()).toStdString() <<
"' to: '" << newFileName.toStdString() <<
"'..." << std::endl;
109
110
111
112 qint64 inputSize =
srcFile.size();
113 std::cout << "VP1FileUtilities -- Size of the input file to be copied: " << inputSize << std::endl;
114
115
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");
118 }
119
120
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 ;
126 while (!copyDone) {
127
128
130
131
132
134 {
135 std::cout <<
"VP1FileUtilities -- Size of the file to be deleted: " <<
checkFile.size() << std::endl;
136 copyDone = true;
138 std::cerr << "VP1FileUtilities -- WARNING! Unable to delete " << sourceFile << std::endl;
139 }
140 else
141 {
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) ) ;
147 {
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" ;
149 copyDone = true;
150 }
151 }
152 }
153 }
154
155
156 QFile latestEvent(latestEventFileName);
157 if(latestEvent.exists() && !latestEvent.remove())
158 throw std::runtime_error("VP1FileUtilities -- Unable to overwrite the existing latest event file");
159
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());
163 latestEvent.close();
164
165
167 std::cout << "VP1FileUtilities -- cleaning up..." << std::endl;
169 }
170}
checkFile(fileName, the_type, requireTree)