30 std::string stream_ref =
"physics_MinBias";
31 int stream_check = -1;
32 stream_check = inFilename.find(stream_ref);
34 if (!isIncremental && stream_check >= 0) {
35 TFile* f = TFile::Open(inFilename.c_str(),
"UPDATE");
36 if (f == 0 || !f->IsOpen()) {
40 if (f->GetSize() < 1000.) {
45 bool dirExists =
false;
50 bool IsFirstTime =
true;
51 std::string AthenaTAG;
53 const char* AtlasVersion = getenv(
"AtlasVersion");
58 AthenaTAG = AtlasVersion;
59 std::string out_inStem;
61 std::string out_LOCAL;
62 std::string out_outStem;
64 TIter run_keys(f->GetListOfKeys());
65 TIter lb_keys(f->GetListOfKeys());
68 while ((key_run =
dynamic_cast<TKey*
>(run_keys())) != 0) {
69 TObject* obj_run = key_run->ReadObj();
70 TDirectory* tdir_run =
dynamic_cast<TDirectory*
>(obj_run);
72 std::string tdir_run_name(tdir_run->GetName());
73 if (tdir_run_name.find(
"run") != std::string::npos) {
74 run_dir = std::move(tdir_run_name);
75 out_EOS =
"root://eosatlas.cern.ch//eos/atlas/atlascerngroupdisk/perf-idtracking/VertexMonitoring/VxMon_" +
76 run_dir +
"_" + AthenaTAG +
".root";
77 out_LOCAL =
"VxMon_" + run_dir +
"_" + AthenaTAG +
".root";
79 lb_keys = tdir_run->GetListOfKeys();
80 while ((key_lb =
dynamic_cast<TKey*
>(lb_keys())) != 0) {
81 TObject* obj_lb = key_lb->ReadObj();
82 TDirectory* tdir_lb =
dynamic_cast<TDirectory*
>(obj_lb);
84 std::string tdir_lb_name(tdir_lb->GetName());
85 if (tdir_lb_name.find(
"lb") != std::string::npos) {
86 lb_dir = std::move(tdir_lb_name);
88 dirExists = f->GetDirectory((run_dir +
"/" + lb_dir +
"/InDetGlobal/PrimaryVertexMultiplicity").c_str());
90 out_inStem = run_dir +
"/" + lb_dir +
"/InDetGlobal/PrimaryVertexMultiplicity/nVx";
91 out_outStem =
"nVx_" + lb_dir;
93 writeEOS =
updateHists(inFilename, out_inStem, out_EOS, out_outStem);
94 if (writeEOS != 0 && IsFirstTime) writeLOCAL =
updateHists(inFilename, out_inStem, out_LOCAL,
97 writeLOCAL =
updateHists(inFilename, out_inStem, out_LOCAL, out_outStem);
100 if (writeEOS != 0 && !IsFirstTime && writeLOCAL != 0) {
105 if (writeEOS != 0 && writeLOCAL != 0) {
118 if (writeEOS != 0 && writeLOCAL == 0) {
119 int return_code = system(
120 (
"xrdcp VxMon_" + run_dir +
"_" + AthenaTAG +
".root root://eosatlas.cern.ch//eos/atlas/atlascerngroupdisk/perf-idtracking/VertexMonitoring/VxMon_" + run_dir +
"_" + AthenaTAG +
122 if (return_code == 0) std::ignore = remove(out_LOCAL.c_str());
143 int updateHists(
const std::string& inFileName,
const std::string& inStem,
const std::string& fileName,
144 const std::string& stem) {
145 std::string outFileName = fileName;
146 std::string outStem = stem;
148 TFile* source = TFile::Open(inFileName.c_str());
156 std::string path = inStem;
159 if (inStem[inStem.size() - 1] !=
'/') {
160 std::string::size_type lastSlash = inStem.find_last_of(
'/');
161 hist = inStem.substr(lastSlash + 1, inStem.size() - lastSlash - 1);
162 path = inStem.substr(0, lastSlash + 1);
163 isDir = (source->FindObjectAny(hist.c_str()))->InheritsFrom(
"TDirectory");
170 if (path[path.size() - 1] ==
'/') path.resize(path.size() - 1);
171 if (!source->GetDirectory(path.c_str())) {
178 if (outFileName.empty()) {
179 outFileName = std::string(inFileName, 0, inFileName.find(
".root"));
180 outFileName +=
"_trimmed.root";
183 TFile* target = TFile::Open(outFileName.c_str(),
"update");
189 if (outStem.empty()) outStem = inStem;
190 std::string targetPath = outStem;
191 std::string targetHist;
193 std::string::size_type lastSlash = outStem.find_last_of(
'/');
194 targetPath = outStem.substr(0, lastSlash + 1);
195 targetHist = outStem.substr(lastSlash + 1, outStem.size() - lastSlash - 1);
198 if (targetPath[targetPath.size() - 1] ==
'/') targetPath.resize(targetPath.size() - 1);
206 if (!target->IsWritable())
return 1;
208 Copy(source, target, path, targetPath, hist, targetHist);
218 if (!dirName.empty()) {
219 std::string::size_type firstSlash = dirName.find(
'/');
220 if (firstSlash == std::string::npos) {
223 std::string subdir(dirName, 0, firstSlash);
224 if (!subdir.empty()) success &=
makeDir(subdir);
226 std::string newSubdir(dirName, firstSlash + 1, dirName.size() - firstSlash);
247 void Copy(TFile* source, TFile* target,
const std::string& inDir,
const std::string& outDir,
248 const std::string& inHist,
const std::string& outHist) {
251 if (!inHist.empty()) {
252 CopyHist(source, target, inDir, outDir, inHist, outHist);
254 TDirectory* sourceDir = source->GetDirectory(inDir.c_str());
255 TDirectory* targetDir = target->GetDirectory(outDir.c_str());
257 TIter nextKey(sourceDir->GetListOfKeys());
260 while ((key = (TKey*) nextKey())) {
261 std::string keyName = key->GetName();
262 std::string className(key->GetClassName());
264 if (className ==
"TDirectoryFile") {
265 std::string newInDir = inDir;
269 std::string newOutDir = outDir;
271 newOutDir += keyName;
273 if (!targetDir->FindKey(keyName.c_str())) {
278 targetDir->mkdir(keyName.c_str());
284 Copy(source, target, newInDir, newOutDir);
286 CopyHist(source, target, inDir, outDir, keyName, keyName);
294 void CopyHist(TFile* source, TFile* target,
const std::string& inDir,
const std::string& outDir,
295 const std::string& inHist,
const std::string& outHist) {
296 TDirectory* sourceDir = source->GetDirectory(inDir.c_str());
297 TDirectory* targetDir = target->GetDirectory(outDir.c_str());
300 TKey* key = sourceDir->FindKey(inHist.c_str());
301 TObject*
object = key->ReadObj();
302 bool permission =
true;
304 if (targetDir->FindKey(outHist.c_str())) permission =
false;
305 if (permission)
object->Write(outHist.c_str(), TObject::kOverwrite);
void Copy(TFile *source, TFile *target, const std::string &inDir, const std::string &outDir, const std::string &inHist="", const std::string &outHist="")