StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2DbConfig.cxx
1 
2 
3 #include <string>
4 #include <iostream>
5 #include <fstream>
6 #include <cassert>
7 
8 #include "L2DbConfig.h"
9 using namespace std;
10 // ---------------------------------------------------------------------------
11 L2DbConfig::L2DbConfig( const Char_t *fname )
12 {
13  mFilename=fname;
14  ifstream inFile(fname, ifstream::in);
15  if ( !inFile )
16  {
17  std::cout << "Problem reading in L2EmcDb configuration from " << fname << std::endl;
18  assert(2+2==5);
19  }
20  // check file for errors
21 
22  printf("L2DbConfig::L2DbConfig, opened =%s=\n", fname);
23  while ( !inFile.eof() )
24  {
25  L2DbTime c;
26  double timeOld=c.getFullStartTime();
27  c.read(inFile);
28  if ( c.comment() ) continue;
29  mConfig.push_back(c);
30  c.print();
31  assert(c.getFullStartTime() < c.getFullFinishTime());
32  //tmp assert(c.getFullStartTime() > timeOld);
33  timeOld=c.getFullStartTime();
34  }
35  std::cout << Form("L2DbConfig::Read in %i records from=%s=, done",mConfig.size(),fname) << std::endl;
36 
37 
38 }
39 
40 //=================================================================
41 L2DbTime *L2DbConfig::getConfiguration( Int_t date, Int_t time, const Char_t *tag )
42 {
43  std::cout << "L2DbConfig:: Get configuration for date=" << date << " time=" << time <<" tag=" <<(tag? tag :"")<<"="<<std::endl;
44  for ( UInt_t ii=0;ii<mConfig.size();ii++ )
45  {
46  if ( mConfig[ii].valid(date,time) )
47  {
48  if ( !tag ) return &mConfig[ii];
49  if ( mConfig[ii].getTag().Contains(tag) ) return &mConfig[ii];
50  }
51  }
52  return 0; // could not find a match
53 }
54