22 :
FileListSource(LocationsForSAMQuery(query, stride, offset), 1, 0)
34 const char*
user = getenv(
"GRID_USER");
37 TString dset = TString::Format(
"%s_cafana_%s", user, query.c_str());
39 dset.ReplaceAll(
" ",
"_");
40 dset.ReplaceAll(
"(",
"_OPEN_");
41 dset.ReplaceAll(
")",
"_CLOSE_");
42 dset.ReplaceAll(
":",
"_COLON_");
43 dset.ReplaceAll(
"'",
"_SQUOTE_");
44 dset.ReplaceAll(
"\"",
"_DQUOTE_");
46 std::cout <<
"Creating dataset " << dset <<
" for query " << query << std::endl;
50 system(TString::Format(
"samweb -e %s list-definitions --defname %s | grep %s || samweb -e %s create-definition %s %s",
56 query.c_str()).
Data());
64 const char*
user = getenv(
"GRID_USER");
66 const char*
cluster = getenv(
"CLUSTER");
68 const char* process = getenv(
"PROCESS");
74 const std::string snap = TString::Format(
"%s_cafana_snap_%s_%s",
82 const std::string snaplock = TString::Format(
"%s_cafana_snap_lock_%s_%s",
90 std::cout <<
"Checking lock " << snaplock << std::endl;
91 if(system(TString::Format(
"samweb -e %s create-definition %s file_name %s",
94 process).
Data()) == 0){
96 std::cout <<
"Snapshotting " << def <<
" as " << snap << std::endl;
97 system(TString::Format(
"samweb -e %s take-snapshot %s | xargs samweb -e %s create-definition %s snapshot_id",
101 snap.c_str()).
Data());
106 while(system(TString::Format(
"samweb -e %s list-definitions --defname %s | grep %s",
109 snap.c_str()).
Data()) != 0){
113 std::cout <<
"We've been waiting a real long time for " << snap <<
" to be created. I don't think it's happening." << std::endl;
118 std::cout <<
"Will use " << snap << std::endl;
130 if(getenv(
"IFDH_BASE_URI"))
return getenv(
"IFDH_BASE_URI");
148 if(!query.Contains(
' ')){
149 if(getenv(
"CAFANA_USE_SNAPSHOTS")){
150 query =
"dataset_def_name_newest_snapshot "+query;
156 query =
"defname: "+query;
161 query += TString::Format(
" with stride %d", stride).Data();
163 query += TString::Format(
" offset %d", offset).Data();
168 std::cout <<
"Looking up files matching '" << query <<
"' using SAM...\n";
170 std::vector<std::string> files;
175 files = i.translateConstraints(query.Data());
177 catch(ifdh_util_ns::WebAPIException&
e){
183 std::cerr <<
"\nCan't find any files matching '" << str
184 <<
"'. Aborting..." << std::endl;
190 if(!files.empty() && files.back().empty()){
201 std::vector<std::string> ret;
204 std::map<std::string, std::vector<std::string>> locmap;
206 Progress prog(TString::Format(
"Looking up locations of %ld files using SAM", fnames.size()).
Data());
215 const unsigned int kStep = 50;
216 for(
unsigned int fIdx = 0; fIdx < fnames.size(); fIdx += kStep){
217 prog.SetProgress(
double(fIdx)/fnames.size());
221 const std::vector<std::string> fslice(fnames.begin()+fIdx, fIdx+kStep < fnames.size() ? fnames.begin()+fIdx+kStep : fnames.end());
223 const auto locslice = i.locateFiles(fslice);
225 locmap.insert(locslice.begin(), locslice.end());
233 for(
auto it: locmap){
234 const std::string& f = it.first;
235 const std::vector<std::string>& locs = it.second;
239 std::string resolved;
240 for(TString
loc: locs){
247 if(std::getenv(
"NOVA_ANA" ))
loc.ReplaceAll(
"/nova/ana", std::getenv(
"NOVA_ANA"));
248 if(std::getenv(
"NOVA_APP" ))
loc.ReplaceAll(
"/nova/app", std::getenv(
"NOVA_APP"));
249 if(std::getenv(
"NOVA_DATA"))
loc.ReplaceAll(
"/nova/data", std::getenv(
"NOVA_DATA"));
250 if(std::getenv(
"NOVA_PROD"))
loc.ReplaceAll(
"/nova/prod", std::getenv(
"NOVA_PROD"));
255 if(
stat((resolved+
'/'+f).c_str(), &junk) == 0){
261 if(
loc.BeginsWith(
"dcache:") && best < 2){
268 loc.ReplaceAll(
"dcache:/pnfs/",
"/pnfs/");
270 if(
loc.First(
'(') >= 0)
loc.Resize(
loc.First(
'('));
274 if(
loc.BeginsWith(
"enstore:") && best < 1){
277 loc.ReplaceAll(
"enstore:/pnfs/",
"/pnfs/");
278 if(
loc.First(
'(') >= 0)
loc.Resize(
loc.First(
'('));
284 if(best == 0 || resolved.empty()){
285 std::cerr <<
"\nCouldn't find a usable location for " << f
286 <<
"'. Aborting..." << std::endl;
290 ret.push_back((resolved+
'/'+f));
std::string IFDHBaseURI() const
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
BEGIN_PROLOG could also be cerr
process_name opflashCryoW ana
std::string EnsureDataset(const std::string &query) const
std::vector< std::string > LocationsForSAMQuery(const std::string &str, int stride, int offset)
SAMQuerySource(const std::string &query, int stride=-1, int offset=-1)
std::string EnsureSnapshot(const std::string &def) const
Simple file source based on an explicit list provided by the user.
std::vector< std::string > LocateSAMFiles(const std::vector< std::string > &fnames)
Take filenames, return locations suitable for TFile::Open()
virtual ~SAMQuerySource()
std::string SAMExperiment()
$SAM_EXPERIMENT or a nice error message and abort
A simple ascii-art progress bar.
BEGIN_PROLOG could also be cout