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