/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
MixRootIOCnvSvc Class Reference

Extension to RootIOCnvSvc for multiple samples to perform mixing huangxt@sdu.edu.cn Thu Feb 19 16:13:07 CST 2009. More...

#include <MixRootIOCnvSvc.h>

Inheritance diagram for MixRootIOCnvSvc:
Inheritance graph
[legend]
Collaboration diagram for MixRootIOCnvSvc:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::map< std::string,
RootInputStream * > 
InputStreamMap
typedef std::map< std::string,
std::string > 
FileMap

Public Member Functions

 MixRootIOCnvSvc (const string &name, ISvcLocator *svc)
virtual ~MixRootIOCnvSvc ()
virtual StatusCode initialize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppint)
virtual void setInputFiles (const vector< string > &inputs)
virtual StatusCode buildStream ()
virtual StatusCode readin (deque< MixHeader > *value)
virtual MixHeader fetchMixHeader ()
virtual void print ()
virtual StatusCode reinitialize ()
virtual StatusCode finalize ()
virtual StatusCode createAddress (long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&newAddr)
virtual StatusCode createAddress (DataObject *obj, RootOutputAddress *&newAddr)
virtual IDataProviderSvc * dataSvc ()
virtual IDataManagerSvc * dataMgrSvc ()
RootOutputStreamoutputStream (const RootOutputAddress &roa)
const std::string & outputFilename (const std::string &tespath)
void associateOutput (const char *filename, const char *streamname)
FileMap fileMap ()
RootInputStreaminputStream (const RootInputAddress &ria)
InputStreamMapinputStreams ()
std::vector< std::string > inputFilenames (const std::string &tespath)
virtual void setInputFiles (const std::vector< std::string > &inputs)=0

Static Public Member Functions

static const InterfaceID & interfaceID ()
static const InterfaceID & interfaceID ()

Protected Member Functions

StatusCode doInitialize ()
void initializeInputStream (const std::string &path, const std::string &filename)
void initializeInputStream (const std::string &path, const std::vector< std::string > &filename_list)

Protected Attributes

std::map< std::string,
std::string > 
m_outputFileMap
std::map< std::string,
RootOutputStream * > 
m_outputStreamMap
std::string m_defaultOutputFilename
std::map< std::string,
std::vector< std::string > > 
m_inputFileMap
InputStreamMap m_inputStreamMap
std::vector< std::string > m_defaultInputFilenames
std::string m_dataSvcName
IDataProviderSvc * m_dataSvc
IDataManagerSvc * m_dataMgr
std::string m_majorIndex
std::string m_minorIndex

Private Member Functions

StatusCode updateBuffer ()
StatusCode doInit ()
double nextTime (double tau)
double flatdis (double maximum)
void performMixing ()

Private Attributes

map< string, vector< string > > m_inputSamples
map< string, RootInputStream * > m_simROMap
map< string, map< string,
RootInputStream * > > 
m_sampleInputStreamMap
double m_days
TimeStamp m_endTime
double m_maximum
double m_maintau
double m_lasttime
TimeStamp m_lastTime
map< string, int > m_fileNum
map< string, int > m_fileindex
map< string, int > m_fileEntryNum
map< string, int > m_fileentries
map< string, int > m_streamentries
map< string, double > m_nod
map< string, double > m_timeTau
deque< MixHeader > * m_firstBuffer
deque< MixHeader > * m_secondBuffer
deque< MixHeader > * m_tesBuffer
MsgStream m_log
MixHeader m_earliestHeader

Detailed Description

Extension to RootIOCnvSvc for multiple samples to perform mixing huangxt@sdu.edu.cn Thu Feb 19 16:13:07 CST 2009.

Definition at line 31 of file MixRootIOCnvSvc.h.


Constructor & Destructor Documentation

MixRootIOCnvSvc::MixRootIOCnvSvc ( const string &  name,
ISvcLocator *  svc 
)

Definition at line 15 of file MixRootIOCnvSvc.cc.

                :RootIOCnvSvc(name, svc),/* m_ranSvc(0),*/ m_log(msgSvc(), "MixRootIOCnvSvc")
{
  declareProperty("SampleInputs" , m_inputSamples   , "Map of sample input files");
  declareProperty("SampleTaus"   , m_timeTau        , "Map of sample Tau");
  //declareProperty("SampleFileNum", m_fileEntryNum   , "Map of sample input files' numbers");
  declareProperty("MixingTime"   , m_days           , "Mix time window");
  declareProperty("BeginTime"    , m_lasttime = 0.0 , "Begin time");
  //declareProperty("RandomSeed"   , m_randomSeed     , "Random Seed of Mixing");
}
MixRootIOCnvSvc::~MixRootIOCnvSvc ( ) [virtual]

