StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StChain.cxx
1 
35 #define STAR_TRACKING 1
36 
37 
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include "TROOT.h"
41 #include "TError.h"
42 #include "TBrowser.h"
43 #include "TBenchmark.h"
44 #include <sys/times.h>
45 #include <time.h>
46 #include "TSystem.h"
47 #include "StChain.h"
48 #include "StEvtHddr.h"
49 #include "StMessMgr.h"
50 #include "StMemStat.h"
51 #include "StCloseFileOnTerminate.h"
52 #include "TApplication.h"
53 ClassImp(StChain)
54 
55 //_____________________________________________________________________________
56 StChain::StChain(const char *name, const Bool_t UseOwnHeader):
57 StMaker(name),m_EvtHddr(0),mChainOpt(0)
58 {
59  m_Version = 100; //StChain version number and release date
60  m_VersionDate = 180698;
61  mNTotal = 0; mNFailed = 0;
62  if ( UseOwnHeader || !(dynamic_cast<StEvtHddr*>(GetDataSet("EvtHddr"))))
63  m_EvtHddr = new StEvtHddr(m_ConstSet);
64 
65 }
66 
67 //_____________________________________________________________________________
68 StChain::~StChain()
69 {
70 }
71 //_____________________________________________________________________________
72 void StChain::Streamer(TBuffer &)
73 { Error("Streamer"," attempt to write %s\n ",GetName());
74  assert(0);
75 }
76 //_____________________________________________________________________________
77 void StChain::Clear(Option_t *option)
78 {
79  // StartTimer();
80  StMaker::Clear(option);
81  // TCollection::EmptyGarbageCollection();
82  // StopTimer();
83 }
84 //_____________________________________________________________________________
86  // StartTimer();
87  if (TestBIT(kFiniEnd)){
88  Warning("Finish","chain %s.%s Finished twice, Ignore it"
89  ,GetName(),ClassName());
90  return 1;
91  }
92  TCollection::StartGarbageCollection();
93  Int_t res = StMaker::Finish();
94  // TCollection::EmptyGarbageCollection();
95  SetBIT (kFiniEnd);
96  // StopTimer();
97  PrintTotalTime();
98  // delete gMessMgr; gMessMgr = 0;
99  return res;
100 }
101 //_____________________________________________________________________________
102 Int_t StChain::Init()
103 {
104  // StartTimer();
105  Int_t res = StMaker::Init();
106  // StopTimer();
107  return res;
108 }
109 //_____________________________________________________________________________
110 Int_t StChain::Make() {
111  // StartTimer();
112  if (m_EvtHddr) m_EvtHddr->SetProdDateTime();
113  Int_t res = StMaker::Make();
114  // StopTimer();
115  return res;
116 }
117 //_____________________________________________________________________________
118 Int_t StChain::MakeEvent()
119 {
120  // Make next event from the TBrowser TContextMenu
121  Clear();
122  return StMaker::IMake(GetNumber()+1);
123 }
124 //_____________________________________________________________________________
125 const StChainOpt *StChain::GetChainOpt() const
126 {
127  if (mChainOpt) return mChainOpt;
128  return StMaker::GetChainOpt();
129 }
130 //_____________________________________________________________________________
131 Int_t StChain::EventLoop(Int_t jBeg,Int_t jEnd, StMaker *outMk)
132 {
133  TBenchmark evnt;
134  struct tms cpt;
135  Double_t userCpuTime=0;
136  Double_t systemCpuTime=0;
137  Double_t childUserCpuTime=0;
138  Double_t childSystemCpuTime=0;
139  Double_t gTicks = (Double_t) sysconf(_SC_CLK_TCK);
140  struct timespec ts;
141  int jCur=0,iMake=0;
142 #ifdef STAR_TRACKING
143 #ifdef OLDTRACKING
144 // Add a record to MySQL tracking Db
145  LOG_QA << "Events=" << mNTotal
146  << ",Failed=" << mNFailed
147  << ",StepEventId=" << "'Start'"
148  << ",StepContext=" << "'MemUsed'," << "MessageId='='"
149  << ",ProgrammMessage='" << int(StMemStat::Used())
150  << "'" << endm;
151 
152  LOG_QA << "Events=" << mNTotal
153  << ",Failed=" << mNFailed
154  << ",StepEventId=" << "'Start'"
155  << ",StepContext=" << "'ProgSize'," << "MessageId='='"
156  << ",ProgrammMessage='" << int(StMemStat::ProgSize())
157  << "'" << endm;
158 #else
159 // Add a record to MySQL tracking Db
160 // LOG_QA << "SequenceValue="<< mNTotal
161  LOG_UCM
162  << "StageID=" << "'1'"
163  << ",MessageKey=" << "'MemUsed'"
164  << ",MessageValue='" << int(StMemStat::Used())
165  << "'" << endm;
166 
167 // LOG_QA << "SequenceValue="<<mNTotal
168  LOG_UCM
169  << "StageID=" << "'1'"
170  << ",MessageKey=" << "'ProgSize'"
171  << ",MessageValue='" << int(StMemStat::ProgSize())
172  << "'" << endm;
173 #endif
174 #endif
175  if (jBeg > 1) Skip(jBeg-1);
176  // End of the event loop as soon as the application receives TERM (-15) system signal
177  class teminator : public StTerminateNotified {
178  Bool_t fEnd_of_time;
179  public:
180  teminator() : StTerminateNotified(), fEnd_of_time(kFALSE) {}
181  Bool_t Notify() {return ! fEnd_of_time;}
182  void SetNotifiedCallBack() {
183  fEnd_of_time = true;
184  fgStChain->Error(__FUNCTION__," Job will be terminated soon by the external signal . . . . ");
185  if (GetTopChain()) {
186  fgStChain->Error(__FUNCTION__," Forced Finish . . . . ");
187  GetTopChain()->Finish();
188  }
189  fgStChain->Error(__FUNCTION__,"Terminating . . . . ");
190  gApplication->Terminate(15);
191  }
192  } endOfTime;
193  for (jCur=jBeg; jCur<=jEnd; jCur++) {
194  evnt.Reset(); evnt.Start("QAInfo:");
195  gTicks = (Double_t) sysconf(_SC_CLK_TCK);
196  times(&cpt);
197  userCpuTime = ((Double_t) cpt.tms_utime) / gTicks;
198  systemCpuTime = ((Double_t) cpt.tms_stime) / gTicks;
199  childUserCpuTime = ((Double_t) cpt.tms_cutime) / gTicks;
200  childSystemCpuTime = ((Double_t) cpt.tms_cstime) / gTicks;
201  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts);
202  time_t start_tv_sec = ts.tv_sec;
203  long start_tv_nsec = ts.tv_nsec;
204 
205  Clear();
206  iMake = Make(jCur);
207 
208  if (outMk && iMake == kStErr) {/*outMk->IMake(jCur);*/ mNFailed++;}
209  if (iMake%10 == kStEOF || iMake%10==kStFatal) break;
210  mNTotal++;
211  evnt.Stop("QAInfo:");
212  // evnt.Show("QAInfo:");
213  times(&cpt);
214  userCpuTime = ((Double_t) cpt.tms_utime) / gTicks - userCpuTime;
215  systemCpuTime = ((Double_t) cpt.tms_stime) / gTicks - systemCpuTime;
216  childUserCpuTime = ((Double_t) cpt.tms_cutime) / gTicks - childUserCpuTime;
217  childSystemCpuTime = ((Double_t) cpt.tms_cstime) / gTicks - childSystemCpuTime;
218  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts);
219  time_t stop_tv_sec = ts.tv_sec;
220  long stop_tv_nsec = ts.tv_nsec;
221  if (stop_tv_nsec < start_tv_nsec) { stop_tv_nsec += 1000000000; stop_tv_sec -= 1; }
222  stop_tv_nsec -= start_tv_nsec;
223  stop_tv_sec -= start_tv_sec;
224  double tv_diff = ((double) stop_tv_sec) + (((double) stop_tv_nsec)*1e-9);
225 
226  //
227  // ATTENTION - please DO NOT change the format of the next line,
228  // they are used by our parsers to detect a generation
229  // was succesful and thereafter Catalog the produced files (or
230  // add useful info to our trackijg DB). Thank you.
231  //
232  LOG_QA << Form
233  /*printf */ ("QAInfo: Done with Event [no. %d/run %d/evt. %d/Date.Time %d.%d/sta %d] Real Time = %10.2f seconds Cpu Time = %10.2f seconds",
234  jCur,GetRunNumber(),GetEventNumber(),GetDate(), GetTime(),
235  iMake,evnt.GetRealTime("QAInfo:"),evnt.GetCpuTime("QAInfo:"))
236  << endm;
237  LOG_QA << Form("QAInfo: Cpu Times: user / system / user children / system children = %8.2f / %8.2f / %8.2f / %8.2f seconds (tick = %8.2f, cps = %ld)",
238  userCpuTime,systemCpuTime,childUserCpuTime,childSystemCpuTime,gTicks,CLOCKS_PER_SEC) << endm;
239  LOG_QA << Form("QAInfo: Cpu Times: all threads = %15.9f seconds",tv_diff) << endm;
240 
241 #ifdef STAR_TRACKING
242 #ifdef OLDTRACKING
243  // Add a record to MySQL tracking Db
244  LOG_QA << "Events=" << mNTotal
245  << ",Failed=" << mNFailed
246  << ",StepEventId=" << "'EventFinish'"
247  << ",StepContext=" << "'Cpu'," << "MessageId='='"
248  << ",ProgrammMessage='" << evnt.GetCpuTime("QAInfo:")
249  << "'" << endm;
250 
251  LOG_QA << "Events=" << mNTotal
252  << ",Failed=" << mNFailed
253  << ",StepEventId=" << "'EventFinish'"
254  << ",StepContext=" << "'RealTime'," << "MessageId='='"
255  << ",ProgrammMessage='" << evnt.GetRealTime("QAInfo:")
256  << "'" << endm;
257 #else
258 // Add a record to MySQL tracking Db
259 // LOG_QA << "SequenceValue=" << mNTotal
260  // LOG_UCM
261 // << "StageID=" << "'3'"
262 // << ",MessageKey=" << "'Cpu'"
263 // << ",MessageValue='" << evnt.GetCpuTime("QAInfo:")
264 // << "'" << endm;
265 
266 // LOG_QA << "SequenceValue=" << mNFailed
267  // LOG_UCM
268 // << "StageID=" << "'3'"
269 // << ",MessageKey=" << "'RealTime'"
270 // << ",MessageValue='" << evnt.GetRealTime("QAInfo:")
271 // << "'" << endm;
272 #endif
273 #endif
274  }
275 
276  LOG_QA << Form
277  /*printf */ ("QAInfo:EventLoop completed code %d",iMake)
278  << endm;
279  gSystem->Exec("date");
280  TDatime t;
281  LOG_QA << Form
282  /* printf */ ("QAInfo:Run is finished at Date/Time %i/%i; Total events processed :%i and not completed: %i",
283  t.GetDate(),t.GetTime(),mNTotal,mNFailed)
284  << endm;
285 
286 #ifdef STAR_TRACKING
287 // Add a record to MySQL tracking Db
288 #ifdef OLDTRACKING
289  LOG_QA << "Events=" << mNTotal
290  << ",Failed=" << mNFailed
291  << ",StepEventId=" << "'Finish'"
292  << ",StepContext=" << "'MemUsed'," << "MessageId='='"
293  << ",ProgrammMessage='" << int(StMemStat::Used())
294  << "'" << endm;
295 
296  LOG_QA << "Events=" << mNTotal
297  << ",Failed=" << mNFailed
298  << ",StepEventId=" << "'Finish'"
299  << ",StepContext=" << "'ProgSize'," << "MessageId='='"
300  << ",ProgrammMessage='" << int(StMemStat::ProgSize())
301  << "'" << endm;
302 #else
303 // Add a record to MySQL tracking Db
304 
305 // LOG_QA << "SequenceValue=" << mNTotal
306  // LOG_UCM
307 // << "StageID=" << "'3'"
308 // << ",MessageKey=" << "'MemUsed'"
309 // << ",MessageValue='" << int(StMemStat::Used())
310 // << "'" << endm;
311 
312 // LOG_QA << "SequenceValue=" << mNFailed
313  // LOG_UCM
314 // << "StageID=" << "'3'"
315 // << ",MessageKey=" << "'ProgSize'"
316 // << ",MessageValue='" << int(StMemStat::ProgSize())
317 // << "'" << endm;
318 #endif
319  if (GetLogger()) GetLogger()->Close();
320 
321 #endif
322  fflush(stdout);
323  return iMake;
324 }
325 
326 
327 // $Id: StChain.cxx,v 1.86 2020/02/27 23:22:24 genevb Exp $
328 // $Log: StChain.cxx,v $
329 // Revision 1.86 2020/02/27 23:22:24 genevb
330 // Even more timing/clock info
331 //
332 // Revision 1.85 2020/02/25 15:29:25 genevb
333 // Track complete CPU time usage
334 //
335 // Revision 1.84 2020/02/24 23:20:08 genevb
336 // Add timer for user CPU time (TBenchmark reports user+system)
337 //
338 // Revision 1.83 2019/03/21 18:56:46 jeromel
339 // Added ATTENTION message
340 //
341 // Revision 1.82 2016/05/26 15:27:11 jeromel
342 // Missing init added
343 //
344 // Revision 1.81 2013/07/18 14:05:25 fisyak
345 // Open garbage can at Finish
346 //
347 // Revision 1.80 2011/10/13 20:06:53 perev
348 // Put removed UCM messages back(req JL)
349 //
350 // Revision 1.79 2011/10/11 16:01:48 perev
351 // Remove redundant printouts
352 //
353 // Revision 1.78 2011/06/20 15:13:50 fisyak
354 // Force to call Finish with SIGTERM signal obtained from condor_vacate_job after time limit reached
355 //
356 // Revision 1.77 2010/04/27 21:31:44 fine
357 // remove the logger destruction side effect
358 //
359 // Revision 1.76 2010/04/23 22:40:08 fine
360 // RT #1911. Close the local logger at Finish
361 //
362 // Revision 1.75 2010/03/02 23:09:24 fine
363 // Simplify Close/Terminate interface
364 //
365 // Revision 1.74 2010/03/01 23:37:41 fine
366 // Terminate StChain::EventLoop with the extrenal TERM 15 signal
367 //
368 // Revision 1.73 2009/06/23 19:37:33 fine
369 // replace QA logger with the dedicated UCM one
370 //
371 // Revision 1.72 2009/03/17 20:03:36 perev
372 // Back to StMemSet version
373 //
374 // Revision 1.70 2009/01/26 14:32:33 fisyak
375 // rename TMemStat => StMemStat due clash with ROOT class
376 //
377 // Revision 1.69 2008/06/03 22:33:14 fisyak
378 // Add geometries for y2005g, y2006g and y2007g; use ROOT convention for variable definitions
379 //
380 // Revision 1.68 2008/03/05 00:01:51 fisyak
381 // Move Skip method in base class
382 //
383 // Revision 1.67 2007/10/19 16:18:32 fine
384 // new Db schema from TxCorp
385 //
386 // Revision 1.66 2007/10/17 18:54:04 fine
387 // new Db tracking schema from TxCorp
388 //
389 // Revision 1.65 2007/09/18 20:42:35 fine
390 // Fix the message typo
391 //
392 // Revision 1.64 2007/04/26 20:36:49 perev
393 // Some ChainOpt fixes
394 //
395 // Revision 1.63 2006/07/03 04:13:38 fine
396 // new Job tracking Db activated
397 //
398 // Revision 1.62 2006/07/01 01:19:16 fine
399 // Add new jiob tracking option code
400 //
401 // Revision 1.61 2006/06/05 00:20:59 fine
402 // class the new StMessMgr method to flush the logger buffers
403 //
404 // Revision 1.60 2006/06/04 22:59:00 fine
405 // Change the wonr event tracking code : Finish with the proper EventFinish
406 //
407 // Revision 1.59 2006/05/24 17:33:43 fine
408 // remove the redundant Db fields
409 //
410 // Revision 1.58 2006/05/16 18:54:23 fine
411 // fix StChain and MySql
412 //
413 // Revision 1.57 2006/05/12 18:48:48 fine
414 // reshape jobn tracking. remove the redundand table columns
415 //
416 // Revision 1.56 2006/05/12 18:08:14 fine
417 // fix the MySQLAppender problem and re-shape the trakDb messages
418 //
419 // Revision 1.55 2006/05/09 23:31:20 fine
420 // Reshape the job tracking Db tables and add a few LOQ_QA message to record it with the Job tracking Db
421 //
422 // Revision 1.54 2006/03/28 02:09:19 fine
423 // Add SIMS_USER SUMS_AUTHENTICATED_USER SUMS_JOBNAME
424 //
425 // Revision 1.53 2006/02/05 01:41:23 fine
426 // Add the tracking information from the STAR chain
427 //
428 // Revision 1.52 2005/08/29 21:42:20 fisyak
429 // switch from fBits to fStatus for StMaker control bits
430 //
431 // Revision 1.51 2005/08/12 21:27:31 perev
432 // Remove call output in the case or read error
433 //
434 // Revision 1.50 2004/11/04 22:26:38 fine
435 // populate the package with save/restore the logger and edit some messages
436 //
437 // Revision 1.49 2004/08/03 17:18:46 perev
438 // EventLoop corrected according to current policy
439 //
440 // Revision 1.48 2002/11/26 02:16:39 perev
441 // EventLoop added
442 //
443 // Revision 1.47 2002/03/12 21:19:00 fisyak
444 // Set only one StEvtHddr as default option (due to Embedding)
445 //
446 // Revision 1.46 2002/02/02 23:31:13 jeromel
447 // doxygenized. Added some text for the Make() method.
448 //
449 // Revision 1.45 2001/04/10 21:38:49 perev
450 // Maki(int) --> IMake(int)
451 //
452 // Revision 1.44 2000/11/27 13:31:23 fisyak
453 // Add Production time set
454 //
455 // Revision 1.43 2000/03/23 00:15:21 fine
456 // Adjusted to libSTAR for ROOT 2.24
457 //
458 // Revision 1.42 1999/12/06 01:57:29 fine
459 // Time statistic fixed
460 //
461 // Revision 1.41 1999/12/03 01:24:39 fine
462 // Advanced timer has been introduced
463 //
464 // Revision 1.40 1999/07/14 15:26:18 fine
465 // Context menu MakeEvent method has been introduced
466 //
467 // Revision 1.39 1999/07/13 02:19:33 perev
468 // GetCVS,StEvtHddr,etc...
469 //
470 // Revision 1.38 1999/07/11 20:40:35 perev
471 // Move Clear from StChain to StMaker
472 //
473 // Revision 1.37 1999/06/11 17:45:56 perev
474 // assert StMaker::Streamer to forbid to write it
475 //
476 // Revision 1.36 1999/03/19 20:30:48 perev
477 // GetCVSTag introduced
478 //
479 // Revision 1.35 1999/03/11 01:23:58 perev
480 // new schema StChain
481 //
482 // Revision 1.23 1998/12/21 19:42:50 fisyak
483 // Move ROOT includes to non system
484 //
485 // Revision 1.22 1998/11/29 20:01:09 fisyak
486 // Fix typo with Run/run
487 //
488 // Revision 1.21 1998/11/25 21:58:21 fisyak
489 // Cleanup
490 //
491 // Revision 1.20 1998/11/22 18:28:05 fisyak
492 // Add name of tag
493 //
494 // Revision 1.19 1998/11/19 01:23:56 fine
495 // StChain::MakeDoc has been introduced, StChain::MakeDoc has been fixed (see macros/bfc_doc.C macro
496 //
497 // Revision 1.18 1998/10/31 00:21:30 fisyak
498 // Makers take care about branches
499 //
500 // Revision 1.17 1998/10/07 18:43:57 perev
501 // Add Spy classes for Farm Monitor
502 //
503 // Revision 1.16 1998/10/06 18:00:26 perev
504 // cleanup
505 //
506 // Revision 1.15 1998/09/23 20:22:51 fisyak
507 // Prerelease SL98h
508 //
509 // Revision 1.14 1998/09/16 14:29:33 love
510 // St_DataSetIter.h added
511 //
512 // Revision 1.13 1998/08/26 12:15:08 fisyak
513 // Remove asu & dsl libraries
514 //
515 // Revision 1.12 1998/08/18 14:05:01 fisyak
516 // Add to bfc dst
517 //
518 // Revision 1.11 1998/08/07 19:34:53 fisyak
519 // Add St_run_Maker
520 //
521 // Revision 1.10 1998/07/23 21:03:30 fisyak
522 // Add more comments
523 //
524 // Revision 1.9 1998/07/23 11:32:11 fisyak
525 // Add comments
526 //
527 // Revision 1.8 1998/07/20 15:08:08 fisyak
528 // Add tcl and tpt
529 //
530 // Revision 1.7 1998/07/19 21:16:29 fisyak
531 // add log information
532 //
533 // Revision 1.6 1998/07/19 21:14:48 fisyak
534 // add log information
535 //
Class StTerminateNotified is a abstract visitor to propagate the termination signal It is to provide ...
Definition: FJcore.h:367
virtual Int_t GetNumber() const
STAR methods.
Definition: StMaker.cxx:256
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
static Double_t Used()
Definition: StMemStat.cxx:142
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual void SetBIT(EMakerStatus k)
Maker Status Bits.
Definition: StMaker.h:204
virtual Int_t Make()
Definition: StMaker.cxx:898
static StMaker * fgStChain
pointer to top StChain
Definition: StMaker.h:76
Definition: Stypes.h:43
virtual Int_t Make()
Definition: StChain.cxx:110
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
static Double_t ProgSize()
Definition: StMemStat.cxx:157
virtual Int_t Finish()
Definition: StMaker.cxx:776
Definition: Stypes.h:44