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