Definition at line 26 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "~MixRootIOCnvSvc()"<< endreq;
  
  delete m_firstBuffer;
  delete m_secondBuffer;
  delete m_tesBuffer;
}

Member Function Documentation

StatusCode MixRootIOCnvSvc::initialize ( ) [virtual]

Reimplemented from RootIOCnvSvc.

Definition at line 35 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "initializing @"<< (void*)this<< endreq;
  StatusCode sc = RootIOCnvSvc::initialize();
  if(sc.isFailure()) 
  {
    m_log<< MSG::ERROR<< "parent class failed to initialize"<< endreq;
    return sc;
  }
  
  //m_randomNum.SetSeed(m_randomSeed);
  /*sc = service("RndmGenSvc", m_ranSvc, true);
  if(sc.isFailure())
  {
    m_log<< MSG::ERROR<< "Unable get RndmGenSvc service"<< m_ranSvc<< endreq;
    return sc;
    }*/

  sc = doInit();
  if(sc.isFailure())
  {
    m_log<< MSG::ERROR<< "Something Wrong before mixing."<<endreq;
    return sc;
  }
  return sc;
}
StatusCode MixRootIOCnvSvc::queryInterface ( const InterfaceID &  riid,
void **  ppint 
) [virtual]

Reimplemented from RootIOCnvSvc.

Definition at line 98 of file MixRootIOCnvSvc.cc.

{
  if(IID_IMixingSvc.versionMatch(riid)) 
  {
    m_log<< MSG::DEBUG<< "queryInterface("<<riid<<")-->(IMixingSvc*)"<< (void*)this<< endreq;
    *ppint = (IMixingSvc*)this;
  }
  else 
  {
    return RootIOCnvSvc::queryInterface(riid, ppint);
  }
  addRef();
  return StatusCode::SUCCESS;
}
virtual void MixRootIOCnvSvc::setInputFiles ( const vector< string > &  inputs) [inline, virtual]

Definition at line 39 of file MixRootIOCnvSvc.h.

StatusCode MixRootIOCnvSvc::buildStream ( ) [virtual]

Implements IMixingSvc.

