FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairRuntimeDb.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 //*-- AUTHOR : Ilse Koenig
9 //*-- Created : 20/10/2004
10 
12 // FairRuntimeDb
13 //
14 // Administration class for parameter input/output
16 #include "FairRuntimeDb.h"
17 
18 #include "FairContFact.h" // for FairContFact
19 #include "FairDetParAsciiFileIo.h" // for FairDetParAsciiFileIo
20 #include "FairDetParRootFileIo.h" // for FairDetParRootFileIo
21 //#include "FairDetParTSQLIo.h" // for FairDetParTSQLIo
22 #include "FairGenericParAsciiFileIo.h" // for FairGenericParAsciiFileIo
23 #include "FairGenericParRootFileIo.h" // for FairGenericParRootFileIo
24 //#include "FairGenericParTSQLIo.h" // for FairGenericParTSQLIo
25 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
26 #include "FairParAsciiFileIo.h" // for FairParAsciiFileIo
27 #include "FairParIo.h" // for FairParIo
28 #include "FairParRootFileIo.h" // for FairParRootFileIo
29 #include "FairParSet.h" // for FairParSet
30 #include "FairRtdbRun.h" // for FairRtdbRun, FairParVersion
31 
32 #include <TClass.h> // for TClass
33 #include <TCollection.h> // for TIter
34 #include <TFile.h> // for TFile, gFile
35 #include <cstdio> // for sprintf
36 #include <cstring> // for strcmp, strlen
37 #include <iomanip> // for setw, operator<<
38 #include <iostream> // for operator<<, basic_ostream, etc
39 
40 class FairDetParIo;
41 
42 using std::cout;
43 using std::endl;
44 using std::ios;
45 using std::setw;
46 
48 // 0 = use original code; 1 = use new code
49 #define USE_DB_METHOD 1
50 
53 
54 FairRuntimeDb* FairRuntimeDb::gRtdb = 0;
55 
57 {
58  // Singleton instance
59  if (gRtdb == 0) {
60  gRtdb = new FairRuntimeDb;
61  }
62  return gRtdb;
63 }
64 
66  : TObject()
67  , containerList(new TList())
68  , runs(new TList())
69  , firstInput(nullptr)
70  , secondInput(nullptr)
71  , output(nullptr)
72  , currentRun(nullptr)
73  , currentFileName("")
74  , versionsChanged(kFALSE)
75  , isRootFileOutput(kFALSE)
76  , fLogger(FairLogger::GetLogger())
77  , ioType(UNKNOWN_Type)
78 {
79  gRtdb = this;
80 }
81 
83 {
84  // destructor
85  // deletes the list of runs and all containers
88  closeOutput();
89  if (containerList) {
90  TIter next(containerList);
91  FairParSet* cont;
92  while ((cont = static_cast<FairParSet*>(next()))) {
93  Text_t* name = const_cast<char*>(cont->GetName());
94  if (!cont->isOwned()) {
95  removeContainer(name);
96  }
97  }
98  delete containerList;
99  }
100  if (runs) {
101  runs->Delete();
102  delete runs;
103  }
104  gRtdb = 0;
105 }
106 
108 {
109  // Adds a container factory to the list of factories
110  if (!(contFactories.FindObject(fact->GetName()))) {
111  LOG(debug) << "- RTDB container factory " << fact->GetName() << "\n";
112  contFactories.Add(fact);
113  }
114 }
115 
117 {
118  // removes a container factory to the list of factories
119  if ((contFactories.Remove(fact))) {
120  LOG(debug) << "removed RTDB container factory " << fact->GetName();
121  }
122 }
123 
125 {
126  return (static_cast<FairContFact*>(contFactories.FindObject(FactName)));
127 }
128 
129 Bool_t FairRuntimeDb::addParamContext(const char* context)
130 {
131  // Sets via the container factories the context of all parameter containers,
132  // which accept this context
133  Bool_t found = kFALSE;
134  TIter next(&contFactories);
135  FairContFact* fact;
136  while ((fact = static_cast<FairContFact*>(next()))) {
137  if (fact->addContext(context)) {
138  found = kTRUE;
139  }
140  }
141  Error("addParamContext(const char*)", "Unknown context");
142  return found;
143 }
144 
146 {
147  // Prints the context of all parameter containers, which can be created by
148  // the container factories
149  TIter next(&contFactories);
150  FairContFact* fact;
151  while ((fact = static_cast<FairContFact*>(next()))) {
152  fact->print();
153  }
154 }
155 
157 {
158 
159  // adds a container to the list of containers
160  // cout << "-I- name parset # " << container->GetName()<< endl;
161  Text_t* name = const_cast<char*>(container->GetName());
162 
163  if (!containerList->FindObject(name)) {
164  containerList->Add(container);
165  TIter next(runs);
166  FairRtdbRun* run;
167  FairParVersion* vers;
168  while ((run = static_cast<FairRtdbRun*>(next()))) {
169  if (!run->getParVersion(name)) {
170  vers = new FairParVersion(name);
171  run->addParVersion(vers);
172  }
173  }
174  // cout << "-I- RTDB entries in list# " << containerList->GetEntries() <<"\n" ;
175 
176  return kTRUE;
177  }
178 
179  Warning("addContainer(FairParSet*)", "Container %s already exists!", name);
180  return kFALSE;
181 }
182 
184 {
185  // The function loops over the container factories to find the corresponding container
186  // with the give name and its context.
187  // The name is the original name of the parameter container without the concatination
188  // with the context.
189  // The factory checks, if the container exists already in the runtime database. Otherwise
190  // it will be created and added by the factory.
191  // The function returns a pointer to the container or nullptr, if not created.
192  TIter next(&contFactories);
193  FairContFact* fact;
194  FairParSet* c = 0;
195  while (!c && (fact = static_cast<FairContFact*>(next()))) {
196  c = fact->getContainer(name);
197  }
198  if (!c) {
199  Error("getContainer(Text_t*)", "Container %s not created!", name);
200  }
201  return c;
202 }
203 
205 {
206  // returns a pointer to the container called by name
207  // The name is the original name of the parameter container eventually concatinated with
208  // a non-default context.
209  return static_cast<FairParSet*>((containerList->FindObject(name)));
210 }
211 
213 {
214  // removes the container from the list and deletes it
215  TObject* c = containerList->FindObject(name);
216  if (c) {
217  containerList->Remove(c);
218  delete c;
219  }
220 }
221 
223 {
224  // removes all containers from the list and deletes them
225  containerList->Delete();
226 }
227 
228 FairRtdbRun* FairRuntimeDb::addRun(Int_t runId, Int_t refId)
229 {
230  // adds a run at the end of the list of runs
231  // returns a pointer to the run newly added
232  FairRtdbRun* run;
233  if (refId != -1) {
234  run = getRun(refId);
235  if (!run) {
236  addRun(refId);
237  }
238  }
239  run = getRun(runId);
240  if (!run) {
241  run = new FairRtdbRun(runId, refId);
242  TIter next(containerList);
243  FairParSet* cont;
244  FairParVersion* vers;
245  while ((cont = static_cast<FairParSet*>(next()))) {
246  vers = new FairParVersion((const_cast<char*>(cont->GetName())));
247  run->addParVersion(vers);
248  }
249  runs->Add(run);
250  currentRun = run;
251  } else {
252  Warning("addRun(Int_t,Int_t)", "Run already exists");
253  }
254  return run;
255 }
256 
258 {
259  // returns a pointer to the run called by the run id
260  char name[255];
261  sprintf(name, "%i", id);
262  return static_cast<FairRtdbRun*>((runs->FindObject(name)));
263 }
264 
266 {
267  // returns a pointer to the run called by name
268  return static_cast<FairRtdbRun*>((runs->FindObject(name)));
269 }
270 
271 void FairRuntimeDb::removeRun(Text_t* name)
272 {
273  // removes the run from the list and deletes it
274  TObject* c = runs->FindObject(name);
275  if (c) {
276  runs->Remove(c);
277  delete c;
278  if (c == currentRun) {
279  currentRun = 0;
280  }
281  }
282 }
283 
284 void FairRuntimeDb::clearRunList() { runs->Delete(); }
285 
287 {
288  // writes the parameter versions for all runs to the output
289  if (getOutput() && output->check()) {
291  output->cd();
292  if (gFile->IsWritable()) {
293  runs->Write();
294  }
295  versionsChanged = kFALSE;
296  }
297  }
298 }
299 
301 {
302  // writes all containers to the output
303  // loops over the list of containers and calls for each the
304  // function writeContainer(...)
305  TIter next(containerList);
306  FairParSet* cont;
307  Bool_t rc = kTRUE;
308  FairRtdbRun* refRun = 0;
309  if (currentRun) {
310  const char* refRunName = currentRun->getRefRun();
311  if (strlen(refRunName) > 0) {
312  refRun = static_cast<FairRtdbRun*>((runs->FindObject(refRunName)));
313  }
314  while ((cont = static_cast<FairParSet*>(next()))) {
315  rc = writeContainer(cont, currentRun, refRun) && rc;
316  }
317  }
318  if (!rc) {
319  Error("writeContainers()", "Error in write of containers to output");
320  }
321  return rc;
322 }
323 
325 {
326  Int_t in1 = cont->getInputVersion(1);
327  Int_t in2 = cont->getInputVersion(2);
328  FairRtdbRun* run;
329  FairParVersion* vers;
330  const Text_t* name = cont->GetName();
331  Int_t v = 0;
332  if (in1 == -1 && in2 == -1) {
333  if (cont->hasChanged()) {
334  return 0;
335  } else {
336  Int_t i = runs->IndexOf(currentRun); // FIXME: This can be optimized with a backwards iter.
337  while (i >= 0) {
338  run = static_cast<FairRtdbRun*>(runs->At(i));
339  vers = run->getParVersion(name);
340  if (vers->getInputVersion(1) == in1 && vers->getInputVersion(2) == in2) {
341  if ((v = vers->getRootVersion()) != 0) {
342  return v;
343  }
344  }
345  --i;
346  }
347  return 0;
348  }
349  }
350  if ((firstInput == output) && (in1 > 0 && in2 == -1)) {
351  return in1;
352  }
353  TIter next(runs);
354  // v=0;
355  while ((run = static_cast<FairRtdbRun*>(next()))) {
356  vers = run->getParVersion(name);
357  if (vers->getInputVersion(1) == in1 && vers->getInputVersion(2) == in2) {
358  if ((v = vers->getRootVersion()) != 0) {
359  return v;
360  }
361  }
362  }
363  return 0;
364 }
365 
367 #if (USE_DB_METHOD == 0)
369 {
370  // writes a container to the output if the containers has changed
371  // The output might be suppressed if the changes is due an initialisation from a
372  // ROOT file which serves also as output or if it was already written
373  const Text_t* c = cont->GetName();
374  LOG(debug) << "RuntimeDb: write container: " << cont->GetName();
375  FairParVersion* vers = run->getParVersion(c);
376  Bool_t rc = kTRUE;
377  Int_t cv = 0;
378  if (getOutput() && output->check() && output->isAutoWritable()) {
379  cout << " CHECK OUTPUT DONE " << endl;
380  if (isRootFileOutput) {
381  if (cont->hasChanged()) {
382  cv = findOutputVersion(cont);
383  if (cv == 0) {
384  cv = cont->write(output);
385  if (cv > 0) {
386  LOG(info) << "*** " << c << " written to ROOT file version: " << cv;
387  } else if (cv == -1) {
388  return kFALSE;
389  }
390  // -1 indicates and error during write
391  // 0 is allowed for all containers which have no write function
392  }
393  vers->setRootVersion(cv);
394  } else {
395  if (vers->getRootVersion() == 0) {
396  cv = findOutputVersion(cont);
397  vers->setRootVersion(cv);
398  }
399  }
400  } else { // might be Ascii I/O
401  if (cont->hasChanged()) {
402  cv = cont->write(output);
403  if (cv < 0) {
404  return kFALSE;
405  }
406  cout << "*** " << c << " written to output" << '\n';
407  vers->setRootVersion(cv);
408  }
409  }
410  }
411  vers->setInputVersion(cont->getInputVersion(1), 1);
412  vers->setInputVersion(cont->getInputVersion(2), 2);
413  cont->setChanged(kFALSE);
414  if (refRun) {
415  FairParVersion* refVers = refRun->getParVersion(c);
416  if (refVers) {
417  refVers->setInputVersion(cont->getInputVersion(1), 1);
418  refVers->setInputVersion(cont->getInputVersion(2), 2);
419  refVers->setRootVersion(cv);
420  }
421  }
422  return rc;
423 }
424 #endif
425 
427 #if (USE_DB_METHOD > 0)
429 {
430  // std::cout << "\n -I FairRuntimeDB Using DB mode \n";
431  // writes a container to the output if the containers has changed
432  // The output might be suppressed if the changes is due an initialisation from a
433  // ROOT file which serves also as output or if it was already written
434  const Text_t* c = cont->GetName();
435  LOG(debug) << "RuntimeDb: write container: " << cont->GetName();
436  FairParVersion* vers = run->getParVersion(c);
437  Bool_t rc = kTRUE;
438  Int_t cv = 0;
439  if (getOutput() && output->check() && output->isAutoWritable()) {
440  switch (ioType) {
441  case RootFileOutput: // RootFile
442  if (cont->hasChanged()) {
443  cv = findOutputVersion(cont);
444  if (cv == 0) {
445  cv = cont->write(output);
446  if (cv > 0) {
447  LOG(info) << "*** " << c << " written to ROOT file version: " << cv;
448  } else if (cv == -1) {
449  return kFALSE;
450  }
451  // -1 indicates and error during write
452  // 0 is allowed for all containers which have no write function
453  }
454  vers->setRootVersion(cv);
455  } else {
456  if (vers->getRootVersion() == 0) {
457  cv = findOutputVersion(cont);
458  vers->setRootVersion(cv);
459  }
460  }
461  break; // End of rootfile IO
462  case RootTSQLOutput: // TSQL
463  if (cont->hasChanged()) {
464  cv = findOutputVersion(cont);
465  if (cv == 0) {
466  // std::cout << "-I- FairRuntimeDB: SQL write() called 1 = "<< cont->GetName() << "\n";
467  cont->print();
468  /*Int_t test = */
469  cont->write(output);
470  // std::cout << "-I- FairRuntimeDB: SQL write() called 2 = \n";
471  }
472  }
473  break; // End of TSQL IO
474  case AsciiFileOutput: // might be Ascii I/O
475  if (cont->hasChanged()) {
476  cv = cont->write(output);
477  if (cv < 0) {
478  return kFALSE;
479  }
480  cout << "*** " << c << " written to output" << '\n';
481  vers->setRootVersion(cv);
482  }
483  break; // End of Ascii IO
484  default: // Unknown IO
485  Error("writeContainer()", "Unknown output file type.");
486  break;
487  }
488  }
489  vers->setInputVersion(cont->getInputVersion(1), 1);
490  vers->setInputVersion(cont->getInputVersion(2), 2);
491  cont->setChanged(kFALSE);
492  if (refRun) {
493  FairParVersion* refVers = refRun->getParVersion(c);
494  if (refVers) {
495  refVers->setInputVersion(cont->getInputVersion(1), 1);
496  refVers->setInputVersion(cont->getInputVersion(2), 2);
497  refVers->setRootVersion(cv);
498  }
499  }
500  return rc;
501 }
502 #endif
503 
505 Bool_t FairRuntimeDb::initContainers(Int_t runId, Int_t refId, const Text_t* fileName)
506 {
507  // loops over the list of containers and calls the init() function of each
508  // container if it is not static
509  // (typically called by Hades::eventLoop(...))
510  if (currentRun && currentRun->getRunId() != runId) {
511  writeContainers();
512  }
513  FairRtdbRun* run = getRun(runId);
514  if (!run) {
515  run = addRun(runId, refId);
516  } else {
517  run->setRefRun(refId);
518  if (refId != -1 && !getRun(refId)) {
519  addRun(refId);
520  }
521  }
522  currentRun = run;
523  currentFileName = fileName;
524  return initContainers();
525 }
526 
528 {
529  // reads all containers with all versions for all runs and writes the
530  // containers, the setup information and the version table to the output
531  if (!(getOutput() && output->check())) {
532  cout << "***********************************************************" << endl;
533  cout << "********************* W A R N I N G *********************" << endl;
534  cout << "********************* no output ! *********************" << endl;
535  cout << "***********************************************************" << endl;
536  }
537  currentRun = 0;
538  Bool_t rc = kTRUE;
539  TIter next(runs);
540  while ((currentRun = static_cast<FairRtdbRun*>(next())) != 0) {
541  rc = initContainers() && rc;
542  writeContainers();
543  }
544  saveOutput();
545  currentRun = 0;
546  return kTRUE;
547 }
548 
549 Bool_t FairRuntimeDb::initContainers(void)
550 {
551  // private function
552  Text_t* refRunName = const_cast<char*>(currentRun->getRefRun());
553  Int_t len = strlen(refRunName);
554  if (len < 1) {
555  if (firstInput) {
557  }
558  if (secondInput) {
560  }
561  } else {
562  FairRtdbRun* refRun = getRun(refRunName);
563  if (firstInput) {
564  firstInput->readVersions(refRun);
565  }
566  if (secondInput) {
567  secondInput->readVersions(refRun);
568  }
569  }
570  TIter next(containerList);
571  FairParSet* cont;
572  Bool_t rc = kTRUE;
573  cout << '\n' << "************************************************************* " << '\n';
574  if (currentFileName.IsNull()) {
575  cout << " initialisation for run id " << currentRun->GetName();
576  } else {
577  cout << " initialisation for event file " << currentFileName.Data() << '\n';
578  cout << " run id " << currentRun->GetName();
579  }
580  if (len > 0) {
581  cout << " --> " << refRunName;
582  }
583  cout << '\n' << "************************************************************* " << '\n';
584  while ((cont = static_cast<FairParSet*>(next()))) {
585  cout << "-I- FairRunTimeDB::InitContainer() " << cont->GetName() << endl;
586  if (!cont->isStatic()) {
587  rc = cont->init() && rc;
588  }
589  }
590  if (!rc) {
591  Error("initContainers()", "Error occured during initialization");
592  }
593  return rc;
594 }
595 
597 {
598  // sets the status flag in all containers
599  // flag kTRUE sets all 'static'
600  // flag kFALSE sets all 'not static'
601  TIter next(containerList);
602  FairParSet* cont;
603  while ((cont = static_cast<FairParSet*>(next()))) {
604  cont->setStatic(flag);
605  }
606 }
607 
608 Bool_t FairRuntimeDb::setInputVersion(Int_t run, Text_t* container, Int_t version, Int_t inp)
609 {
610  // sets the input version of a container defined by its name and a
611  // run defined by its id taken from input with inputNumber inp
612  // (1 for first input and 2 for second input)
613  FairRtdbRun* r = getRun(run);
614  if (r) {
615  FairParVersion* v = r->getParVersion(container);
616  if (v) {
617  v->setInputVersion(version, inp);
618  return kTRUE;
619  } else {
620  Error("setInputVersion", "Container not found");
621  }
622  } else {
623  Error("setInputVersion", "Run not found");
624  }
625  return kFALSE;
626 }
627 
628 Bool_t FairRuntimeDb::setRootOutputVersion(Int_t run, Text_t* container, Int_t version)
629 {
630  // sets the Root file output version of a container defined by its name
631  // and a run defined by its id
632  // should only be used after initialization 'by hand' on the interpreter level
633  FairRtdbRun* r = getRun(run);
634  if (r) {
635  FairParVersion* v = r->getParVersion(container);
636  if (v) {
637  v->setRootVersion(version);
638  return kTRUE;
639  } else {
640  Error("setRootOutputVersion", "Container not found");
641  }
642  } else {
643  Error("setRootOutputVersion", "Run not found");
644  }
645  return kFALSE;
646 }
647 
649 {
650  // prints the list of the actual containers, the list of the
651  // runs/versions and information about input/output
652  cout << "--------------------------------------------------------------------------------\n";
653  cout << "-------------- actual containers in runtime database -------------------------\n";
654  TIter nextCont(containerList);
655  FairParSet* cont;
656  cout.setf(ios::left, ios::adjustfield);
657  while ((cont = static_cast<FairParSet*>(nextCont()))) {
658  cout << setw(45) << cont->GetName() << " " << cont->GetTitle() << '\n';
659  }
660  TIter next(runs);
661  FairRtdbRun* run;
662  cout << "-------------- runs, versions ------------------------------------------------\n";
663  cout << "run id\n";
664  cout << " " << setw(45) << "container";
665  cout.setf(ios::right, ios::adjustfield);
666  cout << setw(11) << "1st-inp" << setw(11) << " 2nd-inp" << setw(11) << " output\n";
667  while ((run = static_cast<FairRtdbRun*>(next()))) {
668  run->print();
669  }
670  cout << "-------------- input/output --------------------------------------------------\n";
671  if (firstInput) {
672  cout << "first Input:\n";
673  firstInput->print();
674  } else {
675  cout << "first input: none" << '\n';
676  }
677  if (secondInput) {
678  cout << "second Input:\n";
679  secondInput->print();
680  } else {
681  cout << "second input: none" << '\n';
682  }
683  if (output) {
684  cout << "output:\n";
685  output->print();
686  } else {
687  cout << "output: none" << '\n';
688  }
689 }
690 
692 {
693  // resets all input versions in the list of runs and in all containers which are not static
694  // is called each time a new input is set
695  TIter nextRun(runs);
696  FairRtdbRun* run;
697  while ((run = static_cast<FairRtdbRun*>(nextRun()))) {
698  run->resetInputVersions();
699  }
700  TIter nextCont(containerList);
701  FairParSet* cont;
702  while ((cont = static_cast<FairParSet*>(nextCont()))) {
703  if (!cont->isStatic()) {
704  cont->resetInputVersions();
705  }
706  }
707 }
708 
710 {
711  // resets all output versions in the list of runs
712  // is called each time a new output is set
713  // is called also each time a new input is set which is not identical with the output
714  TIter next(runs);
715  FairRtdbRun* run;
716  while ((run = static_cast<FairRtdbRun*>(next()))) {
717  run->resetOutputVersions();
718  }
719 }
720 
722 {
723  // resets all input and output versions in the list of runs
724  // and in all containers which are not static
727 }
728 
730 {
731  // sets the first input pointer
732  firstInput = inp1;
733  if (inp1->check() == kTRUE) {
734  inp1->setInputNumber(1);
736  if (output && firstInput != output) {
738  }
739  return kTRUE;
740  } else {
741  Error("setFirstInput(FairParIo*)", "no connection to input");
742  }
743  return kFALSE;
744 }
745 
747 {
748  // sets the second input pointer
749  secondInput = inp2;
750  if (inp2->check() == kTRUE) {
751  inp2->setInputNumber(2);
753  if (output && firstInput != output) {
755  }
756  return kTRUE;
757  } else {
758  Error("setSecondInput(FairParIo*)", "no connection to input");
759  }
760  return kFALSE;
761 }
763 #if (USE_DB_METHOD == 0)
765 {
766  // sets the output pointer
767  output = op;
768  if (output->check() == kTRUE) {
770  if (strcmp(output->IsA()->GetName(), "FairParRootFileIo") == 0) {
771  isRootFileOutput = kTRUE;
772  }
773  return kTRUE;
774  } else {
775  Error("setOutput(FairParIo*)", "no connection to output");
776  }
777  return kFALSE;
778 }
779 #endif
780 #if (USE_DB_METHOD > 0)
783 {
784  // sets the output pointer
785  output = op;
786  if (output->check() == kTRUE) {
788  if (strcmp(output->IsA()->GetName(), "FairParRootFileIo") == 0) {
790  isRootFileOutput = kTRUE;
791  } else if (strcmp(output->IsA()->GetName(), "FairParTSQLIo") == 0) {
793  } else { // ASCII
795  }
796  return kTRUE;
797  } else {
798  Error("setOutput(FairParIo*)", "no connection to output");
799  }
800  return kFALSE;
801 }
802 #endif
805 {
806  // return a pointer to the first input
807  if (firstInput) {
808  firstInput->cd();
809  }
810  return firstInput;
811 }
812 
814 {
815  // return a pointer to the second input
816  if (secondInput) {
817  secondInput->cd();
818  }
819  return secondInput;
820 }
821 
823 {
824  // return a pointer to the output
825  if (output) {
826  output->cd();
827  }
828  return output;
829 }
830 
832 {
833  if (firstInput) {
834  firstInput->cd();
835  firstInput->close();
836  firstInput = 0;
837  }
838 }
839 
841 {
842  if (secondInput) {
843  secondInput->cd();
844  secondInput->close();
845  secondInput = 0;
846  }
847 }
848 
850 {
851  // writes the versions and the containers (if not yet written out)
852  // without the version information the containers cannot be read from a ROOT file!
853  Bool_t rc = kTRUE;
854  if (currentRun != 0) {
855  rc = writeContainers();
856  }
857  writeVersions();
858  if (!rc) {
859  Error("saveOutput()", "Error occured during write");
860  }
861 }
862 
864 {
865  // calls saveOutput() and deletes then the output
866  if (output) {
867  if (output->isAutoWritable()) {
868  saveOutput();
869  }
870  output->close();
872  output = 0;
873  isRootFileOutput = kFALSE;
874  }
875 }
876 
878 {
879  // activates the detector I/O
880  const char* ioName = io->IsA()->GetName();
881  FairDetParIo* po = io->getDetParIo("FairGenericParIo");
882  if (!po) {
883  if (strcmp(ioName, "FairParRootFileIo") == 0) {
885  new FairGenericParRootFileIo((static_cast<FairParRootFileIo*>(io))->getParRootFile());
886  io->setDetParIo(pn);
887  } else if (strcmp(ioName, "FairParAsciiFileIo") == 0) {
889  new FairGenericParAsciiFileIo((static_cast<FairParAsciiFileIo*>(io))->getFile());
890  io->setDetParIo(pn);
891  }
892  // else if(strcmp(ioName,"FairParTSQLIo") == 0) {
893  // std::cout << "\n\n\n\t TSQL versie is called en nu de rest \n\n";
894  // FairDetParTSQLIo* pn = new FairGenericParTSQLIo();
895  // io->setDetParIo(pn);
896  //}
897  }
898  TIter next(&contFactories);
899  FairContFact* fact;
900  while ((fact = static_cast<FairContFact*>(next()))) {
901  fact->activateParIo(io);
902  }
903 }
Bool_t isStatic()
Definition: FairParSet.h:67
FairRtdbRun * getRun(Int_t)
void setInputNumber(Int_t)
Definition: FairParIo.cxx:61
list of container factories
Definition: FairRuntimeDb.h:24
virtual const char * GetName() const
Definition: FairParSet.h:38
void resetOutputVersions()
void activateParIo(FairParIo *)
FairRtdbRun * currentRun
Definition: FairRuntimeDb.h:36
void addParVersion(FairParVersion *pv)
void removeAllContainers(void)
Bool_t setInputVersion(Int_t run, Text_t *container, Int_t version, Int_t inputNumber)
void setStatic(Bool_t flag=kTRUE)
Definition: FairParSet.h:66
Bool_t writeContainer(FairParSet *, FairRtdbRun *, FairRtdbRun *refRun=0)
TList * containerList
Definition: FairRuntimeDb.h:31
FairParIo * secondInput
Definition: FairRuntimeDb.h:34
virtual Int_t write()
Definition: FairParSet.cxx:80
TString currentFileName
Definition: FairRuntimeDb.h:37
void writeVersions(void)
static FairRuntimeDb * instance(void)
FairParVersion * getParVersion(const Text_t *name)
FairParSet * getContainer(const char *)
void closeSecondInput(void)
void resetInputVersions()
void setChanged(Bool_t flag=kTRUE)
Definition: FairParSet.h:72
const Text_t * getRefRun()
Definition: FairRtdbRun.h:74
virtual void print()
Definition: FairParSet.cxx:94
FairParSet * findContainer(const char *)
virtual const char * GetTitle() const
Definition: FairParSet.h:39
Bool_t setSecondInput(FairParIo *)
void clearRunList(void)
ClassImp(FairEventBuilder)
void print(void)
void resetAllVersions(void)
void setInputVersion(Int_t v=-1, Int_t i=0)
Definition: FairRtdbRun.h:33
Int_t getInputVersion(Int_t i)
Definition: FairParSet.h:57
void setRefRun(Text_t *s)
Definition: FairRtdbRun.h:75
Int_t findOutputVersion(FairParSet *)
Bool_t isAutoWritable()
Definition: FairParIo.h:58
FairParIo * output
Definition: FairRuntimeDb.h:35
void setContainersStatic(Bool_t f=kTRUE)
FairParSet * getContainer(const Text_t *)
virtual Bool_t init()
Definition: FairParSet.cxx:46
Bool_t writeContainers(void)
Bool_t initContainers(Int_t runId, Int_t refId=-1, const Text_t *fileName="")
void removeRun(Text_t *)
Int_t getInputVersion(Int_t i)
Definition: FairRtdbRun.h:39
void closeOutput(void)
virtual void activateParIo(FairParIo *)
Definition: FairContFact.h:57
void setRootVersion(Int_t v)
Definition: FairRtdbRun.h:53
Int_t getRootVersion()
Definition: FairRtdbRun.h:54
Bool_t addContainer(FairParSet *)
void removeContainer(Text_t *)
Bool_t hasChanged()
Definition: FairParSet.h:73
virtual Bool_t check()
Definition: FairParIo.h:47
void printParamContexts()
void addContFactory(FairContFact *)
UInt_t getRunId(void)
Definition: FairRtdbRun.h:90
FairParIo * getSecondInput(void)
ParamIOType ioType
Definition: FairRuntimeDb.h:53
virtual void cd()
Definition: FairParIo.h:54
virtual FairDetParIo * getDetParIo(const Text_t *)
Definition: FairParIo.cxx:71
Bool_t addContext(const char *name)
FairParIo * getOutput(void)
Bool_t readAll(void)
virtual void readVersions(FairRtdbRun *)
Definition: FairParIo.h:50
Bool_t setOutput(FairParIo *)
void resetInputVersions()
Definition: FairParSet.cxx:121
Bool_t versionsChanged
Definition: FairRuntimeDb.h:38
void removeContFactory(FairContFact *fact)
FairContFact * getContFactory(const Text_t *)
FairRtdbRun * addRun(Int_t runId, Int_t refId=-1)
void closeFirstInput(void)
virtual void setDetParIo(FairDetParIo *)
Definition: FairParIo.cxx:51
void resetOutputVersions(void)
Bool_t setRootOutputVersion(Int_t run, Text_t *container, Int_t version)
virtual void close()
Definition: FairParIo.h:33
Bool_t addParamContext(const char *)
Bool_t isOwned()
Definition: FairParSet.h:70
void resetInputVersions(void)
Bool_t setFirstInput(FairParIo *)
virtual void print()
Definition: FairParIo.h:44
void saveOutput(void)
FairParIo * getFirstInput(void)
FairParIo * firstInput
Definition: FairRuntimeDb.h:33
Bool_t isRootFileOutput
Definition: FairRuntimeDb.h:39