48 ClassImp(RooStudyManager);
55 RooStudyManager::RooStudyManager(RooWorkspace& w)
57 _pkg =
new RooStudyPackage(w) ;
64 RooStudyManager::RooStudyManager(RooWorkspace& w, RooAbsStudy& study)
66 _pkg =
new RooStudyPackage(w) ;
67 _pkg->addStudy(study) ;
73 RooStudyManager::RooStudyManager(
const char* studyPackFileName)
75 string pwd = gDirectory->GetName() ;
76 TFile *f =
new TFile(studyPackFileName) ;
77 _pkg =
dynamic_cast<RooStudyPackage*
>(f->Get(
"studypack")) ;
78 gDirectory->cd(Form(
"%s:",pwd.c_str())) ;
85 void RooStudyManager::addStudy(RooAbsStudy& study)
87 _pkg->addStudy(study) ;
95 void RooStudyManager::run(Int_t nExperiments)
97 _pkg->driver(nExperiments) ;
105 void RooStudyManager::runProof(Int_t nExperiments,
const char* proofHost, Bool_t showGui)
107 coutP(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") opening PROOF session" << endl ;
108 void* p = (
void*) gROOT->ProcessLineFast(Form(
"TProof::Open(\"%s\")",proofHost)) ;
112 coutE(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") ERROR initializing proof, aborting" << endl ;
118 gROOT->ProcessLineFast(Form(
"((TProof*)0x%lx)->SetProgressDialog(0) ;",(ULong_t)p)) ;
122 coutP(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") sending work package to PROOF servers" << endl ;
123 gROOT->ProcessLineFast(Form(
"((TProof*)0x%lx)->AddInput((TObject*)0x%lx) ;",(ULong_t)p,(ULong_t)_pkg) ) ;
126 coutP(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") starting PROOF processing of " << nExperiments <<
" experiments" << endl ;
128 gROOT->ProcessLineFast(Form(
"((TProof*)0x%lx)->Process(\"RooProofDriverSelector\",%d) ;",(ULong_t)p,nExperiments)) ;
131 coutP(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") aggregating results data" << endl ;
132 TList* olist = (TList*) gROOT->ProcessLineFast(Form(
"((TProof*)0x%lx)->GetOutputList()",(ULong_t)p)) ;
133 aggregateData(olist) ;
136 coutP(Generation) <<
"RooStudyManager::runProof(" << GetName() <<
") cleaning up input list" << endl ;
137 gROOT->ProcessLineFast(Form(
"((TProof*)0x%lx)->GetInputList()->Remove((TObject*)0x%lx) ;",(ULong_t)p,(ULong_t)_pkg) ) ;
149 void RooStudyManager::closeProof(Option_t *option)
151 if (gROOT->GetListOfProofs()->LastIndex() != -1 && gROOT->ProcessLineFast(
"gProof;"))
153 gROOT->ProcessLineFast(Form(
"gProof->Close(\"%s\") ;",option)) ;
154 gROOT->ProcessLineFast(
"gProof->CloseProgressDialog() ;") ;
158 if (gROOT->GetListOfProofs()->LastIndex() != -1 && gROOT->ProcessLineFast(
"gProof;")) {
159 gROOT->ProcessLineFast(
"delete gProof ;") ;
162 ooccoutI((TObject*)NULL,Generation) <<
"RooStudyManager: No global Proof objects. No connections closed." << endl ;
170 void RooStudyManager::prepareBatchInput(
const char* studyName, Int_t nExpPerJob, Bool_t unifiedInput=kFALSE)
172 TFile f(Form(
"study_data_%s.root",studyName),
"RECREATE") ;
173 _pkg->Write(
"studypack") ;
179 ofstream bdr(Form(
"study_driver_%s.sh",studyName)) ;
180 bdr <<
"#!/bin/sh" << endl
181 << Form(
"if [ ! -f study_data_%s.root ] ; then",studyName) << endl
182 <<
"uudecode <<EOR" << endl ;
186 gSystem->Exec(Form(
"cat study_data_%s.root | uuencode -m study_data_%s.root >> study_driver_%s.sh",studyName,studyName,studyName)) ;
189 ofstream bdr2 (Form(
"study_driver_%s.sh",studyName),ios::app) ;
190 bdr2 <<
"EOR" << endl
192 <<
"root -l -b <<EOR" << endl
193 << Form(
"RooStudyPackage::processFile(\"%s\",%d) ;",studyName,nExpPerJob) << endl
197 gSystem->Unlink(Form(
"study_data_%s.root",studyName)) ;
199 coutI(DataHandling) <<
"RooStudyManager::prepareBatchInput batch driver file is '" << Form(
"study_driver_%s.sh",studyName) <<
"," << endl
200 <<
" input data files is embedded in driver script" << endl ;
204 ofstream bdr(Form(
"study_driver_%s.sh",studyName)) ;
205 bdr <<
"#!/bin/sh" << endl
206 <<
"root -l -b <<EOR" << endl
207 << Form(
"RooStudyPackage::processFile(\"%s\",%d) ;",studyName,nExpPerJob) << endl
211 coutI(DataHandling) <<
"RooStudyManager::prepareBatchInput batch driver file is '" << Form(
"study_driver_%s.sh",studyName) <<
"," << endl
212 <<
" input data file is " << Form(
"study_data_%s.root",studyName) << endl ;
222 void RooStudyManager::processBatchOutput(
const char* filePat)
225 expandWildCardSpec(filePat,flist) ;
229 for (list<string>::iterator iter = flist.begin() ; iter!=flist.end() ; ++iter) {
230 coutP(DataHandling) <<
"RooStudyManager::processBatchOutput() now reading file " << *iter << endl ;
231 TFile f(iter->c_str()) ;
233 TList* list = f.GetListOfKeys() ;
234 TIterator* kiter = list->MakeIterator();
238 while((key=(TKey*)kiter->Next())) {
239 obj = f.Get(key->GetName()) ;
240 TObject* clone = obj->Clone(obj->GetName()) ;
245 aggregateData(&olist) ;
252 void RooStudyManager::aggregateData(TList* olist)
254 for (list<RooAbsStudy*>::iterator iter=_pkg->studies().begin() ; iter!=_pkg->studies().end() ; ++iter) {
255 (*iter)->aggregateSummaryOutput(olist) ;
265 void RooStudyManager::expandWildCardSpec(
const char* name, list<string>& result)
267 if (!TString(name).MaybeWildcard()) {
268 result.push_back(name) ;
273 TString basename(name);
275 Int_t dotslashpos = -1;
277 Int_t next_dot = basename.Index(
".root");
279 dotslashpos = next_dot;
280 next_dot = basename.Index(
".root",dotslashpos+1);
282 if (basename[dotslashpos+5]!=
'/') {
289 TString behind_dot_root;
290 if (dotslashpos>=0) {
292 behind_dot_root = basename(dotslashpos+6,basename.Length()-dotslashpos+6);
294 basename.Remove(dotslashpos+5);
297 Int_t slashpos = basename.Last(
'/');
300 directory = basename(0,slashpos);
301 basename.Remove(0,slashpos+1);
303 directory = gSystem->UnixPathName(gSystem->WorkingDirectory());
307 void *dir = gSystem->OpenDirectory(gSystem->ExpandPathName(directory.Data()));
312 TRegexp re(basename,kTRUE);
313 while ((file = gSystem->GetDirEntry(dir))) {
314 if (!strcmp(file,
".") || !strcmp(file,
".."))
continue;
316 if ( (basename!=file) && s.Index(re) == kNPOS)
continue;
317 l.Add(
new TObjString(file));
319 gSystem->FreeDirectory(dir);
324 while ((obj = (TObjString*)next())) {
325 file = obj->GetName();
326 if (behind_dot_root.Length() != 0)
327 result.push_back(Form(
"%s/%s/%s",directory.Data(),file,behind_dot_root.Data())) ;
329 result.push_back(Form(
"%s/%s",directory.Data(),file)) ;