Definition at line 113 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "BuildStream"<< endreq;
  if(m_sampleInputStreamMap.size() == 0) 
  {
    m_log<< MSG::DEBUG<< "Building Streams from mixing sources."<< endreq;
    map<string,vector<string> >::iterator miter, mbegin, mend;
    mbegin = m_inputSamples.begin();
    mend   = m_inputSamples.end();
    m_log<< MSG::DEBUG<< "Initialize the MixBuffer here."<< endreq;
    
    // Initialize the files of each sample
    for(miter = mbegin; miter != mend; miter++) 
    {
      m_inputStreamMap.clear();

      vector<string> files = (*miter).second;
      setInputFiles(files);
      doInitialize();

      m_sampleInputStreamMap[(*miter).first] = inputStreams();
      m_simROMap[(*miter).first] = m_inputStreamMap[DayaBay::SimReadoutHeaderLocation::Default];
    }

    // Initialize the file numbers of each sample
    for(miter = mbegin; miter != mend; miter++)
    {
      int filenum = 0;
      vector<string> files = miter->second;
      for(vector<string>::iterator vit = files.begin(); vit != files.end(); vit++)
      {
        filenum++;
      }
      m_fileNum[miter->first] = filenum;
    }

    // Initialize the file index, file entry and stream entry for each sample
    for(map<string, RootInputStream*>::iterator it = m_simROMap.begin(); it != m_simROMap.end(); it++)
    {
      RootInputStream* ris       = it->second;
      //m_fileindex[it->first]     = flatdis((double)ris->getFiles().size());
      m_fileindex[it->first]     = flatdis((double)m_fileNum[it->first]);
      bool ifjump                = ris->getFiles().jump(m_fileindex[it->first]);
      if(ifjump == false)
      {
        m_log<< MSG::ERROR<< "Can't jump to the specified file!"<< endreq;
        return StatusCode::FAILURE;
      }
      m_fileEntryNum[it->first]  = ris->getFiles().current()->entries();
      m_fileentries[it->first]   = flatdis((double)m_fileEntryNum[it->first]);

      m_log<< MSG::DEBUG<< "Now needing to jump to "<< it->first<< ": "<< m_fileindex[it->first]<< ".root file"<< endreq;
      m_log<< MSG::DEBUG<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;
      m_log<< MSG::DEBUG<< "Now the file total entries is: "<< m_fileEntryNum[it->first]<< endreq;

      ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
      //m_log<< MSG::DEBUG<< "RootInputStream: "<< ris<< endreq;
      m_streamentries[it->first] = ris->getEntry();
      //m_log<< MSG::DEBUG<< "Get the RootInputStream entry."<< endreq;
    }

    //m_log<< MSG::DEBUG<< "Here."<< endreq;
    // Initialize the mix buffer
    m_tesBuffer    = new deque<MixHeader>();
    m_firstBuffer  = new deque<MixHeader>();
    m_secondBuffer = new deque<MixHeader>();
    //print();

    m_log<< MSG::DEBUG<< "TESBuffer Size    = "<< m_tesBuffer->size()<< endreq;
    m_log<< MSG::DEBUG<< "FirstBuffer Size  = "<< m_firstBuffer->size()<< endreq;
    m_log<< MSG::DEBUG<< "SecondBuffer Size = "<< m_secondBuffer->size()<< endreq;
    m_log<< MSG::DEBUG<< "SteamMap Size     = "<< m_sampleInputStreamMap.size()<< "/"<< m_simROMap.size()<< endreq;
    
    // Initialize the maintau, the time nod by the samples
    for(map<string, RootInputStream*>::iterator mit = m_simROMap.begin(); mit != m_simROMap.end(); mit++)
    { 
      m_maintau += 1/m_timeTau[mit->first];
      m_nod[mit->first] = m_maintau;
      m_log<< MSG::DEBUG<< "m_nod["<< mit->first<< "] is: "<< m_nod[mit->first]<< endreq;
      m_maximum  = m_maintau;
    }
    m_maintau = 1/m_maintau;
    m_log<< MSG::DEBUG<< "The main tau is: "<< m_maintau<< endreq;

    //m_totalentries = m_days*86400.0/m_maintau;
    //m_log<< MSG::DEBUG<< "The Total entries are: "<< m_totalentries<< endreq;
    m_log<< MSG::DEBUG<< "The end time is: "<< m_endTime.GetSec()
         << "--"<< m_endTime.GetNanoSec()<< endreq;
  }

  //if (m_uniSample.initialize(m_ranSvc, Rndm::Flat(0.0, m_maximum)).isFailure()) 
  //{
  //  m_log<< MSG::FATAL<< "Failed to initialize uniform random numbers" << endreq;
  //  return StatusCode::FAILURE;
  //}
  //if (m_exp.initialize(m_ranSvc, Rndm::Exponential(m_maintau)).isFailure()) 
  //{
  //  m_log<< MSG::FATAL<< "Failed to initialize Gaussian random numbers" << endreq;
  //  return StatusCode::FAILURE;
  //}

  StatusCode sc = updateBuffer();
  return sc;
}
StatusCode MixRootIOCnvSvc::readin ( deque< MixHeader > *  value) [virtual]

