Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4AllServer.cc
Go to the documentation of this file.
1 #include "Fun4AllServer.h"
2 #include "Fun4AllHistoBinDefs.h"
3 #include "Fun4AllInputManager.h"
4 #include "Fun4AllOutputManager.h"
5 #include "Fun4AllReturnCodes.h"
6 #include "Fun4AllSyncManager.h"
7 #include "SubsysReco.h"
8 
10 #include <phool/PHDataNode.h>
11 #include <phool/PHNodeIOManager.h>
12 #include <phool/PHNodeIterator.h>
13 #include <phool/PHNodeReset.h>
14 #include <phool/PHObject.h>
16 #include <phool/PHTimeStamp.h>
18 #include <phool/getClass.h>
19 #include <phool/phool.h>
20 #include <phool/recoConsts.h>
21 
22 #include <TDirectory.h>
23 #include <TFile.h>
24 #include <TH1D.h>
25 #include <TNamed.h>
26 #include <TROOT.h>
27 #include <TSystem.h>
28 
29 #include <boost/foreach.hpp>
30 
31 #include <sys/utsname.h>
32 #include <algorithm>
33 #include <cmath>
34 #include <cstdlib>
35 #include <exception>
36 #include <iostream>
37 #include <sstream>
38 
39 using namespace std;
40 
42 
44 {
45  if (__instance)
46  {
47  return __instance;
48  }
49  __instance = new Fun4AllServer();
50  return __instance;
51 }
52 
53 Fun4AllServer::Fun4AllServer(const std::string &name)
54  : Fun4AllBase(name)
55  , OutNodeCount(0)
56  , bortime_override(0)
57  , ScreamEveryEvent(0)
58  , unregistersubsystem(0)
59  , runnumber(0)
60  , eventnumber(0)
61  , beginruntimestamp(nullptr)
62  , keep_db_connected(0)
63 {
64  InitAll();
65  return;
66 }
67 
69 {
70  Reset();
71  delete beginruntimestamp;
72  while (Subsystems.begin() != Subsystems.end())
73  {
75  {
76  Subsystems.back().first->Verbosity(verbosity);
77  }
78  delete Subsystems.back().first;
79  Subsystems.pop_back();
80  }
81  while (HistoManager.begin() != HistoManager.end())
82  {
84  {
85  HistoManager.back()->Verbosity(verbosity);
86  }
87  delete HistoManager.back();
88  HistoManager.pop_back();
89  }
90  while (OutputManager.begin() != OutputManager.end())
91  {
93  {
94  OutputManager.back()->Verbosity(verbosity);
95  }
96  delete OutputManager.back();
97  OutputManager.pop_back();
98  }
99  while (SyncManagers.begin() != SyncManagers.end())
100  {
101  SyncManagers.back()->Verbosity(verbosity);
102  delete SyncManagers.back();
103  SyncManagers.pop_back();
104  }
105  while (topnodemap.begin() != topnodemap.end())
106  {
107  if (verbosity >= VERBOSITY_MORE)
108  {
109  topnodemap.begin()->second->print();
110  }
111  delete topnodemap.begin()->second;
112  topnodemap.erase(topnodemap.begin());
113  }
114  while (TDirCollection.begin() != TDirCollection.end())
115  {
116  delete TDirCollection.back();
117  TDirCollection.pop_back();
118  }
120  delete rc;
121  __instance = nullptr;
122  return;
123 }
124 
126 {
127  // first remove stupid root signal handler to get
128  // decent crashes with debuggable core file
129  for (int i = 0; i < kMAXSIGNALS; i++)
130  {
131  gSystem->IgnoreSignal((ESignals) i);
132  }
133  ostringstream histomanagername;
134  histomanagername << Name() << "HISTOS";
135  ServerHistoManager = new Fun4AllHistoManager(histomanagername.str());
137  double uplim = NFRAMEWORKBINS - 0.5;
138  FrameWorkVars = new TH1D("FrameWorkVars", "FrameWorkVars", NFRAMEWORKBINS, -0.5, uplim);
139  registerHisto("FrameWorkVars", FrameWorkVars);
140  defaultSyncManager = new Fun4AllSyncManager("DefaultSyncManager");
141  SyncManagers.push_back(defaultSyncManager);
142  TopNode = new PHCompositeNode("TOP");
143  topnodemap["TOP"] = TopNode;
144  default_Tdirectory = gDirectory->GetPath();
146  return;
147 }
148 
149 int Fun4AllServer::dumpHistos(const string &filename, const string &openmode)
150 {
151  int iret = 0;
152  cout << "Fun4AllServer::dumpHistos() dumping histograms" << endl;
153  if (!filename.empty())
154  {
156  }
157  vector<Fun4AllHistoManager *>::const_iterator hiter;
158  for (hiter = HistoManager.begin(); hiter != HistoManager.end(); ++hiter)
159  {
160  iret += (*hiter)->dumpHistos("", openmode);
161  }
162  return iret;
163 }
164 
165 bool Fun4AllServer::registerHisto(TNamed *h1d, const int replace)
166 {
167  return ServerHistoManager->registerHisto(h1d, replace);
168 }
169 
170 bool Fun4AllServer::registerHisto(const char *hname, TNamed *h1d, const int replace)
171 {
172  return ServerHistoManager->registerHisto(hname, h1d, replace);
173 }
174 
175 int Fun4AllServer::isHistoRegistered(const string &name) const
176 {
177  int iret = ServerHistoManager->isHistoRegistered(name);
178  return iret;
179 }
180 
181 int Fun4AllServer::registerSubsystem(SubsysReco *subsystem, const string &topnodename)
182 {
184  // if somebody opens a TFile (or changes the gDirectory) in the ctor
185  // we need to set it to a "known" directory
186  gROOT->cd(default_Tdirectory.c_str());
187  string currdir = gDirectory->GetPath();
188  TDirectory *tmpdir = gDirectory;
189  if (!tmpdir->FindObject(topnodename.c_str()))
190  {
191  tmpdir = tmpdir->mkdir(topnodename.c_str());
192  if (!tmpdir)
193  {
194  cout << "Error creating TDirectory topdir " << topnodename.c_str() << endl;
195  exit(1);
196  }
197  // store the TDir pointer so it can be cleaned up in the dtor
198  // if one deletes it here the Histograms are dangling somewhere
199  // in root (at least according to valgrind the delete doesn't work
200  // properly anymore)
201  TDirCollection.push_back(tmpdir);
202  }
203  gROOT->cd(topnodename.c_str());
204  tmpdir = gDirectory;
205  if (!tmpdir->FindObject(subsystem->Name().c_str()))
206  {
207  tmpdir = tmpdir->mkdir(subsystem->Name().c_str());
208  if (!tmpdir)
209  {
210  cout << "Error creating TDirectory subdir " << subsystem->Name() << endl;
211  exit(1);
212  }
213  // store the TDir pointer so it can be cleaned up in the dtor
214  // if one deletes it here the Histograms are dangling somewhere
215  // in root
216  TDirCollection.push_back(tmpdir);
217  }
218  PHCompositeNode *subsystopNode = se->topNode(topnodename);
219  pair<SubsysReco *, PHCompositeNode *> newsubsyspair(subsystem, subsystopNode);
220  int iret = 0;
221  try
222  {
223  iret = subsystem->Init(subsystopNode);
224  }
225  catch (const exception &e)
226  {
227  cout << PHWHERE << " caught exception thrown during SubsysReco::Init() from "
228  << subsystem->Name() << endl;
229  cout << "error: " << e.what() << endl;
230  exit(1);
231  }
232  catch (...)
233  {
234  cout << PHWHERE << " caught unknown type exception thrown during SubsysReco::Init() from "
235  << subsystem->Name() << endl;
236  exit(1);
237  }
238  gROOT->cd(currdir.c_str());
239  if (iret)
240  {
242  {
243  if (verbosity >= VERBOSITY_SOME)
244  {
245  cout << "Not Registering Subsystem " << subsystem->Name() << endl;
246  }
247  return 0;
248  }
249  cout << PHWHERE << " Error initializing subsystem "
250  << subsystem->Name() << ", return code: " << iret << endl;
251  return iret;
252  }
253  if (verbosity >= VERBOSITY_SOME)
254  {
255  cout << "Registering Subsystem " << subsystem->Name() << endl;
256  }
257  Subsystems.push_back(newsubsyspair);
258  ostringstream timer_name;
259  timer_name << subsystem->Name() << "_" << topnodename;
260  PHTimer timer(timer_name.str());
261  if (timer_map.find(timer_name.str()) == timer_map.end())
262  {
263  timer_map[timer_name.str()] = timer;
264  }
265  RetCodes.push_back(iret); // vector with return codes
266  return 0;
267 }
268 
270 {
271  pair<SubsysReco *, PHCompositeNode *> subsyspair(subsystem, 0);
272  DeleteSubsystems.push_back(subsyspair);
274  return 0;
275 }
276 
278 {
279  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator sysiter, removeiter;
280  for (removeiter = DeleteSubsystems.begin();
281  removeiter != DeleteSubsystems.end();
282  ++removeiter)
283  {
284  int index = 0;
285  int foundit = 0;
286  for (sysiter = Subsystems.begin(); sysiter != Subsystems.end(); ++sysiter)
287  {
288  if ((*sysiter).first == (*removeiter).first)
289  {
290  foundit = 1;
291  break;
292  }
293  index++;
294  }
295  if (!foundit)
296  {
297  cout << "unregisterSubsystem: Could not find SubsysReco "
298  << (*removeiter).first->Name()
299  << " in Fun4All Reco Module list" << endl;
300  delete (*removeiter).first;
301  continue;
302  }
303  if (verbosity >= VERBOSITY_MORE)
304  {
305  cout << "Removing Subsystem: " << (*removeiter).first->Name()
306  << " at index " << index << endl;
307  }
308  Subsystems.erase(Subsystems.begin() + index);
309  delete (*removeiter).first;
310  // also update the vector with return codes
311  RetCodes.erase(RetCodes.begin() + index);
312  vector<Fun4AllOutputManager *>::iterator outiter;
313  for (outiter = OutputManager.begin(); outiter != OutputManager.end(); ++outiter)
314  {
315  UpdateEventSelector(*outiter);
316  }
317  }
319  DeleteSubsystems.clear();
320  return 0;
321 }
322 
323 SubsysReco *
324 Fun4AllServer::getSubsysReco(const string &name)
325 {
326  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator sysiter;
327  for (sysiter = Subsystems.begin(); sysiter != Subsystems.end(); ++sysiter)
328  {
329  if ((*sysiter).first->Name() == name)
330  {
332  {
333  cout << "Found Subsystem " << name << endl;
334  }
335  return (*sysiter).first;
336  }
337  }
338  cout << "Could not find SubsysReco " << name << endl;
339  return 0;
340 }
341 
342 int Fun4AllServer::AddComplaint(const string &complaint, const string &remedy)
343 {
345  string separatorstring = "------------------------------";
346  ostringstream complaintno;
347  complaintno << "Problem No " << ScreamEveryEvent;
348 
349  ComplaintList.push_back(separatorstring);
350  ComplaintList.push_back(complaintno.str());
351  ComplaintList.push_back(complaint);
352  ComplaintList.push_back(" ");
353  ComplaintList.push_back("Remedy:");
354  ComplaintList.push_back(remedy);
355  ComplaintList.push_back(separatorstring);
356  return 0;
357 }
358 
360 {
361  vector<Fun4AllOutputManager *>::iterator iter;
362  for (iter = OutputManager.begin(); iter != OutputManager.end(); ++iter)
363  {
364  if ((*iter)->Name() == manager->Name())
365  {
366  cout << "OutputManager " << manager->Name() << " allready in list" << endl;
367  return -1;
368  }
369  }
370  if (verbosity >= VERBOSITY_SOME)
371  {
372  cout << "Registering OutputManager " << manager->Name() << endl;
373  }
374  UpdateEventSelector(manager);
375  OutputManager.push_back(manager);
376  return 0;
377 }
378 
380 {
381  vector<string>::iterator striter;
382  vector<pair<SubsysReco *, PHCompositeNode *> >::const_iterator subsysiter;
383 
384 tryagain:
385  manager->RecoModuleIndex()->clear();
386  for (striter = manager->EventSelector()->begin(); striter != manager->EventSelector()->end(); ++striter)
387  {
389  {
390  cout << PHWHERE << "striter: " << *striter << endl;
391  }
392  unsigned index = 0;
393  int found = 0;
394  for (subsysiter = Subsystems.begin(); subsysiter != Subsystems.end(); ++subsysiter)
395  {
396  if (*striter == (*subsysiter).first->Name())
397  {
398  manager->RecoModuleIndex()->push_back(index);
400  {
401  cout << PHWHERE << "setting RecoModuleIndex to " << index << endl;
402  }
403  found = 1;
404  break;
405  }
406  index++;
407  }
408  if (!found)
409  {
410  cout << "Could not find module " << *striter
411  << ", removing it from list of event selector modules" << endl;
412  manager->EventSelector()->erase(striter);
413  goto tryagain;
414  }
415  }
416  return 0;
417 }
418 
421 {
422  vector<Fun4AllOutputManager *>::iterator iter;
423  for (iter = OutputManager.begin(); iter != OutputManager.end(); ++iter)
424  {
425  if (name == (*iter)->Name())
426  {
428  {
429  cout << "Found OutputManager " << name << endl;
430  }
431  return *iter;
432  }
433  }
434  cout << "Could not find OutputManager" << name << endl;
435  return 0;
436 }
437 
440 {
441  vector<Fun4AllHistoManager *>::iterator iter;
442  for (iter = HistoManager.begin(); iter != HistoManager.end(); ++iter)
443  {
444  if ((*iter)->Name() == name)
445  {
447  {
448  cout << "Found HistoManager " << name << endl;
449  }
450  return *iter;
451  }
452  }
453  if (verbosity >= VERBOSITY_MORE)
454  {
455  cout << "Could not find HistoManager " << name << endl;
456  }
457  return 0;
458 }
459 
461 {
462  vector<Fun4AllHistoManager *>::iterator iter;
463  for (iter = HistoManager.begin(); iter != HistoManager.end(); ++iter)
464  {
465  if ((*iter)->Name() == manager->Name())
466  {
467  cout << "HistoManager " << manager->Name() << " allready in list" << endl;
468  return -1;
469  }
470  }
471  if (verbosity >= VERBOSITY_SOME)
472  {
473  cout << "Registering HistoManager " << manager->Name() << endl;
474  }
475  HistoManager.push_back(manager);
476  return 0;
477 }
478 
479 TNamed *
480 Fun4AllServer::getHisto(const unsigned int ihisto) const
481 {
482  return ServerHistoManager->getHisto(ihisto);
483 }
484 
485 const char *
486 Fun4AllServer::getHistoName(const unsigned int ihisto) const
487 {
488  return (ServerHistoManager->getHistoName(ihisto));
489 }
490 
491 TNamed *Fun4AllServer::getHisto(const string &hname) const
492 {
493  return (ServerHistoManager->getHisto(hname));
494 }
495 
497 {
498  int iret = process_event();
499  return iret;
500 }
501 
503 {
504  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
505  unsigned icnt = 0;
506  int eventbad = 0;
507  if (ScreamEveryEvent)
508  {
509  cout << "*******************************************************************************" << endl;
510  cout << "*******************************************************************************" << endl;
511  cout << "*******************************************************************************" << endl;
512  cout << "Now that I have your attention, please fix the following "
513  << ScreamEveryEvent << " problem(s):" << endl;
514  vector<string>::const_iterator viter;
515  for (viter = ComplaintList.begin(); viter != ComplaintList.end(); ++viter)
516  {
517  cout << *viter << endl;
518  }
519  cout << " " << endl;
520  cout << "*******************************************************************************" << endl;
521  cout << "*******************************************************************************" << endl;
522  cout << "*******************************************************************************" << endl;
523  }
525  {
527  }
528  gROOT->cd(default_Tdirectory.c_str());
529  string currdir = gDirectory->GetPath();
530  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
531  {
532  if (verbosity >= VERBOSITY_MORE)
533  {
534  cout << "Fun4AllServer::process_event processing " << (*iter).first->Name() << endl;
535  }
536  ostringstream newdirname;
537  newdirname << (*iter).second->getName() << "/" << (*iter).first->Name();
538  if (!gROOT->cd(newdirname.str().c_str()))
539  {
540  cout << PHWHERE << "Unexpected TDirectory Problem cd'ing to "
541  << (*iter).second->getName()
542  << " - send e-mail to off-l with your macro" << endl;
543  exit(1);
544  }
545  else
546  {
548  {
549  cout << "process_event: cded to " << newdirname.str().c_str() << endl;
550  }
551  }
552 
553  try
554  {
555  ostringstream timer_name;
556  timer_name << (*iter).first->Name() << "_" << (*iter).second->getName();
557  std::map<const std::string, PHTimer>::iterator titer = timer_map.find(timer_name.str());
558  bool timer_found = false;
559  if (titer != timer_map.end())
560  {
561  timer_found = true;
562  titer->second.restart();
563  }
564  else
565  {
566  cout << "could not find timer for " << timer_name << endl;
567  }
568  RetCodes[icnt] = (*iter).first->process_event((*iter).second);
569  if (timer_found)
570  {
571  titer->second.stop();
572  }
573 
574  }
575  catch (const exception &e)
576  {
577  cout << PHWHERE << " caught exception thrown during process_event from "
578  << (*iter).first->Name() << endl;
579  cout << "error: " << e.what() << endl;
580  exit(1);
581  }
582  catch (...)
583  {
584  cout << PHWHERE << " caught unknown type exception thrown during process_event from "
585  << (*iter).first->Name() << endl;
586  exit(1);
587  }
588  if (RetCodes[icnt])
589  {
591  {
593  {
594  cout << "Fun4AllServer::Discard Event by " << (*iter).first->Name() << endl;
595  }
596  }
597  else if (RetCodes[icnt] == Fun4AllReturnCodes::ABORTEVENT)
598  {
600  eventbad = 1;
601  if (verbosity >= VERBOSITY_MORE)
602  {
603  cout << "Fun4AllServer::Abort Event by " << (*iter).first->Name() << endl;
604  }
605  break;
606  }
607  else if (RetCodes[icnt] == Fun4AllReturnCodes::ABORTRUN)
608  {
610  cout << "Fun4AllServer::Abort Run by " << (*iter).first->Name() << endl;
612  }
613  else
614  {
615  cout << "Fun4AllServer::Unknown return code: "
616  << RetCodes[icnt] << " from process_event method of "
617  << (*iter).first->Name() << endl;
618  cout << "This smells like an uninitialized return code and" << endl;
619  cout << "it is too dangerous to continue, this Run will be aborted" << endl;
620  cout << "If you do not know how to fix this please send mail to" << endl;
621  cout << "phenix-off-l with this message" << endl;
623  }
624  }
625  icnt++;
626  }
627  if (!eventbad)
628  {
630  }
631 
632  gROOT->cd(currdir.c_str());
633 
634  // mainIter.print();
635  if (!OutputManager.empty() && !eventbad) // there are registered IO managers and
636  // the event is not flagged bad
637  {
638  PHNodeIterator iter(TopNode);
639  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
640 
641  if (dstNode)
642  {
643  // check if we have same number of nodes. After first event is
644  // written out root I/O doesn't permit adding nodes, otherwise
645  // events get out of sync
646  static int first = 1;
647  int newcount = CountOutNodes(dstNode);
648  if (first)
649  {
650  first = 0;
651  OutNodeCount = newcount; // save number of nodes before first write
652  MakeNodesTransient(dstNode); // make all nodes transient before 1st write in case someone sneaked a node in at the first event
653  }
654 
655  if (OutNodeCount != newcount)
656  {
657  iter.print();
658  cout << PHWHERE << " FATAL: Someone changed the number of Output Nodes on the fly, from " << OutNodeCount << " to " << newcount << endl;
659  exit(1);
660  }
661  vector<Fun4AllOutputManager *>::iterator iterOutMan;
662  for (iterOutMan = OutputManager.begin(); iterOutMan != OutputManager.end(); ++iterOutMan)
663  {
664  if (!(*iterOutMan)->DoNotWriteEvent(&RetCodes))
665  {
666  if (verbosity >= VERBOSITY_MORE)
667  {
668  cout << "Writing Event for " << (*iterOutMan)->Name() << endl;
669  }
670  (*iterOutMan)->WriteGeneric(dstNode);
671  }
672  else
673  {
674  if (verbosity >= VERBOSITY_MORE)
675  {
676  cout << "Not Writing Event for " << (*iterOutMan)->Name() << endl;
677  }
678  }
679  }
680  }
681  }
682  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
683  {
685  {
686  cout << "Fun4AllServer::process_event Resetting Event " << (*iter).first->Name() << endl;
687  }
688  (*iter).first->ResetEvent((*iter).second);
689  }
690  BOOST_FOREACH (Fun4AllSyncManager *syncman, SyncManagers)
691  {
693  {
694  cout << "Fun4AllServer::process_event Resetting Event for Sync Manager " << syncman->Name() << endl;
695  }
696  syncman->ResetEvent();
697  }
698  ResetNodeTree();
699  return 0;
700 }
701 
703 {
704  vector<string> ResetNodeList;
705  ResetNodeList.push_back("DST");
706  PHNodeReset reset;
707  reset.Verbosity(verbosity>0 ? verbosity-1: 0); // one lower verbosity level than Fun4AllServer
708  map<string, PHCompositeNode *>::const_iterator iter;
709  for (iter = topnodemap.begin(); iter != topnodemap.end(); ++iter)
710  {
711  PHNodeIterator mainIter((*iter).second);
712  for (vector<string>::const_iterator nodename = ResetNodeList.begin();
713  nodename != ResetNodeList.end(); ++nodename)
714  {
715  if (mainIter.cd(*nodename))
716  {
717  mainIter.forEach(reset);
718  mainIter.cd();
719  }
720  }
721  }
722  return 0; // anything except 0 would abort the event loop in pmonitor
723 }
724 
726 {
727  int i = 0;
728  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
729  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
730  {
732  {
733  cout << "Fun4AllServer::Reset Resetting " << (*iter).first->Name() << endl;
734  }
735  i += (*iter).first->Reset((*iter).second);
736  }
737  vector<Fun4AllHistoManager *>::iterator hiter;
738  for (hiter = HistoManager.begin(); hiter != HistoManager.end(); ++hiter)
739  {
740  (*hiter)->Reset();
741  }
742  return i;
743 }
744 
746 {
747  beginruntimestamp = new PHTimeStamp(TimeStp);
748  cout << "Setting BOR timestamp to ";
750  cout << endl;
751  bortime_override = 1;
752  return 0;
753 }
754 
755 int Fun4AllServer::BeginRun(const int runno)
756 {
757  if (!bortime_override)
758  {
759  if (beginruntimestamp)
760  {
761  delete beginruntimestamp;
762  }
764  }
765  else
766  {
767  cout << "overriding BOR timestamp by ";
769  cout << endl;
770  //rc->set_TimeStamp(*beginruntimestamp);
771  }
772  if (verbosity >= VERBOSITY_SOME)
773  {
774  cout << "Fun4AllServer::BeginRun: Run number " << runno << " uses RECO TIMESTAMP: ";
776  cout << endl;
777  }
778  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
779  int iret;
780 
781  // check if any registered SubsysReco wants to be dropped and
782  // remove it from the list before its BeginRun is executed
784  {
786  }
787 
788  // we have to do the same TDirectory games as in the Init methods
789  // save the current dir, cd to the subsystem name dir (which was
790  // created in init) call the InitRun of the module and cd back
791 
792  gROOT->cd(default_Tdirectory.c_str());
793  string currdir = gDirectory->GetPath();
794  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
795  {
796  ostringstream newdirname;
797  newdirname << (*iter).second->getName() << "/" << (*iter).first->Name();
798  if (!gROOT->cd(newdirname.str().c_str()))
799  {
800  cout << PHWHERE << "Unexpected TDirectory Problem cd'ing to "
801  << (*iter).second->getName()
802  << " - send e-mail to off-l with your macro" << endl;
803  exit(1);
804  }
805  else
806  {
808  {
809  cout << "BeginRun: cded to " << newdirname.str().c_str() << endl;
810  }
811  }
812 
813  if (verbosity >= VERBOSITY_SOME)
814  {
815  cout << "Fun4AllServer::BeginRun: InitRun for " << (*iter).first->Name() << endl;
816  }
817  try
818  {
819  iret = (*iter).first->InitRun((*iter).second);
820  }
821  catch (const exception &e)
822  {
823  cout << PHWHERE << " caught exception thrown during SubsysReco::InitRun() from "
824  << (*iter).first->Name() << endl;
825  cout << "error: " << e.what() << endl;
826  exit(1);
827  }
828  catch (...)
829  {
830  cout << PHWHERE << " caught unknown type exception thrown during SubsysReco::InitRun() from "
831  << (*iter).first->Name() << endl;
832  exit(1);
833  }
834 
835  if (iret == Fun4AllReturnCodes::ABORTRUN)
836  {
837  cout << PHWHERE << "Module " << (*iter).first->Name() << " issued Abort Run, exiting" << endl;
838  exit(-1);
839  }
840  else if (iret != Fun4AllReturnCodes::EVENT_OK)
841  {
842  cout << PHWHERE << "Module " << (*iter).first->Name() << " issued non Fun4AllReturnCodes::EVENT_OK return code " << iret << " in InitRun()" << endl;
843  exit(-2);
844  }
845  }
846  gROOT->cd(currdir.c_str());
847 
848  // disconnect from DB to save resources on DB machine
849  // PdbCal leaves the DB connection open (PdbCal will reconnect without
850  // problem if neccessary)
851  if (!keep_db_connected)
852  {
853  DisconnectDB();
854  }
855  else
856  {
857  cout << "WARNING WARNING, DBs will not be disconnected" << endl;
858  cout << "This is for DB server testing purposes only" << endl;
859  cout << "If you do not test our DB servers, remove" << endl;
860  cout << "Fun4AllServer->KeepDBConnection()" << endl;
861  cout << "from your macro" << endl;
862  }
863  // print out all node trees
864  Print("NODETREE");
865  return 0;
866 }
867 
869 {
870  int icount = 0;
871  icount = CountOutNodesRecursive(startNode, icount);
872  return icount;
873 }
874 
876 {
877  PHNodeIterator nodeiter(startNode);
878  PHPointerListIterator<PHNode> iterat(nodeiter.ls());
879  PHNode *thisNode;
880  int icnt = icount;
881  while ((thisNode = iterat()))
882  {
883  if ((thisNode->getType() == "PHCompositeNode"))
884  {
885  icnt = CountOutNodesRecursive(static_cast<PHCompositeNode *>(thisNode), icnt); // if this is a CompositeNode do this trick again
886  }
887  else
888  {
889  icnt++;
891  {
892  cout << thisNode->getName() << ", Node Count: " << icnt << endl;
893  }
894  }
895  }
896  return icnt;
897 }
898 
900 {
901  PHNodeIterator nodeiter(startNode);
902  PHPointerListIterator<PHNode> iterat(nodeiter.ls());
903  PHNode *thisNode;
904  while ((thisNode = iterat()))
905  {
906  if ((thisNode->getType() == "PHCompositeNode"))
907  {
908  MakeNodesTransient(static_cast<PHCompositeNode *>(thisNode)); // if this is a CompositeNode do this trick again
909  }
910  else
911  {
912  thisNode->makeTransient();
913  }
914  }
915  return 0;
916 }
917 
919 {
920  PHNodeIterator nodeiter(startNode);
921  PHPointerListIterator<PHNode> iterat(nodeiter.ls());
922  PHNode *thisNode;
923  while ((thisNode = iterat()))
924  {
925  if ((thisNode->getType() == "PHCompositeNode"))
926  {
927  MakeNodesPersistent(static_cast<PHCompositeNode *>(thisNode)); // if this is a CompositeNode do this trick again
928  }
929  else
930  {
931  thisNode->makePersistent();
932  }
933  }
934  return 0;
935 }
936 
937 int Fun4AllServer::EndRun(const int runno)
938 {
939  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
940  gROOT->cd(default_Tdirectory.c_str());
941  string currdir = gDirectory->GetPath();
942  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
943  {
944  if (verbosity >= VERBOSITY_MORE)
945  {
946  cout << "Fun4AllServer::EndRun: EndRun("
947  << runno << ") for " << (*iter).first->Name() << endl;
948  }
949  ostringstream newdirname;
950  newdirname << (*iter).second->getName() << "/" << (*iter).first->Name();
951  if (!gROOT->cd(newdirname.str().c_str()))
952  {
953  cout << PHWHERE << "Unexpected TDirectory Problem cd'ing to "
954  << (*iter).second->getName()
955  << " - send e-mail to off-l with your macro" << endl;
956  exit(1);
957  }
958  else
959  {
961  {
962  cout << "EndRun: cded to " << newdirname.str().c_str() << endl;
963  }
964  }
965  try
966  {
967  (*iter).first->EndRun(runno);
968  }
969  catch (const exception &e)
970  {
971  cout << PHWHERE << " caught exception thrown during SubsysReco::EndRun() from "
972  << (*iter).first->Name() << endl;
973  cout << "error: " << e.what() << endl;
974  exit(1);
975  }
976  catch (...)
977  {
978  cout << PHWHERE << " caught unknown type exception thrown during SubsysReco::EndRun() from "
979  << (*iter).first->Name() << endl;
980  exit(1);
981  }
982  }
983  gROOT->cd(currdir.c_str());
984 
985  return 0;
986 }
987 
989 {
991  EndRun(rc->get_IntFlag("RUNNUMBER")); // call SubsysReco EndRun methods for current run
992  int i = 0;
993  vector<pair<SubsysReco *, PHCompositeNode *> >::iterator iter;
994  gROOT->cd(default_Tdirectory.c_str());
995  string currdir = gDirectory->GetPath();
996  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
997  {
998  if (verbosity >= VERBOSITY_SOME)
999  {
1000  cout << "Fun4AllServer::End: End for " << (*iter).first->Name() << endl;
1001  }
1002  ostringstream newdirname;
1003  newdirname << (*iter).second->getName() << "/" << (*iter).first->Name();
1004  if (!gROOT->cd(newdirname.str().c_str()))
1005  {
1006  cout << PHWHERE << "Unexpected TDirectory Problem cd'ing to "
1007  << (*iter).second->getName()
1008  << " - send e-mail to off-l with your macro" << endl;
1009  exit(1);
1010  }
1011  else
1012  {
1014  {
1015  cout << "End: cded to " << newdirname.str().c_str() << endl;
1016  }
1017  }
1018  try
1019  {
1020  i += (*iter).first->End((*iter).second);
1021  }
1022  catch (const exception &e)
1023  {
1024  cout << PHWHERE << " caught exception thrown during SusbsysReco::End() from "
1025  << (*iter).first->Name() << endl;
1026  cout << "error: " << e.what() << endl;
1027  exit(1);
1028  }
1029  catch (...)
1030  {
1031  cout << PHWHERE << " caught unknown type exception thrown during SubsysReco::End() from "
1032  << (*iter).first->Name() << endl;
1033  exit(1);
1034  }
1035  }
1036  gROOT->cd(currdir.c_str());
1037  PHNodeIterator nodeiter(TopNode);
1038  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(nodeiter.findFirst("PHCompositeNode", "RUN"));
1039  if (!runNode)
1040  {
1041  cout << "No Run Node, not writing Runwise info" << endl;
1042  }
1043  else
1044  {
1045  if (!OutputManager.empty()) // there are registered IO managers
1046  {
1047  vector<Fun4AllOutputManager *>::iterator IOiter;
1048  for (IOiter = OutputManager.begin(); IOiter != OutputManager.end(); ++IOiter)
1049  {
1050  (*IOiter)->WriteNode(runNode);
1051  }
1052  }
1053  }
1054  // close output files (check for existing output managers is
1055  // done inside outfileclose())
1056  outfileclose();
1057 
1058  if (ScreamEveryEvent)
1059  {
1060  cout << "*******************************************************************************" << endl;
1061  cout << "*******************************************************************************" << endl;
1062  cout << "*******************************************************************************" << endl;
1063  cout << "Now that we are at the End(), please fix the following "
1064  << ScreamEveryEvent << " problem(s):" << endl;
1065  vector<string>::const_iterator viter;
1066  for (viter = ComplaintList.begin(); viter != ComplaintList.end(); ++viter)
1067  {
1068  cout << *viter << endl;
1069  }
1070  cout << " " << endl;
1071  cout << "*******************************************************************************" << endl;
1072  cout << "*******************************************************************************" << endl;
1073  cout << "*******************************************************************************" << endl;
1074  }
1075 
1076  return i;
1077 }
1078 
1079 void Fun4AllServer::Print(const string &what) const
1080 {
1081  if (what == "ALL" || what == "HISTOS")
1082  {
1083  // loop over the map and print out the content (name and location in memory)
1084  BOOST_FOREACH (Fun4AllHistoManager *histoman, HistoManager)
1085  {
1086  histoman->Print(what);
1087  }
1088  }
1089  if (what == "ALL" || what == "SUBSYSTEMS")
1090  {
1091  // loop over the map and print out the content (name and location in memory)
1092  cout << "--------------------------------------" << endl
1093  << endl;
1094  cout << "List of Subsystems in Fun4AllServer:" << endl;
1095 
1096  vector<pair<SubsysReco *, PHCompositeNode *> >::const_iterator miter;
1097  for (miter = Subsystems.begin(); miter != Subsystems.end(); ++miter)
1098  {
1099  cout << (*miter).first->Name()
1100  << " running under topNode " << (*miter).second->getName() << endl;
1101  }
1102  cout << endl;
1103  }
1104 
1105  if (what == "ALL" || what == "INPUTMANAGER")
1106  {
1107  // the input managers are managed by the input singleton
1108  BOOST_FOREACH (Fun4AllSyncManager *syncman, SyncManagers)
1109  {
1110  cout << "SyncManager: " << syncman->Name() << endl;
1111  syncman->Print(what);
1112  }
1113  }
1114 
1115  if (what == "ALL" || what.find("OUTPUTMANAGER") != string::npos)
1116  {
1117  // loop over the map and print out the content (name and location in memory)
1118  string pass_on = what;
1119  if (pass_on == "ALL" || pass_on == "OUTPUTMANAGER")
1120  {
1121  cout << "--------------------------------------" << endl
1122  << endl;
1123  cout << "List of OutputManagers in Fun4AllServer:" << endl;
1124  pass_on = "ALL";
1125  }
1126  else
1127  {
1128  string::size_type pos = pass_on.find("%");
1129  pass_on = pass_on.substr(pos + 1, pass_on.size());
1130  }
1131  BOOST_FOREACH (Fun4AllOutputManager *outman, OutputManager)
1132  {
1133  outman->Print(pass_on);
1134  }
1135  cout << endl;
1136  }
1137  if (what == "ALL" || what == "TOPNODES")
1138  {
1139  // loop over the map and print out the content (name and location in memory)
1140  cout << "--------------------------------------" << endl
1141  << endl;
1142  cout << "List of TopNodes in Fun4AllServer:" << endl;
1143 
1144  map<std::string, PHCompositeNode *>::const_iterator iter;
1145  for (iter = topnodemap.begin(); iter != topnodemap.end(); ++iter)
1146  {
1147  cout << iter->first << " is at " << hex
1148  << iter->second << dec << endl;
1149  }
1150  cout << endl;
1151  }
1152  if (what == "ALL" || what == "NODETREE")
1153  {
1154  // loop over the map and print out the content (name and location in memory)
1155  cout << "--------------------------------------" << endl
1156  << endl;
1157  cout << "List of Nodes in Fun4AllServer:" << endl;
1158 
1159  map<std::string, PHCompositeNode *>::const_iterator iter;
1160  for (iter = topnodemap.begin(); iter != topnodemap.end(); ++iter)
1161  {
1162  cout << "Node Tree under TopNode " << iter->first << endl;
1163  PHNodeIterator nodeiter(iter->second);
1164  nodeiter.print();
1165  cout << endl;
1166  }
1167  cout << endl;
1168  }
1169  return;
1170 }
1171 
1172 void Fun4AllServer::identify(std::ostream &out) const
1173 {
1174  out << "Fun4AllServer Name: " << ThisName << endl;
1175  return;
1176 }
1177 
1179 {
1180  while (!OutputManager.empty())
1181  {
1182  if (verbosity >= VERBOSITY_MORE)
1183  {
1184  cout << "Erasing OutputManager "
1185  << (*OutputManager.begin())->Name()
1186  << " at memory location " << *(OutputManager.begin()) << endl;
1187  }
1188  delete *(OutputManager.begin());
1189  OutputManager.erase(OutputManager.begin());
1190  }
1191  return 0;
1192 }
1193 
1195 {
1196  PHCompositeNode *dstNode, *runNode, *parNode;
1197  dstNode = new PHCompositeNode("DST");
1198  topNode->addNode(dstNode);
1199  runNode = new PHCompositeNode("RUN");
1200  topNode->addNode(runNode);
1201  parNode = new PHCompositeNode("PAR");
1202  topNode->addNode(parNode);
1203  return 0;
1204 }
1205 
1207 Fun4AllServer::topNode(const string &name)
1208 {
1209  map<string, PHCompositeNode *>::const_iterator iter;
1210  iter = topnodemap.find(name);
1211  if (iter != topnodemap.end())
1212  {
1213  return iter->second;
1214  }
1215  AddTopNode(name);
1216  iter = topnodemap.find(name);
1217  if (iter != topnodemap.end())
1218  {
1219  InitNodeTree(iter->second);
1220  return iter->second;
1221  }
1222  cout << PHWHERE << " Could not create new topNode " << name
1223  << " send email to off-l with the following printout: " << endl;
1224  for (iter = topnodemap.begin(); iter != topnodemap.end(); ++iter)
1225  {
1226  cout << iter->first << " is at " << hex << iter->second << endl;
1227  }
1228  exit(1);
1229 }
1230 
1231 int Fun4AllServer::AddTopNode(const string &name)
1232 {
1233  map<string, PHCompositeNode *>::const_iterator iter;
1234  iter = topnodemap.find(name);
1235  if (iter != topnodemap.end())
1236  {
1237  return -1;
1238  }
1239  PHCompositeNode *newNode = new PHCompositeNode(name.c_str());
1240  topnodemap[name] = newNode;
1241  return 0;
1242 }
1243 
1244 PHCompositeNode *Fun4AllServer::getNode(const char *name, const char *topnodename)
1245 {
1246  PHNodeIterator iter(topNode(topnodename));
1247  PHCompositeNode *thisNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", name));
1248  if (!thisNode)
1249  {
1250  thisNode = new PHCompositeNode(name);
1251  topNode(topnodename)->addNode(thisNode);
1252  }
1253  return thisNode;
1254 }
1255 
1257 {
1258  int iret = defaultSyncManager->registerInputManager(InManager);
1259  return iret;
1260 }
1261 
1264 {
1265  vector<Fun4AllSyncManager *>::const_iterator iter;
1266  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1267  {
1268  if ((*iter)->getInputManager(name))
1269  {
1270  return (*iter)->getInputManager(name);
1271  }
1272  }
1273  cout << "Could not locate input manager " << name << endl;
1274  return 0;
1275 }
1276 
1278 {
1279  return (defaultSyncManager->PrdfEvents());
1280 }
1281 
1283 {
1284  return (defaultSyncManager->TotalEvents());
1285 }
1286 
1287 //_________________________________________________________________
1288 int Fun4AllServer::run(const int nevnts, const bool require_nevents)
1289 {
1291  static bool run_number_forced = rc->FlagExist("RUNNUMBER");
1292  static int ifirst = 1;
1293  if (ifirst && run_number_forced)
1294  {
1295  runnumber = rc->get_IntFlag("RUNNUMBER");
1296  cout << "Fun4AllServer: Runnumber forced to " << runnumber << " by RUNNUMBER IntFlag" << endl;
1297  }
1298  int iret = 0;
1299  int icnt = 0;
1300  int icnt_good = 0;
1301  vector<Fun4AllSyncManager *>::const_iterator iter;
1302  while (!iret)
1303  {
1304  int resetnodetree = 0;
1305  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1306  {
1307  if (verbosity >= VERBOSITY_MORE)
1308  {
1309  cout << "executing run for input master " << (*iter)->Name() << endl;
1310  }
1311  int retval = (*iter)->run(1);
1312  // if a new input file is opened during syncing and it contains
1313  // different nodes
1314  // as the previous one, the info in the nodes which are only in
1315  // the previous file will be carried to another event. We also
1316  // do not know under which topNode the input managers put
1317  // their data. This is why
1318  // the whole node tree is resetted whenever one of the Sync Managers
1319  // requires it.
1320  if (retval == 1)
1321  {
1322  resetnodetree = 1;
1323  }
1324  else
1325  {
1326  iret += retval;
1327  }
1328  }
1329  if (resetnodetree)
1330  {
1331  // if the node tree needs resetting, we just push the current
1332  // event(s) (which are all properly synced at this point)
1333  // back into the input managers and just read again.
1334  ResetNodeTree();
1335  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1336  {
1337  (*iter)->PushBackInputMgrsEvents(1);
1338  }
1339  continue;
1340  }
1341  if (iret)
1342  {
1343  break;
1344  }
1345  int currentrun = 0;
1346  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1347  {
1348  int runno = (*iter)->CurrentRun();
1349  // cout << (*iter)->Name() << " run no: " << runno << endl;
1350  if (runno != 0)
1351  {
1352  if (currentrun == 0)
1353  {
1354  currentrun = runno;
1355  }
1356  else
1357  {
1358  if (currentrun != runno)
1359  {
1360  cout << "Mixing of Runs within same event is not supported" << endl;
1361  cout << "Here is the list of Sync Managers and their runnumbers:" << endl;
1362  vector<Fun4AllSyncManager *>::const_iterator syiter;
1363  for (syiter = SyncManagers.begin(); syiter != SyncManagers.end(); ++syiter)
1364  {
1365  cout << (*syiter)->Name() << " run number: " << (*syiter)->CurrentRun() << endl;
1366  }
1367  cout << "Exiting now" << endl;
1368  exit(1);
1369  }
1370  }
1371  }
1372  }
1373  if (ifirst)
1374  {
1375  if (currentrun != runnumber && !run_number_forced) // use real run if not forced
1376  {
1377  runnumber = currentrun;
1378  }
1379  setRun(runnumber);
1381  ifirst = 0;
1382  }
1383  else if (!run_number_forced)
1384  {
1385  if (currentrun != runnumber)
1386  {
1387  EndRun(runnumber);
1388  runnumber = currentrun;
1389  setRun(runnumber);
1391  }
1392  }
1393 
1394  if (verbosity >= VERBOSITY_SOME)
1395  {
1396  // print event cycle counter in log scale if VERBOSITY_SOME
1397 
1398  const double significand = icnt / pow(10, (int) (log10(icnt)));
1399 
1400  if ((fmod(significand, 1.0) == 0 && significand <= 10) or icnt == 0)
1401  {
1402  cout << "Fun4AllServer::run - process_event cycle "
1403  << icnt << "\t for run " << runnumber;
1404  if (require_nevents)
1405  cout << ", " << icnt_good << " good event so far";
1406  cout << endl;
1407  }
1408  }
1409 
1410  if (icnt == 0 and verbosity > VERBOSITY_QUIET)
1411  {
1412  // increase verbosity for the first event in verbose modes
1413  ++verbosity;
1414  }
1415 
1416  iret = process_event();
1417 
1418  if (icnt == 0 and verbosity > VERBOSITY_QUIET)
1419  {
1420  // increase verbosity for the first event in verbose modes
1421  --verbosity;
1422  }
1423 
1424  if (require_nevents)
1425  {
1426  if (std::find(RetCodes.begin(),
1427  RetCodes.end(),
1428  static_cast<int>(Fun4AllReturnCodes::ABORTEVENT)) == RetCodes.end())
1429  icnt_good++;
1430  if (iret || (nevnts > 0 && icnt_good >= nevnts))
1431  break;
1432  }
1433  else if (iret || (nevnts > 0 && ++icnt >= nevnts))
1434  {
1435  break;
1436  }
1437  }
1438  return iret;
1439 }
1440 
1441 //_________________________________________________________________
1442 int Fun4AllServer::skip(const int nevnts)
1443 {
1444  int iret = 0;
1445  vector<Fun4AllSyncManager *>::const_iterator iter;
1446  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1447  {
1448  iret += (*iter)->skip(nevnts);
1449  }
1450  return iret;
1451 }
1452 
1453 //_________________________________________________________________
1454 int Fun4AllServer::fileopen(const char *managername, const char *filename)
1455 {
1456  int iret = 0;
1457  vector<Fun4AllSyncManager *>::const_iterator iter;
1458  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1459  {
1460  iret += (*iter)->fileopen(managername, filename);
1461  }
1462  return iret;
1463 }
1464 
1465 int Fun4AllServer::BranchSelect(const char *managername, const char *branch, int iflag)
1466 {
1467  int iret = 0;
1468  vector<Fun4AllSyncManager *>::const_iterator iter;
1469  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1470  {
1471  iret += (*iter)->BranchSelect(managername, branch, iflag);
1472  }
1473  return iret;
1474 }
1475 
1476 int Fun4AllServer::BranchSelect(const char *branch, int iflag)
1477 {
1478  int iret = 0;
1479  vector<Fun4AllSyncManager *>::const_iterator iter;
1480  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1481  {
1482  iret += (*iter)->BranchSelect(branch, iflag);
1483  }
1484  return iret;
1485 }
1486 
1487 int Fun4AllServer::setBranches(const char *managername)
1488 {
1489  int iret = 0;
1490  vector<Fun4AllSyncManager *>::const_iterator iter;
1491  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1492  {
1493  iret += (*iter)->setBranches(managername);
1494  }
1495  return iret;
1496 }
1497 
1499 {
1500  int iret = 0;
1501  vector<Fun4AllSyncManager *>::const_iterator iter;
1502  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1503  {
1504  iret += (*iter)->setBranches();
1505  }
1506  return iret;
1507 }
1508 
1509 int Fun4AllServer::fileclose(const string &managername)
1510 {
1511  int iret = 0;
1512  vector<Fun4AllSyncManager *>::const_iterator iter;
1513  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1514  {
1515  iret += (*iter)->fileclose(managername);
1516  }
1517  return iret;
1518 }
1519 
1521 {
1522  int iret = defaultSyncManager->SegmentNumber();
1523  return iret;
1524 }
1525 
1526 void Fun4AllServer::GetInputFullFileList(vector<string> &fnames) const
1527 {
1529  return;
1530 }
1531 
1533 {
1534  return 0;
1535 }
1536 
1537 unsigned
1538 Fun4AllServer::GetTopNodes(std::vector<std::string> &names) const
1539 {
1540  map<string, PHCompositeNode *>::const_iterator iter;
1541  for (iter = topnodemap.begin(); iter != topnodemap.end(); ++iter)
1542  {
1543  names.push_back(iter->first);
1544  }
1545  return names.size();
1546 }
1547 
1548 void Fun4AllServer::GetOutputManagerList(std::vector<std::string> &names) const
1549 {
1550  names.clear();
1551  vector<Fun4AllOutputManager *>::const_iterator iter;
1552  for (iter = OutputManager.begin(); iter != OutputManager.end(); ++iter)
1553  {
1554  names.push_back((*iter)->Name());
1555  }
1556  return;
1557 }
1558 
1559 void Fun4AllServer::GetModuleList(std::vector<std::string> &names) const
1560 {
1561  names.clear();
1562  vector<pair<SubsysReco *, PHCompositeNode *> >::const_iterator iter;
1563  for (iter = Subsystems.begin(); iter != Subsystems.end(); ++iter)
1564  {
1565  names.push_back((*iter).first->Name());
1566  }
1567  return;
1568 }
1569 
1571 {
1572  BOOST_FOREACH (Fun4AllSyncManager *syncman, SyncManagers)
1573  {
1574  if (syncman->Name() == newmaster->Name())
1575  {
1576  cout << "Input Master " << newmaster->Name()
1577  << " already registered" << endl;
1578  return -1;
1579  }
1580  }
1581  if (verbosity >= VERBOSITY_SOME)
1582  {
1583  cout << "Registering Input Master " << newmaster->Name() << endl;
1584  }
1585  SyncManagers.push_back(newmaster);
1586  return 0;
1587 }
1588 
1591 {
1592  if (name == "DefaultSyncManager")
1593  {
1594  return defaultSyncManager;
1595  }
1596  vector<Fun4AllSyncManager *>::iterator iter;
1597 
1598  for (iter = SyncManagers.begin(); iter != SyncManagers.end(); ++iter)
1599  {
1600  if ((*iter)->Name() == name)
1601  {
1602  return *iter;
1603  }
1604  }
1605  cout << "Could not find Input Master " << name << endl;
1606  return 0;
1607 }
1608 
1609 int Fun4AllServer::setRun(const int runno)
1610 {
1612  rc->set_IntFlag("RUNNUMBER", runno);
1613  PHTimeStamp *tstamp = nullptr;
1614  if (!tstamp)
1615  {
1616  tstamp = new PHTimeStamp(0);
1617  cout << "Fun4AllServer::setRun(): could not get timestamp for run " << runno
1618  << ", using tics(0) timestamp: ";
1619  tstamp->print();
1620  cout << endl;
1621  }
1622  delete tstamp;
1623  FrameWorkVars->SetBinContent(RUNNUMBERBIN, (Stat_t) runno);
1624  return 0;
1625 }
1626 
1627 void Fun4AllServer::NodeIdentify(const std::string &name)
1628 {
1629  PHObject *obj = findNode::getClass<PHObject>(TopNode, name);
1630  if (obj)
1631  {
1632  obj->identify();
1633  }
1634  else
1635  {
1636  cout << "Could not locate node " << name
1637  << " or no PHObject Node" << endl;
1638  }
1639  return;
1640 }
1641 
1642 void Fun4AllServer::PrintTimer(const string &name)
1643 {
1644  map<const string, PHTimer>::const_iterator iter;
1645  if (name.empty())
1646  {
1647  for (iter = timer_map.begin(); iter != timer_map.end(); ++iter)
1648  {
1649  iter->second.print_stat();
1650  }
1651  }
1652  else
1653  {
1654  iter = timer_map.find(name);
1655  if (iter != timer_map.end())
1656  {
1657  iter->second.print_stat();
1658  }
1659  else
1660  {
1661  cout << "No timer with name " << name << " found" << endl;
1662  cout << "Existing timers:" << endl;
1663  for (iter = timer_map.begin(); iter != timer_map.end(); ++iter)
1664  {
1665  cout << iter->first << endl;
1666  }
1667  }
1668  }
1669  return;
1670 }
std::vector< std::string > ComplaintList
int registerInputManager(Fun4AllInputManager *InManager)
int AddComplaint(const std::string &complaint, const std::string &remedy)
PHPointerList< PHNode > & ls()
virtual int End()
virtual int Init(PHCompositeNode *)
Definition: SubsysReco.h:41
int registerSyncManager(Fun4AllSyncManager *newmaster)
virtual std::vector< unsigned > * RecoModuleIndex()
retrieves pointer to vector of event selector module ids
int verbosity
The verbosity level. 0 means not verbose at all.
Definition: Fun4AllBase.h:75
std::vector< Fun4AllOutputManager * > OutputManager
static Fun4AllServer * __instance
int BeginRunTimeStamp(PHTimeStamp &TimeStp)
void setOutfileName(const std::string &filename)
std::vector< Fun4AllSyncManager * > SyncManagers
PHTimeStamp * beginruntimestamp
virtual int EndRun(const int runno=0)
void Print(const std::string &what="ALL") const
void GetInputFullFileList(std::vector< std::string > &fnames) const
PHNode * findFirst(const std::string &, const std::string &)
virtual void Print(const std::string &what="ALL") const
#define PHWHERE
Definition: phool.h:23
Fun4AllInputManager * getInputManager(const char *name)
void GetModuleList(std::vector< std::string > &names) const
int AddTopNode(const std::string &name)
void Print(const std::string &what="ALL") const
Fun4AllSyncManager * getSyncManager(const std::string &name="DefaultSyncManager")
virtual std::vector< std::string > * EventSelector()
retrieves pointer to vector of event selector module names
virtual void Verbosity(const int i)
int fileopen(const char *managername="NONE", const char *filename="NONE")
TNamed * getHisto(const std::string &hname) const
static Fun4AllServer * instance()
PHBoolean addNode(PHNode *)
Fun4AllServer * se
void PrintTimer(const std::string &name="")
Fun4AllServer(const std::string &name="Fun4AllServer")
PHBoolean cd(const std::string &pathString="")
const char * getHistoName(const unsigned int ihisto) const
virtual int FlagExist(const std::string &name) const
Definition: PHFlag.cc:255
virtual void set_IntFlag(const std::string &name, const int flag)
Definition: PHFlag.cc:145
virtual int DisconnectDB()
unsigned GetTopNodes(std::vector< std::string > &names) const
int registerHistoManager(Fun4AllHistoManager *manager)
int skip(const int nevnts=0)
skip n events (0 means up to the end of file). Skip means read, don&#39;t process.
int dumpHistos(const std::string &filename="", const std::string &openmode="RECREATE")
int MakeNodesPersistent(PHCompositeNode *startNode)
std::string default_Tdirectory
static recoConsts * instance()
Definition: recoConsts.cc:7
Fun4AllHistoManager * ServerHistoManager
std::vector< std::pair< SubsysReco *, PHCompositeNode * > > DeleteSubsystems
void GetInputFullFileList(std::vector< std::string > &fnames) const
int registerSubsystem(SubsysReco *subsystem, const std::string &topnodename="TOP")
void TotalEvents(const int i)
std::map< int, int > retcodesmap
int unregisterSubsystemsNow()
virtual void identify(std::ostream &os=std::cout) const
Definition: PHObject.cc:21
PHCompositeNode * getNode(const char *name, const char *topnodename="TOP")
std::map< const std::string, PHTimer > timer_map
int registerInputManager(Fun4AllInputManager *InManager)
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
int CountOutNodes(PHCompositeNode *startNode)
Fun4AllHistoManager * getHistoManager(const std::string &name)
virtual const std::string Name() const
Returns the name of this module.
Definition: Fun4AllBase.h:23
void SegmentNumber(const int iseg)
int registerOutputManager(Fun4AllOutputManager *manager)
TNamed * getHisto(const std::string &hname) const
std::vector< int > RetCodes
const char * getHistoName(const unsigned int ihisto) const
std::vector< Fun4AllHistoManager * > HistoManager
Output more messages.
Definition: Fun4AllBase.h:42
virtual int process_event()
int DstEvents() const
int unregisterSubsystem(SubsysReco *subsystem)
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
std::map< std::string, PHCompositeNode * > topnodemap
virtual int isHistoRegistered(const std::string &name) const
int BranchSelect(const char *managername, const char *branch, int iflag)
virtual bool registerHisto(const char *hname, TNamed *h1d, const int replace=0)
virtual void identify(std::ostream &out=std::cout) const
Fun4AllOutputManager * getOutputManager(const std::string &name)
Output even more messages.
Definition: Fun4AllBase.h:45
int InitNodeTree(PHCompositeNode *topNode)
void GetOutputManagerList(std::vector< std::string > &names) const
std::string ThisName
Definition: Fun4AllBase.h:72
Output some useful messages during manual command line running.
Definition: Fun4AllBase.h:39
std::vector< std::pair< SubsysReco *, PHCompositeNode * > > Subsystems
void PrdfEvents(const int i)
bool registerHisto(const std::string &hname, TNamed *h1d, const int replace=0)
virtual void Print(const std::string &what="ALL") const
print method (dump event selector)
void print()
Definition: PHTimeStamp.cc:127
SubsysReco * getSubsysReco(const std::string &name)
static const int NFRAMEWORKBINS
void NodeIdentify(const std::string &name)
int UpdateEventSelector(Fun4AllOutputManager *manager)
Fun4AllSyncManager * defaultSyncManager
int fileclose(const std::string &managername="")
virtual int BeginRun(const int runno)
Definition: PHNode.h:14
int PrdfEvents() const
int setRun(const int runnumber)
void forEach(PHNodeOperation &)
int CountOutNodesRecursive(PHCompositeNode *startNode, const int icount)
Quiet mode. Only output critical messages. Intended for batch production mode.
Definition: Fun4AllBase.h:36
virtual int get_IntFlag(const std::string &name) const
Definition: PHFlag.cc:117
PHCompositeNode * TopNode
high precision timer
Definition: PHTimer.h:24
int MakeNodesTransient(PHCompositeNode *startNode)
virtual ~Fun4AllServer()
std::vector< TDirectory * > TDirCollection
int isHistoRegistered(const std::string &name) const