ATLAS Offline Software
Loading...
Searching...
No Matches
SampleLocal.cxx File Reference
#include <SampleHandler/SampleLocal.h>
#include <RootCoreUtils/Assert.h>
#include <TSystem.h>
Include dependency graph for SampleLocal.cxx:

Go to the source code of this file.

Functions

 ClassImp (SH::SampleLocal) namespace SH

Function Documentation

◆ ClassImp()

ClassImp ( SH::SampleLocal )
Author
Nils Krumnack

Definition at line 20 of file SampleLocal.cxx.

23{
24 void SampleLocal ::
25 testInvariant () const
26 {
27 for (const auto& file : m_files)
28 {
29 RCU_INVARIANT (!file.empty());
30 RCU_INVARIANT (file[0]==0 || file.find (":/") != std::string::npos);
31 }
32 }
33
34
35
36 SampleLocal ::
37 SampleLocal ()
38 : Sample ("unnamed")
39 {
40 RCU_NEW_INVARIANT (this);
41 }
42
43
44
45 SampleLocal ::
46 SampleLocal (const std::string& name)
47 : Sample (name)
48 {
49 RCU_NEW_INVARIANT (this);
50 }
51
52
53
54 void SampleLocal ::
55 add (const std::string& file)
56 {
58 RCU_REQUIRE_SOFT (!file.empty());
59
60 std::string myfile = file;
61 if (myfile.find (":/") == std::string::npos)
62 {
63 if (myfile[0] != '/')
64 myfile = gSystem->WorkingDirectory() + ("/" + myfile);
65 myfile = "file://" + myfile;
66 }
67 m_files.push_back (myfile);
68 }
69
70
71
72 std::size_t SampleLocal ::
73 getNumFiles () const
74 {
75 RCU_READ_INVARIANT (this);
76 return m_files.size();
77 }
78
79
80
81 std::string SampleLocal ::
82 getFileName (const std::size_t index) const
83 {
84 RCU_READ_INVARIANT (this);
85
86 RCU_INVARIANT (index < m_files.size());
87 return m_files[index];
88 }
89
90
91
92 std::unique_ptr<SampleLocal> SampleLocal ::
93 doMakeLocal () const
94 {
95 RCU_READ_INVARIANT (this);
96 return std::make_unique<SampleLocal>(*this);
97 }
98
99
100
101 std::vector<std::string> SampleLocal ::
102 doMakeFileList () const
103 {
104 RCU_READ_INVARIANT (this);
105
106 std::vector<std::string> result;
107 for (const auto& file : m_files)
108 result.push_back (file);
109 return result;
110 }
111
112
113
114 void SampleLocal ::
115 doUpdateLocation (const std::string& from, const std::string& to)
116 {
118 for (auto& file : m_files)
119 {
120 // rationale: only replace the prefix on a path boundary (so that
121 // "/a/b" does not also match "/a/bc") and join without
122 // inserting a duplicate '/'.
123 if (file.starts_with (from) &&
124 (file.size() == from.size() || file[from.size()] == '/'))
125 {
126 std::string rest = file.substr (from.size());
127 if (!rest.empty() && rest.front() == '/')
128 rest.erase (0, 1);
129 file = rest.empty() ? to : to + "/" + rest;
130 }
131 }
132 }
133}
#define RCU_INVARIANT(x)
Definition Assert.h:187
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:141
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
CONT to(RANGE &&r)
Definition ranges.h:39
Definition index.py:1
TFile * file