Definition at line 218 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "Read Sample into deque!"<< endreq;

  double randomnum = flatdis(m_maximum);
  //double randomnum = m_uniSample();
  map<string, RootInputStream*>::iterator it;

  //Loop on the samples
  for(it = m_simROMap.begin(); it != m_simROMap.end(); ) 
  {
    if(randomnum < m_nod[it->first])
    {
      // SetEntry to find that if reaching the end of a file
      RootInputStream* ris = it->second;
      RootInputFile*   rif = ris->getFiles().current();
      
      if(m_fileentries[it->first] >= rif->entries())
      {
        /*m_fileindex[it->first]++;
          m_log<< MSG::DEBUG<< "After resetting, the file index is: "<< m_fileindex[it->first]<< endreq;*/
        m_fileindex[it->first]   = flatdis((double)m_fileNum[it->first]);
        bool ifjump              = ris->getFiles().jump(m_fileindex[it->first]);
        if(ifjump == false)
        {
          m_log<< MSG::ERROR<< "Can't jump to the specified file!"<< endreq;
          return StatusCode::FAILURE;
        }
        m_fileEntryNum[it->first]  = ris->getFiles().current()->entries();
        m_fileentries[it->first] = flatdis((double)m_fileEntryNum[it->first]);
        //m_log<< MSG::DEBUG<< "After resetting, the file entry is: "<< m_fileentries[it->first]<< endreq;
        //m_fileindex[it->first]   = flatdis((double)ris->getFiles().size());
 
        m_log<< MSG::DEBUG<< "Now needing to jump to "<< it->first<< ": "<< m_fileindex[it->first]<< ".root file"<< endreq;
        m_log<< MSG::DEBUG<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;
        m_log<< MSG::DEBUG<< "Now the file total entries is: "<< m_fileEntryNum[it->first]<< endreq;
        ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
        m_streamentries[it->first] = ris->getEntry();
        rif = ris->getFiles().current();
      }

      // SetEntry 
      m_log << MSG::DEBUG<< "SetEntry manually: "<< " The sample: "<< it->first
            << "  File entry: "     << m_fileentries[it->first]
            << "  Stream entry: "   << m_streamentries[it->first]
            << "  RootInputStream: "<< ris
            << "  Old entry: "      << ris->getEntry()<< endreq;
      ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
      rif = ris->getFiles().current();
      //bool ifend = ris->setEntry(m_streamentries[it->first] ,true);
      //if(ifend == false) return StatusCode::FAILURE;

      m_log<< MSG::DEBUG<< "Now the file is: "      << rif->filename()         << endreq;
      m_log<< MSG::DEBUG<< "Now the file index is: "<< m_fileindex[it->first]  << endreq;
      m_log<< MSG::DEBUG<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;

      // Read in Event
      m_log << MSG::DEBUG<< "Casting TObject to PerSimReadoutHeader."<< endreq;
      PerSimReadoutHeader* psro = (PerSimReadoutHeader*)((void*)(ris->obj()));
      m_log << MSG::DEBUG<< "======= PerSimReadoutHeader: "<< psro<< endreq;

      //Test the PerSimReadoutHeader's InputHeaders
      //vector<PerRef> iheaders = psro->inputHeaders;
      //m_log<< MSG::DEBUG<< "InputHeader's vector size: "<< iheaders.size()<< endreq;

      vector<PerSimReadout*> ro; 
      if(psro != NULL) 
      { 
        ro = psro->readouts;

        // Important parameters     
        TimeStamp newtime(nextTime(m_maintau));
        //TimeStamp newtime(m_exp());
        TimeStamp pretime = m_lastTime;

        m_log<< MSG::DEBUG<< "Last time: "<< m_lastTime.GetSeconds()<< "s"<< endreq;
        m_log<< MSG::DEBUG<< "Generte new time["<< newtime.GetSeconds()<< "sec] for sample ["<< it->first<< "]"<< endreq;
     
        if(ro.size() == 0) // There is an empty event
        {
          m_log<< MSG::DEBUG<< "There is no Readouts in SimReadoutHeader!"<< endreq;
          m_fileentries[it->first]++;
          m_streamentries[it->first]++;
          m_lastTime.Add(newtime);
          m_log<< MSG::DEBUG<< "Current time: "<< m_lastTime.GetSeconds()<< "s"<< endreq;
          m_log<< MSG::DEBUG<< "Set new file entry as: "<< m_fileentries[it->first]<< endreq;

          if(m_lastTime >= m_endTime)
          {
            m_log<< MSG::DEBUG<< "Current time: "<< m_lastTime.GetSec()<< "--"<< m_lastTime.GetNanoSec()
                 <<" has exceeded the time limitation: "<< m_endTime.GetSec()<< "--"<< m_endTime.GetNanoSec()
                 << endreq;
      m_log<< MSG::INFO<< "Current time: "<< m_lastTime
        << " has exceeded the time limitation: "<< m_endTime
        << ". So this job is finished."
        << endreq;
            return StatusCode::FAILURE;
          }

          //resample again
          randomnum = flatdis(m_maximum);
          it = m_simROMap.begin();
          continue;
        }
        else 
        {
          m_log<< MSG::DEBUG<< "PerSimReadout from "<< it->first<< " with "<< ro.size()<< " PerSimReadouts"<< endreq;

          pretime.Add(newtime);
          m_lastTime = pretime;
          if(m_lastTime >= m_endTime)
          {
            m_log<< MSG::WARNING<< "Current time: "<< m_lastTime.GetSec()<< "--"<< m_lastTime.GetNanoSec()
                 <<" has exceeded the time limitation: "<< m_endTime.GetSec()<< "--"<< m_endTime.GetNanoSec()
                 << endreq;
            return StatusCode::FAILURE;
          }

          vector<MixHeader> mixVec;

          m_log<< MSG::DEBUG<< "Generte new time["<< newtime.GetSeconds()<< "sec] for sample ["<< it->first<< "]"<< endreq;
       
          // Distinguish subevents
          for(vector<PerSimReadout*>::size_type i = 0; i != ro.size(); i++) 
          {
            m_log << MSG::DEBUG<< "PmtChannelSize is: "
                  << (static_cast<PerReadoutPmtCrate*>(ro[i]->readout))->perChannelReadouts.size()
                  << " in: "<< ro[i]->readout<< endreq;
            // Copy the variables in PerReadout
            MixHeader             mh;
            PerReadout*           pro  = new PerReadoutPmtCrate();
            PerReadoutHeader*     proh = new PerReadoutHeader();
            
            pro->detector           = ro[i]->readout->detector;
            pro->triggerType        = ro[i]->readout->triggerType;
            pro->triggerNumber      = ro[i]->readout->triggerNumber;
            pro->triggerTimeSec     = ro[i]->readout->triggerTimeSec;
            pro->triggerTimeNanoSec = ro[i]->readout->triggerTimeNanoSec;

            // Deep-Copy the variables in PerReadoutPmtCrate
            vector<PerReadoutPmtChannel*> PmtVec;
            vector<PerReadoutPmtChannel*> pmtvec = (static_cast<PerReadoutPmtCrate*>(ro[i]->readout))->perChannelReadouts;
            for(vector<PerReadoutPmtChannel*>::iterator pit = pmtvec.begin(); pit != pmtvec.end(); pit++)
            {
              PerReadoutPmtChannel* propc = new PerReadoutPmtChannel();
              propc->tdc             = (*pit)->tdc;
              propc->adc             = (*pit)->adc;
              propc->mode            = (*pit)->mode;
              propc->adcCycle        = (*pit)->adcCycle;
              propc->adcRange        = (*pit)->adcRange;
              propc->pedestal        = (*pit)->pedestal;
              propc->channelId       = (*pit)->channelId;
              propc->tdcHitCount     = (*pit)->tdcHitCount;
              propc->waveAdcLow      = (*pit)->waveAdcLow;
              propc->waveAdcHigh     = (*pit)->waveAdcHigh;
              propc->waveAdcCycle    = (*pit)->waveAdcCycle;
              
              PmtVec.push_back(propc);
            }
            (static_cast<PerReadoutPmtCrate*>(pro))->perChannelReadouts = PmtVec;

            m_log<< MSG::DEBUG<< "TriggerSec: "     << pro->triggerTimeSec
                             << " TriggerNanoSec: "<< pro->triggerTimeNanoSec<< endreq; 
            proh->readout  = pro;
            m_log<< MSG::DEBUG<< "TriggerSec: "     << proh->readout->triggerTimeSec
                             << " TriggerNanoSec: "<< proh->readout->triggerTimeNanoSec<< endreq;

            //proh->earliest = psro->earliest;
            //proh->latest   = psro->latest;
            TimeStamp trigTime(proh->readout->triggerTimeSec, proh->readout->triggerTimeNanoSec);
            proh->earliest = trigTime;
            proh->latest   = trigTime;
            m_log<< MSG::DEBUG<< "The earliest TimeStamp: "<< proh->earliest
                             << " The latest TimeStamp: " << proh->latest<< endreq;

            proh->context  = psro->context;
            Detector det(pro->detector);
            proh->context.SetDetId(det.detectorId());
            proh->context.SetTimeStamp(trigTime);
            m_log<< MSG::DEBUG<< "The TimeStamp in Context: "<< proh->context.GetTimeStamp()<< endreq;
            m_log<< MSG::DEBUG<< "The DetectorId in Context: "<< proh->context.GetDetId()
                 << "("<< DetectorId::AsString(proh->context.GetDetId())<< ")"<< endreq;

            //Create MixHeader and fill the mixbuffer
            mh.hder   = proh;
            mh.sample = it->first;
            mh.entry  = m_streamentries[it->first];
   
            mixVec.push_back(mh);
          }

          MixHeader   firstHeader;
          TimeStamp*  ftemp     = new TimeStamp(0.0);
          //double*     temp      = new double(0.0);
          TimeStamp*  TotalTime = new TimeStamp(0.0);
          (*TotalTime) = pretime;
          // Find the earliest subevent
          for(vector<MixHeader>::size_type j = 0; j != mixVec.size(); j++)
          {
            TimeStamp rotime(mixVec[j].hder->readout->triggerTimeSec, mixVec[j].hder->readout->triggerTimeNanoSec);
            //double rotime = mixVec[j].hder->readout->triggerTimeSec + mixVec[j].hder->readout->triggerTimeNanoSec/1.0e9;
            if(j == 0 || *ftemp > rotime )
            {
              *ftemp = rotime;
              firstHeader = mixVec[j];
            }
          }
        
          // Reset the subevnets' triggertime and time window
          /*double de1 = firstHeader.hder->readout->triggerTimeSec - firstHeader.hder->earliest.GetSec()
                     + (firstHeader.hder->readout->triggerTimeNanoSec - firstHeader.hder->earliest.GetNanoSec())/1.0e9;
          double de2 = firstHeader.hder->latest.GetSec() - firstHeader.hder->readout->triggerTimeSec
                     + (firstHeader.hder->latest.GetNanoSec() - firstHeader.hder->readout->triggerTimeNanoSec)/1.0e9;
          */
          
          TimeStamp fde1 = *ftemp - firstHeader.hder->earliest;
          TimeStamp fde2 = firstHeader.hder->latest - *ftemp;

          for(vector<MixHeader>::size_type k = 0; k != mixVec.size(); k++)
          {
            if(mixVec[k] != firstHeader)
            {
              /*double de1 = mixVec[k].hder->readout->triggerTimeSec - mixVec[k].hder->earliest.GetSec()
                         + (mixVec[k].hder->readout->triggerTimeNanoSec - mixVec[k].hder->earliest.GetNanoSec())/1.0e9;
              double de2 = mixVec[k].hder->latest.GetSec() - mixVec[k].hder->readout->triggerTimeSec
                         + (mixVec[k].hder->latest.GetNanoSec() - mixVec[k].hder->readout->triggerTimeNanoSec)/1.0e9;
              */
              TimeStamp ktemp(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
              TimeStamp kde1 = ktemp - mixVec[k].hder->earliest;
              TimeStamp kde2 = mixVec[k].hder->latest - ktemp;

              mixVec[k].hder->readout->triggerTimeSec     -= firstHeader.hder->readout->triggerTimeSec;
              mixVec[k].hder->readout->triggerTimeNanoSec -= firstHeader.hder->readout->triggerTimeNanoSec;

              //double deltime = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9;
              //TimeStamp TriggerTime(deltime + TotalTime->GetSec() + TotalTime->GetNanoSec()/1.0e9);
              TimeStamp deltime(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
              deltime.Add((*TotalTime));
              TimeStamp TriggerTime = deltime;

              mixVec[k].hder->readout->triggerTimeSec      = TriggerTime.GetSec();
              mixVec[k].hder->readout->triggerTimeNanoSec  = TriggerTime.GetNanoSec();
  
              //double t = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9 - de1;
              TimeStamp ktempe(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
              ktempe = ktempe - kde1;
              mixVec[k].hder->earliest = ktempe;
              //t = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9 + de2;
              TimeStamp ktempt(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
              ktempt.Add(kde2);
              mixVec[k].hder->latest   = ktempt;
              (mixVec[k].hder->context).SetTimeStamp(mixVec[k].hder->earliest);          
            }
          }
                   
          firstHeader.hder->readout->triggerTimeSec     = TotalTime->GetSec();
          firstHeader.hder->readout->triggerTimeNanoSec = TotalTime->GetNanoSec();         

          //double t = firstHeader.hder->readout->triggerTimeSec + firstHeader.hder->readout->triggerTimeNanoSec/1.0e9 - de1;
          TimeStamp ftempe(firstHeader.hder->readout->triggerTimeSec, firstHeader.hder->readout->triggerTimeNanoSec);
          ftempe = ftempe - fde1;
          firstHeader.hder->earliest = ftempe;
          TimeStamp ftempt(firstHeader.hder->readout->triggerTimeSec, firstHeader.hder->readout->triggerTimeNanoSec);
          ftempt.Add(fde2);
          firstHeader.hder->latest   = ftempt;
          (firstHeader.hder->context).SetTimeStamp(firstHeader.hder->earliest);
         
          delete ftemp;
          delete TotalTime;

          m_fileentries[it->first]++;
          m_streamentries[it->first]++;
          vector<MixHeader>::iterator pit;
          for(pit = mixVec.begin(); pit != mixVec.end(); pit++)
          {
            value->push_back(*pit);
          }
        }
      }
      else 
      {
        m_log<< MSG::ERROR<< "Can't retrive pointer to PerSimReadoutHeader : Terminated!"<< endreq;
        return StatusCode::FAILURE;
      }
      break;    
    }
    it++;
  }
  deque<MixHeader>::iterator dbeg, dend;
  dbeg = value->begin(); dend = value->end();
  sort(dbeg, dend);
  return StatusCode::SUCCESS;
}
MixHeader MixRootIOCnvSvc::fetchMixHeader ( ) [virtual]

Implements IMixingSvc.

Definition at line 620 of file MixRootIOCnvSvc.cc.

{
  m_log<<MSG::DEBUG<<"Return  one pointer to PerReadoutHeader."<<endreq;
  return m_earliestHeader;
}
void MixRootIOCnvSvc::print ( ) [virtual]

Implements IMixingSvc.

Definition at line 626 of file MixRootIOCnvSvc.cc.

{
  MsgStream m_log(msgSvc(), "MixRootIOCnvSvc");
  m_log<< MSG::DEBUG<< "MixRootIOCnvSvc::print()"<< endreq;

  deque<MixHeader>::iterator fit;

  m_log<< MSG::DEBUG<< "FirstBuffer: "<< m_firstBuffer<< " Size: "<< m_firstBuffer->size()<< endreq; 
  for(fit = m_firstBuffer->begin(); fit != m_firstBuffer->end(); fit++)
  {
    m_log<< MSG::DEBUG<< fit->sample<<" : "<< fit->entry<< "--";
    m_log<< MSG::DEBUG<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
  }
  
  m_log<< MSG::DEBUG<< "SecondBuffer: "<< m_secondBuffer<< " Size: "<< m_secondBuffer->size()<< endreq; 
  for(fit = m_secondBuffer->begin(); fit != m_secondBuffer->end(); fit++)
  {
    m_log<< MSG::DEBUG<< fit->sample<<" : "<< fit->entry<< "--";
    m_log<< MSG::DEBUG<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
  }
  
  m_log<< MSG::DEBUG<< "TESBuffer: "<< m_tesBuffer<< " Size: "<< m_tesBuffer->size()<< endreq; 
  for(fit = m_tesBuffer->begin(); fit != m_tesBuffer->end(); fit++)
  {
    m_log<< MSG::DEBUG<< fit->sample<<" : "<< fit->entry<< "--";
    m_log<< MSG::DEBUG<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
  }  
}
StatusCode MixRootIOCnvSvc::updateBuffer ( ) [private]

Definition at line 512 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "UpdateBuffer"<< endreq;
  StatusCode sc;

  if(m_tesBuffer->size() != 0)
  {
    m_earliestHeader = m_tesBuffer->front();
    m_tesBuffer->pop_front();

    m_log<< MSG::DEBUG<< "m_currentEntry = " << m_earliestHeader.entry<<  endreq;
    m_log<< MSG::DEBUG<< "m_currentSample = "<< m_earliestHeader.sample<< endreq;

    m_inputStreamMap = m_sampleInputStreamMap[m_earliestHeader.sample];

    setInputFiles(m_inputSamples[m_earliestHeader.sample]);
    //print();

    return StatusCode::SUCCESS;
  }
  else
  { 
    if(m_firstBuffer->size() == 0 && m_secondBuffer->size() == 0) 
    { 
      sc = readin(m_firstBuffer);
      sc = readin(m_secondBuffer);
    }
    else if(m_firstBuffer->size() != 0 && m_secondBuffer->size() == 0)
    {
      sc = readin(m_secondBuffer);
    }
    else 
    { 
      m_log<< MSG::ERROR<< "There are some errors! "<< endreq;
      return StatusCode::FAILURE;
    }
    //print();
    if(sc == StatusCode::FAILURE) return StatusCode::FAILURE;
    performMixing();
    //print();
    return updateBuffer();
  }

  return StatusCode::SUCCESS;
}       
StatusCode MixRootIOCnvSvc::doInit ( ) [private]

Definition at line 62 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "reset some variables at begining."<< endreq;
  if(m_inputSamples.size() != m_timeTau.size() || m_timeTau.size() == 0) 
  {
    return StatusCode::FAILURE;
  }
  else
  {
    map<string, double>::iterator itt, tend = m_timeTau.end();
    map<string, vector<string> >::iterator iter; 
    for(itt = m_timeTau.begin(); itt != tend; itt++) 
    {
      iter = m_inputSamples.find(itt->first);
      if(iter == m_inputSamples.end()) 
      {
        m_log<< MSG::DEBUG<< "Configuration is not correct for mixing"<< endreq;
        return StatusCode::FAILURE;
      }
      m_fileNum[itt->first]       = 0;
      m_fileindex[itt->first]     = 0;
      m_fileentries[itt->first]   = 0;
      m_fileEntryNum[itt->first]  = 0;
      m_streamentries[itt->first] = 0;
    }
    m_maintau  = 0.0;
    m_maximum  = 0.0;
    TimeStamp  lastTime(m_lasttime);
    double mixTinterval = 86400.0*m_days;
    TimeStamp  endTime(m_lasttime + mixTinterval);
    m_endTime  = endTime;
    m_lastTime = lastTime;
  }
  return StatusCode::SUCCESS;
}
double MixRootIOCnvSvc::nextTime ( double  tau) [private]

Definition at line 606 of file MixRootIOCnvSvc.cc.

{
  //Rndm::Numbers exponential(m_ranSvc, Rndm::Exponential(tau));
  //if(exponential)  return  exponential();
  //else 
  //{ 
  //m_log<< MSG::ERROR<< "Random Engine was not correct."<< endreq;
  //return 0.0; 
  //}
  //double tempnum = m_randomNum.Exp(tau);
  double tempnum = gRandom->Exp(tau);
  return tempnum;
}
double MixRootIOCnvSvc::flatdis ( double  maximum) [private]

Definition at line 592 of file MixRootIOCnvSvc.cc.

{
  //Rndm::Numbers flat(m_ranSvc, Rndm::Flat(0.0, maximum));
  //if(flat) return flat();
  //else
  //{
  //m_log<< MSG::ERROR<< "Random Engine was not correct."<< endreq;
  //return 0.0;
  //}
  //double tempnum = m_randomNum.Uniform(0.0, maximum);
  double tempnum = gRandom->Uniform(0.0, maximum);
  return tempnum;
}
void MixRootIOCnvSvc::performMixing ( ) [private]

Definition at line 558 of file MixRootIOCnvSvc.cc.

{
  m_log<< MSG::DEBUG<< "This is a place to perform mixing."<< endreq;

  if(m_firstBuffer->back() < m_secondBuffer->front())
  {
    deque<MixHeader>* tempbuffer;
    tempbuffer     = m_tesBuffer;
    m_tesBuffer    = m_firstBuffer;
    m_firstBuffer  = m_secondBuffer;
    m_secondBuffer = tempbuffer;  
  }
  else
  {
    deque<MixHeader>::iterator pos, dbegf, dendf, dbegs, dends, dbegt;
    dbegf = m_firstBuffer->begin();  dendf = m_firstBuffer->end();
    dbegs = m_secondBuffer->begin(); dends = m_secondBuffer->end();
    pos = lower_bound(dbegf, dendf, m_secondBuffer->front());

    m_tesBuffer->resize(distance(pos, dendf) + m_secondBuffer->size());
    dbegt = m_tesBuffer->begin();
    merge(pos, dendf, dbegs, dends, dbegt);

    m_firstBuffer->resize(distance(dbegf, pos));
    m_secondBuffer->clear();

    deque<MixHeader>* tempbuffer;
    tempbuffer    = m_tesBuffer;
    m_tesBuffer   = m_firstBuffer;
    m_firstBuffer = tempbuffer;
  }
  m_log<< MSG::DEBUG<< "Succesffully perform mixing."<<endreq;
}
static const InterfaceID& IMixingSvc::interfaceID ( ) [inline, static, inherited]

Definition at line 22 of file IMixingSvc.h.

{ return  IID_IMixingSvc; }
virtual void IMixingSvc::setInputFiles ( const std::vector< std::string > &  inputs) [pure virtual, inherited]

Member Data Documentation

map<string, vector<string> > MixRootIOCnvSvc::m_inputSamples [private]

Definition at line 54 of file MixRootIOCnvSvc.h.

Definition at line 55 of file MixRootIOCnvSvc.h.

map<string, map<string, RootInputStream*> > MixRootIOCnvSvc::m_sampleInputStreamMap [private]

Definition at line 56 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_days [private]

Definition at line 59 of file MixRootIOCnvSvc.h.

Definition at line 60 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_maximum [private]

Definition at line 62 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_maintau [private]

Definition at line 63 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_lasttime [private]

Definition at line 64 of file MixRootIOCnvSvc.h.

Definition at line 65 of file MixRootIOCnvSvc.h.

map<string, int> MixRootIOCnvSvc::m_fileNum [private]

Definition at line 68 of file MixRootIOCnvSvc.h.

map<string, int> MixRootIOCnvSvc::m_fileindex [private]

Definition at line 69 of file MixRootIOCnvSvc.h.

map<string, int> MixRootIOCnvSvc::m_fileEntryNum [private]

Definition at line 70 of file MixRootIOCnvSvc.h.

map<string, int> MixRootIOCnvSvc::m_fileentries [private]

Definition at line 72 of file MixRootIOCnvSvc.h.

map<string, int> MixRootIOCnvSvc::m_streamentries [private]

Definition at line 73 of file MixRootIOCnvSvc.h.

map<string, double> MixRootIOCnvSvc::m_nod [private]

Definition at line 74 of file MixRootIOCnvSvc.h.

map<string, double> MixRootIOCnvSvc::m_timeTau [private]

Definition at line 75 of file MixRootIOCnvSvc.h.

Definition at line 77 of file MixRootIOCnvSvc.h.

Definition at line 78 of file MixRootIOCnvSvc.h.

Definition at line 79 of file MixRootIOCnvSvc.h.

MsgStream MixRootIOCnvSvc::m_log [mutable, private]

Definition at line 81 of file MixRootIOCnvSvc.h.

Definition at line 88 of file MixRootIOCnvSvc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:15:21 for Mixing by doxygen 1.7.4