]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muondep/AliMuonGridSubmitter.cxx
Adding -lssl
[u/mrichter/AliRoot.git] / PWG / muondep / AliMuonGridSubmitter.cxx
CommitLineData
81190958 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//
17// AliMuonGridSubmitter : a class to help submit jobs for several runs
18//
19// This class is dealing with 3 different directories :
20//
21// - template directory ($ALICE_ROOT/PWG/muondep/XXXTemplates) containing the
22// basic template files to be used for a particular job type (XXX). A template can contain
23// some variables that will be replaced during during the copy from template
24// to local dir
25//
26// - local directory, where the files from the template directory, are copied
27// once the class has been configured properly (i.e. using the various Set, Use,
28// etc... methods). Some other files (e.g. JDL ones) are generated from
29// scratch and also copied into this directory.
30// At this point one could(should) check the files, as they are the ones
31// to be copied to the remote directory for the production
32//
33// - remote directory, the alien directory where the files will be copied
34// (from the local directory) before the actual submission
35//
36// author: Laurent Aphecetche (Subatech
37//
38
39#include "AliMuonGridSubmitter.h"
40
41#include "AliLog.h"
42#include "TFile.h"
43#include "TGrid.h"
44#include "TGridResult.h"
45#include "TMap.h"
46#include "TMath.h"
47#include "TObjString.h"
48#include "TROOT.h"
49#include "TString.h"
50#include "TSystem.h"
51#include <vector>
52#include "AliAnalysisTriggerScalers.h"
53#include "Riostream.h"
54
55//______________________________________________________________________________
eb5de7ee 56AliMuonGridSubmitter::AliMuonGridSubmitter(AliMuonGridSubmitter::EJobType jobType, Bool_t localOnly)
81190958 57: TObject(),
58fInternalMap(0x0),
59fVars(0x0),
60fIsValid(kFALSE),
61fShouldOverwriteFiles(kFALSE),
62fTemplateFileList(0x0),
d484adc1 63fLocalFileList(0x0),
64fRunList()
81190958 65{
66 // ctor
67
eb5de7ee 68 if (!gGrid && !localOnly)
81190958 69 {
70 TGrid::Connect("alien://");
71 if ( !gGrid )
72 {
73 AliError("cannot connect to grid");
74 }
75 }
76
77 SetPackages("VO_ALICE@AliRoot::v5-04-46-AN","VO_ALICE@GEANT3::v1-15","VO_ALICE@ROOT::v5-34-05");
78
79 TString basedir = gSystem->ExpandPathName("$ALICE_ROOT/PWG/muondep");
80
81 TString dir;
82 dir.Form("%s/%sTemplates",basedir.Data(),JobTypeName(jobType).Data());
83
84 if (!SetTemplateDir(dir.Data()))
85 {
86 AliError(Form("Could not find %s directory. Please check.",dir.Data()));
87 }
88
89 SetLocalDir(gSystem->pwd());
90}
91
92//______________________________________________________________________________
93AliMuonGridSubmitter::~AliMuonGridSubmitter()
94{
95 // dtor
96 delete fTemplateFileList;
97 delete fLocalFileList;
98 delete fInternalMap;
99 delete fVars;
100}
101
102//______________________________________________________________________________
103void AliMuonGridSubmitter::AddToTemplateFileList(const char* filename)
104{
105 // add a file to the list of templates
106 // and update the local file list if needed
107
108 TObjArray* a = TemplateFileList();
109
110 if ( !a->FindObject(filename) )
111 {
112 a->Add(new TObjString(filename));
113 UpdateLocalFileList();
114 }
115}
116
eb5de7ee 117//______________________________________________________________________________
118void AliMuonGridSubmitter::AddToLocalFileList(const char* filename)
119{
120 // add a file to the list of local files
121
122 TObjArray* a = LocalFileList();
123
124 if ( !a->FindObject(filename) )
125 {
126 a->Add(new TObjString(filename));
127 }
128}
129
81190958 130//______________________________________________________________________________
131Bool_t AliMuonGridSubmitter::CheckCompilation(const char* file) const
132{
133 /// Check whether file can be compiled or not
134 /// FIXME: use gSystem->TempFileName for tmpfile !
135
136 Bool_t rv(kTRUE);
137
138 TString sfile(gSystem->BaseName(file));
139 TString tmpfile(Form("tmpfile_%s",sfile.Data()));
140
141 gSystem->Exec(Form("cp %s %s",file,tmpfile.Data()));
142
143 ReplaceVars(tmpfile.Data());
144
145 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
146 gSystem->AddIncludePath("-I$ALICE_ROOT/EVGEN");
147
148 if (gROOT->LoadMacro(Form("%s++",tmpfile.Data())))
149 {
150 AliError(Form("macro %s can not be compiled. Please check.",file));
151 rv = kFALSE;
152 }
153
154 gSystem->Exec(Form("rm %s",tmpfile.Data()));
155
156 return rv;
157}
158
159
160//______________________________________________________________________________
161Bool_t AliMuonGridSubmitter::CheckLocal() const
162{
163 /// Check whether all required local files are there
164 TIter next(LocalFileList());
165 TObjString* file;
166
167 while ( ( file = static_cast<TObjString*>(next())) )
168 {
169 if ( gSystem->AccessPathName(file->String().Data()) )
170 {
171 return kFALSE;
172 }
173 }
174
175 return kTRUE;
176}
177
178//______________________________________________________________________________
179Bool_t AliMuonGridSubmitter::CheckRemote() const
180{
181 /// Check whether all required remote files are there
182 AliWarning("implement me");
183 return kFALSE;
184}
185
186//______________________________________________________________________________
187void AliMuonGridSubmitter::CleanLocal(const char* excludeList) const
188{
189 /// Clean (remove) local generated files
190 /// exclude contains a list of comma separated pattern of files
191 /// to be avoided
192
193 TIter next(LocalFileList());
194 TObjString* file;
195 TObjArray* excludeArray = TString(excludeList).Tokenize(",");
196
197 while ( ( file = static_cast<TObjString*>(next())) )
198 {
199 Bool_t shouldExclude(kFALSE);
200
201 TIter nextExclude(excludeArray);
202 TObjString* s;
203
204 while ( ( s = static_cast<TObjString*>(nextExclude())) && !shouldExclude )
205 {
206 if ( file->String().Contains(s->String()) ) shouldExclude=kTRUE;
207 }
208
209 if (!shouldExclude)
210 {
211 gSystem->Unlink(file->String().Data());
212 }
213 }
214
215 delete excludeArray;
216}
217
218//______________________________________________________________________________
219Bool_t AliMuonGridSubmitter::CopyFile(const char* localFile)
220{
221 /// copy a local file to remote destination
222 TString local;
223
224 if ( gSystem->IsAbsoluteFileName(localFile) )
225 {
226 local = localFile;
227 }
228 else
229 {
230 local = Form("%s/%s",LocalDir().Data(),gSystem->ExpandPathName(localFile));
231 }
232
233 if (gSystem->AccessPathName(local.Data()))
234 {
235 AliErrorClass(Form("Local file %s does not exist",local.Data()));
236 return kFALSE;
237 }
238
239 TString remote;
240
241 remote += RemoteDir().Data();
242 remote += "/";
243
244 if ( gSystem->IsAbsoluteFileName(localFile) )
245 {
246 TString tmp(localFile);
247 tmp.ReplaceAll(GetMapValue("Snapshot"),"");
248 tmp.ReplaceAll(GetMapValue("Local"),"");
249 remote += tmp;
250 }
251 else
252 {
253 remote += localFile;
254 }
255
256 TString dirName = gSystem->DirName(remote.Data());
257
258 Bool_t ok(kTRUE);
259
260 if (!RemoteDirectoryExists(dirName.Data()))
261 {
262 ok = gGrid->Mkdir(dirName.Data(),"-p");
263 }
264
265 if ( ok )
266 {
267 AliDebugClass(1,Form("cp %s alien://%s",local.Data(),remote.Data()));
268 return TFile::Cp(local.Data(),Form("alien://%s",remote.Data()));
269 }
270 else
271 {
272 return kFALSE;
273 }
274}
275
276//______________________________________________________________________________
277Bool_t AliMuonGridSubmitter::CheckRemoteDir() const
278{
279 /// Check we have a grid connection and that the remote dir exists
280
281 if (RemoteDir().IsNull())
282 {
283 AliError("you must provide the grid location where to copy the files");
284 return kFALSE;
285 }
286
287 if (!RemoteDirectoryExists(RemoteDir()))
288 {
289 AliError(Form("directory %s does not exist", RemoteDir().Data()));
290 return kFALSE;
291 }
292
293 return kTRUE;
294}
295
296//______________________________________________________________________________
297Bool_t AliMuonGridSubmitter::CopyLocalFilesToRemote()
298{
299 /// copy all files necessary to run the simulation into remote directory
300
301 TIter next(LocalFileList());
302 TObjString* ftc;
303
304 Bool_t allok(kTRUE);
305
306 while ( ( ftc = static_cast<TObjString*>(next())) )
307 {
308 allok = allok && CopyFile(ftc->String());
309 }
310 return allok;
311}
312
313//______________________________________________________________________________
314Bool_t AliMuonGridSubmitter::CopyTemplateFilesToLocal()
315{
316 // copy (or generate) local files from the template ones
317
318 if (!IsValid()) return kFALSE;
319
320 AliDebug(1,"");
321
322 TIter next(TemplateFileList());
323 TObjString* file;
324
325 Int_t err(0);
326 Bool_t potentialProblem(kFALSE);
327
328 while ( ( file = static_cast<TObjString*>(next())) )
329 {
330 if ( file->String().Contains("OCDB") )
331 {
332 /// OCDB snapshots are not in template
333 continue;
334 }
335
336 if ( !ShouldOverwriteFiles() && !gSystem->AccessPathName(file->String().Data()) )
337 {
338 AliError(Form("Local file %s already exists. Remove it first if you want to update overwrite it",file->String().Data()));
339 potentialProblem = kTRUE;
340 }
341 else
342 {
343 TString stemplate(Form("%s/%s",TemplateDir().Data(),file->String().Data()));
344 TString slocal(Form("%s/%s",LocalDir().Data(),file->String().Data()));
345
346 Int_t c = gSystem->CopyFile(stemplate.Data(),slocal.Data(),ShouldOverwriteFiles());
347 if ( c )
348 {
349 Bool_t ok(kFALSE);
350 if ( stemplate.Contains(".jdl",TString::kIgnoreCase) )
351 {
352 ok = Generate(file->String().Data());
353 }
354 if (!ok)
355 {
356 AliError(Form("Error %d copying file %s",c,stemplate.Data()));
357 }
358 else
359 {
360 c=0;
361 }
362 }
363 else
364 {
365 if ( HasVars(slocal.Data()) )
366 {
367 if (!ReplaceVars(slocal.Data()))
368 {
369 AliError("pb in ReplaceVars");
370 c=1;
371 }
372 }
373 }
374 err += c;
375 }
376 }
377
378 if ( potentialProblem )
379 {
380 AliWarning("At least one local file could not be overwritten. Cross-check that the local files are OK before we try to upload them to the Grid !");
381 return kFALSE;
382 }
383 return (err==0);
384}
385
386//______________________________________________________________________________
387std::ostream* AliMuonGridSubmitter::CreateJDLFile(const char* name) const
388{
389 /// Create a (local and empty) JDL file
390
391 AliDebugClass(1,"");
392
393 TString jdl(Form("%s/%s",LocalDir().Data(),name));
394
395 if ( !ShouldOverwriteFiles() && !gSystem->AccessPathName(jdl.Data()) )
396 {
397 AliErrorClass(Form("File %s already exists. Remove it if you want to overwrite it",jdl.Data()));
398 return 0x0;
399 }
400
401 std::ofstream* os = new std::ofstream(gSystem->ExpandPathName(jdl.Data()));
402
403 if (os->bad())
404 {
405 AliErrorClass(Form("Cannot create file %s",jdl.Data()));
406 delete os;
407 os=0x0;
408 }
409
410 return os;
411}
412
413//______________________________________________________________________________
414Int_t AliMuonGridSubmitter::GetLastStage(const char* remoteDir)
415{
416 /// Get the last staging phase already performed
417
418 TGridResult* r = gGrid->Ls(remoteDir);
419 Int_t i(0);
420 Int_t lastStage(0);
421 Int_t offset = TString("Stage_").Length();
422
423 while ( r->GetFileName(i) )
424 {
425 TString file(r->GetFileName(i));
426 if (file.BeginsWith("Stage_") && !file.Contains("xml") )
427 {
428 Int_t n = TString(file(offset,file.Length()-offset)).Atoi();
429 lastStage = TMath::Max(lastStage,n);
430 }
431 ++i;
432 }
433 delete r;
434 return lastStage;
435}
436
437//______________________________________________________________________________
438TString AliMuonGridSubmitter::GetMapValue(const char* key) const
439{
440 // convenience method to access internal map of TObjStrings
441 if (!fInternalMap) return "";
442
443 TObject* o = fInternalMap->GetValue(key);
444
445 if (o)
446 {
447 return static_cast<TObjString*>(o)->String();
448 }
449
450 return "";
451}
452
453//______________________________________________________________________________
454TObjArray* AliMuonGridSubmitter::GetVariables(const char* file) const
455{
456 /// Find the variables in the file
457
458 std::ifstream in(file);
459 char line[1024];
460 TObjArray* variables(0x0);
461
462 while ( in.getline(line,1023,'\n') )
463 {
464 TString sline(line);
465 while (sline.Contains("VAR_") && !sline.BeginsWith("//") )
466 {
467 Int_t i1 = sline.Index("VAR_");
468 Int_t i2(i1);
469
470 while ( ( i2 < sline.Length() ) && ( isalnum(sline[i2]) || sline[i2]=='_' ) ) ++i2;
471
472 if (!variables)
473 {
474 variables = new TObjArray;
475 variables->SetOwner(kTRUE);
476 }
477
478 TString var = sline(i1,i2-i1);
479 if ( !variables->FindObject(var) )
480 {
481 variables->Add(new TObjString(var));
482 }
483 sline.ReplaceAll(var,"");
484 }
485 }
486
487 in.close();
488
489 return variables;
490}
491
492//______________________________________________________________________________
493Bool_t AliMuonGridSubmitter::HasVars(const char* file) const
494{
495 /// Whether or not the file contains variables that have to
496 /// be substituted
497
498 std::ifstream in(file);
499 char line[1024];
500 while ( in.getline(line,1023,'\n') )
501 {
502 TString sline(line);
503 if (sline.Contains("VAR_") && !sline.BeginsWith("//") )
504 {
505 return kTRUE;
506 }
507 }
508 return kFALSE;
509}
510
511//______________________________________________________________________________
512TMap* AliMuonGridSubmitter::InternalMap() const
513{
514 if (!fInternalMap)
515 {
516 fInternalMap = new TMap;
517 fInternalMap->SetOwnerKeyValue(kTRUE,kTRUE);
518 }
519 return fInternalMap;
520}
521
522//______________________________________________________________________________
523TString AliMuonGridSubmitter::JobTypeName(AliMuonGridSubmitter::EJobType jobType) const
524{
525 if ( jobType == kAccEff )
526 {
527 return "AccEff";
528 }
529 else if ( jobType == kQAMerge)
530 {
531 return "QAMerge";
532 }
533 return "unknown";
534}
535
536//______________________________________________________________________________
537TObjArray* AliMuonGridSubmitter::LocalFileList() const
538{
539 /// Return (after createing and filling it if needed)
540 /// the internal file list with paths from the local directory
541
542 if (!fLocalFileList)
543 {
544 fLocalFileList = static_cast<TObjArray*>(TemplateFileList()->Clone());
545 }
546
547 return fLocalFileList;
548}
549
550//______________________________________________________________________________
551UInt_t AliMuonGridSubmitter::NofRuns() const
552{
553 // number of runs we're dealing with
554 return fRunList.size();
555}
556
557//______________________________________________________________________________
558void AliMuonGridSubmitter::OutputToJDL(std::ostream& out, const char* key,
559 const TObjArray& values) const
560{
561 /// output to ostream of key,{values} pair
562
563 out << key << " = ";
564
565 Int_t n = values.GetEntries();
566
567 if ( n > 1 )
568 {
569 out << "{" << std::endl;
570 TIter next(&values);
571 TObjString* v;
572
573 while ( ( v = static_cast<TObjString*>(next())) )
574 {
575 --n;
576 out << "\t\"" << v->String().Data() << "\"";
577 if ( n ) out << ",";
578 out << std::endl;
579 }
580 out << "}";
581 }
582 else
583 {
584 TString& v1 = static_cast<TObjString*>(values.At(0))->String();
585
586 if ( v1.IsDigit() && !(TString(key).Contains("SplitMax")) && !(TString(key).Contains("TTL")) )
587 {
588 out << v1.Atoi();
589 }
590 else
591 {
592 out << "\"" << v1.Data() << "\"";
593 }
594 }
595 out << ";" << std::endl;
596}
597
598//______________________________________________________________________________
599void AliMuonGridSubmitter::OutputToJDL(std::ostream& out, const char* key, const char* v1,
600 const char* v2, const char* v3, const char* v4,
601 const char* v5, const char* v6, const char* v7,
602 const char* v8, const char* v9) const
603{
604 /// output to ostream
605
606 TObjArray values;
607 values.SetOwner(kTRUE);
608
609 values.Add(new TObjString(v1));
610 if ( strlen(v2) > 0 ) values.Add(new TObjString(v2));
611 if ( strlen(v3) > 0 ) values.Add(new TObjString(v3));
612 if ( strlen(v4) > 0 ) values.Add(new TObjString(v4));
613 if ( strlen(v5) > 0 ) values.Add(new TObjString(v5));
614 if ( strlen(v6) > 0 ) values.Add(new TObjString(v6));
615 if ( strlen(v7) > 0 ) values.Add(new TObjString(v7));
616 if ( strlen(v8) > 0 ) values.Add(new TObjString(v8));
617 if ( strlen(v9) > 0 ) values.Add(new TObjString(v9));
618
619 OutputToJDL(out,key,values);
620}
621
622
623//______________________________________________________________________________
624void AliMuonGridSubmitter::Print(Option_t* /*opt*/) const
625{
626 /// Printout
627
628 if (!IsValid())
629 {
630 std::cout << std::string(80,'*') << std::endl;
631 std::cout << "INVALID OBJECT. CHECK BELOW THE CONFIGURATION." << std::endl;
632 std::cout << std::string(80,'*') << std::endl;
633 }
634
635 TIter next(fInternalMap);
636 TObjString* key;
637
638 while ( ( key = static_cast<TObjString*>(next()) ) )
639 {
640 TString value = static_cast<TObjString*>(fInternalMap->GetValue(key->String()))->String();
641
642 std::cout << key->String() << " : " << value.Data() << std::endl;
643 }
644
645 if ( NofRuns() )
646 {
647 std::cout << NofRuns() << " run";
648 if ( NofRuns() > 1 ) std::cout << "s";
649 std::cout << " = ";
650 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
651 {
652 std::cout << fRunList[i] << " ";
653 }
654 }
655
656 TIter nextVar(fVars);
657 while ( ( key = static_cast<TObjString*>(nextVar())) )
658 {
659 TObjString* value = static_cast<TObjString*>(fVars->GetValue(key->String()));
660 std::cout << "Variable " << key->String() << " will be replaced by " << value->String() << std::endl;
661 }
662
663 std::cout << "Files to be uploaded:" << std::endl;
664 TIter nextFile(LocalFileList());
665 TObjString* sfile;
666 while ( ( sfile = static_cast<TObjString*>(nextFile())) )
667 {
668 std::cout << sfile->String().Data() << std::endl;
669 }
670}
671
672
673//______________________________________________________________________________
674Bool_t AliMuonGridSubmitter::RemoteDirectoryExists(const char *dirname) const
675{
676 // Returns true if directory exists. Can be also a path.
677 if (!gGrid) return kFALSE;
678 // Check if dirname is a path
679 TString dirstripped = dirname;
680 dirstripped = dirstripped.Strip();
681 dirstripped = dirstripped.Strip(TString::kTrailing, '/');
682 TString dir = gSystem->BaseName(dirstripped);
683 dir += "/";
684 TString path = gSystem->DirName(dirstripped);
685 TGridResult *res = gGrid->Ls(path, "-F");
686 if (!res) return kFALSE;
687 TIter next(res);
688 TMap *map;
689 TObject *obj;
690 while ((map=dynamic_cast<TMap*>(next()))) {
691 obj = map->GetValue("name");
692 if (!obj) break;
693 if (dir == obj->GetName()) {
694 delete res;
695 return kTRUE;
696 }
697 }
698 delete res;
699 return kFALSE;
700}
701
702//______________________________________________________________________________
703Bool_t AliMuonGridSubmitter::RemoteFileExists(const char *lfn)
704{
705 // Returns true if file exists.
706 if (!gGrid) return kFALSE;
707 TGridResult *res = gGrid->Ls(lfn);
708 if (!res) return kFALSE;
709 TMap *map = dynamic_cast<TMap*>(res->At(0));
710 if (!map) {
711 delete res;
712 return kFALSE;
713 }
714 TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name"));
715 if (!objs || !objs->GetString().Length()) {
716 delete res;
717 return kFALSE;
718 }
719 delete res;
720 return kTRUE;
721}
722
723//______________________________________________________________________________
724Bool_t AliMuonGridSubmitter::ReplaceVars(const char* file) const
725{
726 /// Replace the variables (i.e. things starting by VAR_) found in file
727
728 std::ifstream in(file);
729 char line[1024];
730 TObjArray lines;
731 lines.SetOwner(kTRUE);
732 Int_t nvars(0);
733 Int_t nreplaced(0);
734
735 TIter next(fVars);
736
737 while ( in.getline(line,1023,'\n') )
738 {
739 TString sline(line);
740 while (sline.Contains("VAR_") && !sline.BeginsWith("//") )
741 {
742 ++nvars;
743 TObjString* key;
744 next.Reset();
745 while ( ( key = static_cast<TObjString*>(next())) )
746 {
747 if ( sline.Contains(key->String()) )
748 {
749 ++nreplaced;
750 TObjString* value = static_cast<TObjString*>(fVars->GetValue(key->String()));
751 sline.ReplaceAll(key->String(),value->String());
752 break;
753 }
754 }
755 }
756
757 lines.Add(new TObjString(sline));
758 }
759
760 in.close();
761
762 if ( nvars > 0 )
763 {
764 if ( nreplaced != nvars )
765 {
766 AliError(Form("nvars=%d nreplaced=%d",nvars,nreplaced));
767 return kFALSE;
768 }
769 std::ofstream out(file);
770 TIter nextLine(&lines);
771 TObjString* s;
772 while ( ( s = static_cast<TObjString*>(nextLine()) ) )
773 {
774 out << s->String().Data() << std::endl;
775 }
776 out.close();
777 }
778
779 return kTRUE;
780}
781
782//______________________________________________________________________________
783const std::vector<int>& AliMuonGridSubmitter::RunList() const
784{
785 /// Return a reference to our runlist
786 return fRunList;
787}
788
789//______________________________________________________________________________
790void AliMuonGridSubmitter::SetPackages(const char* aliroot,
791 const char* root,
792 const char* geant3,
793 const char* api)
794{
795 /// Set the packages to be used by the jobs
796 /// Must be a valid combination, see http://alimonitor.cern.ch/packages/
797 ///
798
799 SetMapKeyValue("AliRoot",aliroot);
800 SetMapKeyValue("Root",root);
801 SetMapKeyValue("Geant3",geant3);
802 SetMapKeyValue("API",api);
803}
804
805//______________________________________________________________________________
806TString AliMuonGridSubmitter::GetRemoteDir(const char* dir, Bool_t create)
807{
808 /// Set the target remote directory (on the grid)
809
810 if (!RemoteDirectoryExists(dir))
811 {
812 if (!create)
813 {
814 AliErrorClass(Form("Remote directory %s does not exist", dir));
815 return "";
816 }
817 else
818 {
819 AliInfoClass(Form("Remote directory %s does not exist. Trying to create it...",dir));
820 if (!gGrid)
821 {
822 AliErrorClass("cannot connect to grid");
823 return "";
824 }
825 if ( !gGrid->Mkdir(dir,"-p") )
826 {
827 AliErrorClass(Form("Could not create remote dir. Sorry."));
828 return "";
829 }
830 }
831 }
832 return dir;
833}
834
835//______________________________________________________________________________
836Bool_t AliMuonGridSubmitter::SetLocalDirectory(const char* type, const char* path)
837{
838 if (gSystem->AccessPathName(path)==kFALSE)
839 {
840 SetMapKeyValue(type,path);
841 return kTRUE;
842 }
843 return kFALSE;
844}
845
846//______________________________________________________________________________
847void AliMuonGridSubmitter::SetMapKeyValue(const char* key, const char* value)
848{
849 TObjString skey(key);
850 InternalMap()->Remove(&skey);
851 InternalMap()->Add(new TObjString(key),new TObjString(value));
852}
853
854//______________________________________________________________________________
855Bool_t AliMuonGridSubmitter::SetRemoteDirectory(const char* type, const char* path)
856{
857 // Set the merged directory to be used
858 TString v = GetRemoteDir(path,kTRUE);
859 SetMapKeyValue(type,v);
860 return (v.Length()>0);
861}
862
863//______________________________________________________________________________
864void AliMuonGridSubmitter::SetRunList(const char* runlist)
865{
866 // set the runlist from a text file
867 AliAnalysisTriggerScalers ts(runlist);
868 fRunList = ts.GetRunList();
869}
870
871//______________________________________________________________________________
872void AliMuonGridSubmitter::SetRunList(int runNumber)
873{
874 // set the runlist from a text file
875 fRunList.clear();
876 fRunList.push_back(runNumber);
877}
878
879//______________________________________________________________________________
880Bool_t AliMuonGridSubmitter::SetVar(const char* varname, const char* value)
881{
882 /// Set a variable
883
884 TString s(varname);
885 s.ToUpper();
886 if (!s.BeginsWith("VAR_"))
887 {
888 AliError("Variable name should start with VAR_");
889 return kFALSE;
890 }
891 if (!fVars)
892 {
893 fVars = new TMap;
894 fVars->SetOwnerKeyValue(kTRUE,kTRUE);
895 }
896
897 TObject* o = new TObjString(s);
898 fVars->Remove(o);
899
900 fVars->Add(o,new TObjString(value));
901
902 return kTRUE;
903}
904
905//______________________________________________________________________________
906TObjArray* AliMuonGridSubmitter::TemplateFileList() const
907{
908 /// Return (after createing if needed)
909
910 if (!fTemplateFileList)
911 {
912 fTemplateFileList = new TObjArray;
913 fTemplateFileList->SetOwner(kTRUE);
914 }
915 return fTemplateFileList;
916}
917
918//______________________________________________________________________________
919void AliMuonGridSubmitter::UpdateLocalFileList()
920{
921 // insure that local file list contains at least all of the template files
922 TIter next(TemplateFileList());
923 TObjString* s;
924
925 while ( ( s = static_cast<TObjString*>(next())) )
926 {
eb5de7ee 927 AddToLocalFileList(s->String().Data());
81190958 928 }
929}
930
931//______________________________________________________________________________
932TMap* AliMuonGridSubmitter::Vars() const
933{
934 if (!fVars)
935 {
936 fVars = new TMap;
937 fVars->SetOwnerKeyValue(kTRUE,kTRUE);
938 }
939 return fVars;
940}
941