| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

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:

[legend]
Collaboration diagram for MixRootIOCnvSvc:
[legend]
List of all members.

Public Types

typedef std::vector< WorkerEntry > Workers
 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
 CONVERSIONSVC_NO_ERROR
 NO_CONVERTER
 INVALID_ADDRESS
 INVALID_OBJECT
 NO_MEMORY
 BAD_STORAGE_TYPE
 NO_SOURCE_OBJECT
 ICONVERSIONSVC_LAST_ERROR
typedef std::map< std::string,
RootInputStream * > 
InputStreamMap
typedef std::map< std::string,
std::string > 
FileMap
enum  Status
enum  Status

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 long entries ()
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 StatusCode createAddress (long svc_type, const CLID &clid, const std::string &refAddress, IOpaqueAddress *&refpAddress)
virtual IDataProviderSvcdataSvc ()
virtual IDataManagerSvcdataMgrSvc ()
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)
bool isReadoutForced () const
virtual long repSvcType () const
const CLIDobjType () const
virtual StatusCode setDataProvider (IDataProviderSvc *pService)
virtual IDataProviderSvcdataProvider () const
virtual StatusCode setConversionSvc (IConversionSvc *svc)
virtual IConversionSvcconversionSvc () const
virtual StatusCode setAddressCreator (IAddressCreator *creator)
virtual IAddressCreatoraddressCreator () const
virtual StatusCode createObj (IOpaqueAddress *pAddress, DataObject *&refpObject)
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateObj (IOpaqueAddress *pAddress, DataObject *refpObject)
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateRep (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode addConverter (const CLID &clid)
virtual StatusCode addConverter (IConverter *pConverter)
virtual StatusCode removeConverter (const CLID &clid)
virtual IConverterconverter (const CLID &wanted)
virtual StatusCode connectOutput (const std::string &outputFile, const std::string &openMode)
virtual StatusCode connectOutput (const std::string &output)
virtual StatusCode commitOutput (const std::string &output, bool do_commit)
virtual StatusCode convertAddress (const IOpaqueAddress *pAddress, std::string &refAddress)
virtual StatusCode updateServiceState (IOpaqueAddress *pAddress)
virtual unsigned long addRef ()
virtual unsigned long release ()
virtual const std::string & name () const
virtual const InterfaceIDtype () const
virtual StatusCode configure ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode terminate ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual StatusCode restart ()
virtual StatusCode sysInitialize ()
virtual StatusCode sysStart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
ISvcLocatorserviceLocator () const
IMessageSvcmsgSvc ()
IMessageSvcmsgSvc () const
IMessageSvcmessageService ()
IMessageSvcmessageService () const
StatusCode setProperties ()
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IAuditorSvcauditorSvc () const
virtual void setInputFiles (const std::vector< std::string > &inputs)=0

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
 CONVERSIONSVC_NO_ERROR
 NO_CONVERTER

Protected Member Functions

virtual IAddressCreatoraddressCreator ()
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)
virtual IConvertercreateConverter (long typ, const CLID &clid, const ICnvFactory *fac)
virtual StatusCode configureConverter (long typ, const CLID &clid, IConverter *cnv)
virtual StatusCode initializeConverter (long typ, const CLID &clid, IConverter *cnv)
virtual StatusCode activateConverter (long typ, const CLID &clid, IConverter *cnv)
virtual void loadConverter (DataObject *pObject)
StatusCode makeCall (int typ, bool ignore_add, bool ignore_obj, bool update, IOpaqueAddress *&pAddress, DataObject *&pObject)
int outputLevel () const

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
IDataProviderSvcm_dataSvc
IDataManagerSvcm_dataMgr
IAddressCreatorm_addressCreator
long m_type
Workersm_workers
IntegerProperty m_outputLevel
Gaudi::StateMachine::State m_state
Gaudi::StateMachine::State m_targetState
IMessageSvcm_messageSvc

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
long m_totalentries
double m_days
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

Friends

friend friend class ServiceManager

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.

00016                 :RootIOCnvSvc(name, svc),/* m_ranSvc(0),*/ m_log(msgSvc(), "MixRootIOCnvSvc")
00017 {
00018   declareProperty("SampleInputs" , m_inputSamples   , "Map of sample input files");
00019   declareProperty("SampleTaus"   , m_timeTau        , "Map of sample Tau");
00020   //declareProperty("SampleFileNum", m_fileEntryNum   , "Map of sample input files' numbers");
00021   declareProperty("MixingTime"   , m_days           , "Mix time window");
00022   declareProperty("BeginTime"    , m_lasttime = 0.0 , "Begin time");
00023   //declareProperty("RandomSeed"   , m_randomSeed     , "Random Seed of Mixing");
00024 }

MixRootIOCnvSvc::~MixRootIOCnvSvc (  )  [virtual]

Definition at line 26 of file MixRootIOCnvSvc.cc.

00027 {
00028   m_log<< MSG::DEBUG<< "~MixRootIOCnvSvc()"<< endreq;
00029   
00030   delete m_firstBuffer;
00031   delete m_secondBuffer;
00032   delete m_tesBuffer;
00033 }


Member Function Documentation

StatusCode MixRootIOCnvSvc::initialize (  )  [virtual]

Reimplemented from RootIOCnvSvc.

Definition at line 35 of file MixRootIOCnvSvc.cc.

00036 {
00037   m_log<< MSG::DEBUG<< "initializing @"<< (void*)this<< endreq;
00038   StatusCode sc = RootIOCnvSvc::initialize();
00039   if(sc.isFailure()) 
00040   {
00041     m_log<< MSG::ERROR<< "parent class failed to initialize"<< endreq;
00042     return sc;
00043   }
00044   
00045   //m_randomNum.SetSeed(m_randomSeed);
00046   /*sc = service("RndmGenSvc", m_ranSvc, true);
00047   if(sc.isFailure())
00048   {
00049     m_log<< MSG::ERROR<< "Unable get RndmGenSvc service"<< m_ranSvc<< endreq;
00050     return sc;
00051     }*/
00052 
00053   sc = doInit();
00054   if(sc.isFailure())
00055   {
00056     m_log<< MSG::ERROR<< "Something Wrong before mixing."<<endreq;
00057     return sc;
00058   }
00059   return sc;
00060 }

StatusCode MixRootIOCnvSvc::queryInterface ( const InterfaceID riid,
void **  ppint 
) [virtual]

Reimplemented from RootIOCnvSvc.

Definition at line 95 of file MixRootIOCnvSvc.cc.

00096 {
00097   if(IID_IMixingSvc.versionMatch(riid)) 
00098   {
00099     m_log<< MSG::DEBUG<< "queryInterface("<<riid<<")-->(IMixingSvc*)"<< (void*)this<< endreq;
00100     *ppint = (IMixingSvc*)this;
00101   }
00102   else 
00103   {
00104     return RootIOCnvSvc::queryInterface(riid, ppint);
00105   }
00106   addRef();
00107   return StatusCode::SUCCESS;
00108 }

virtual void MixRootIOCnvSvc::setInputFiles ( const vector< string > &  inputs  )  [inline, virtual]

Definition at line 39 of file MixRootIOCnvSvc.h.

00040                              { m_defaultInputFilenames = inputs;}

StatusCode MixRootIOCnvSvc::buildStream (  )  [virtual]

Implements IMixingSvc.

Definition at line 110 of file MixRootIOCnvSvc.cc.

00111 {
00112   m_log<< MSG::DEBUG<< "BuildStream"<< endreq;
00113   if(m_sampleInputStreamMap.size() == 0) 
00114   {
00115     m_log<< MSG::INFO<< "Building Streams from mixing sources."<< endreq;
00116     map<string,vector<string> >::iterator miter, mbegin, mend;
00117     mbegin = m_inputSamples.begin();
00118     mend   = m_inputSamples.end();
00119     m_log<< MSG::INFO<< "Initialize the MixBuffer here."<< endreq;
00120     
00121     // Initialize the files of each sample
00122     for(miter = mbegin; miter != mend; miter++) 
00123     {
00124       m_inputStreamMap.clear();
00125 
00126       vector<string> files = (*miter).second;
00127       setInputFiles(files);
00128       doInitialize();
00129 
00130       m_sampleInputStreamMap[(*miter).first] = inputStreams();
00131       m_simROMap[(*miter).first] = m_inputStreamMap[DayaBay::SimReadoutHeaderLocation::Default];
00132     }
00133 
00134     // Initialize the file numbers of each sample
00135     for(miter = mbegin; miter != mend; miter++)
00136     {
00137       int filenum = 0;
00138       vector<string> files = miter->second;
00139       for(vector<string>::iterator vit = files.begin(); vit != files.end(); vit++)
00140       {
00141         filenum++;
00142       }
00143       m_fileNum[miter->first] = filenum;
00144     }
00145 
00146     // Initialize the file index, file entry and stream entry for each sample
00147     for(map<string, RootInputStream*>::iterator it = m_simROMap.begin(); it != m_simROMap.end(); it++)
00148     {
00149       RootInputStream* ris       = it->second;
00150       //m_fileindex[it->first]     = flatdis((double)ris->getFiles().size());
00151       m_fileindex[it->first]     = flatdis((double)m_fileNum[it->first]);
00152       bool ifjump                = ris->getFiles().jump(m_fileindex[it->first]);
00153       if(ifjump == false)
00154       {
00155         m_log<< MSG::ERROR<< "Can't jump to the specified file!"<< endreq;
00156         return StatusCode::FAILURE;
00157       }
00158       m_fileEntryNum[it->first]  = ris->getFiles().current()->entries();
00159       m_fileentries[it->first]   = flatdis((double)m_fileEntryNum[it->first]);
00160 
00161       m_log<< MSG::INFO<< "Now needing to jump to "<< it->first<< ": "<< m_fileindex[it->first]<< ".root file"<< endreq;
00162       m_log<< MSG::INFO<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;
00163       m_log<< MSG::INFO<< "Now the file total entries is: "<< m_fileEntryNum[it->first]<< endreq;
00164 
00165       ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
00166       //m_log<< MSG::INFO<< "RootInputStream: "<< ris<< endreq;
00167       m_streamentries[it->first] = ris->getEntry();
00168       //m_log<< MSG::INFO<< "Get the RootInputStream entry."<< endreq;
00169     }
00170 
00171     //m_log<< MSG::INFO<< "Here."<< endreq;
00172     // Initialize the mix buffer
00173     m_tesBuffer    = new deque<MixHeader>();
00174     m_firstBuffer  = new deque<MixHeader>();
00175     m_secondBuffer = new deque<MixHeader>();
00176     //print();
00177 
00178     m_log<< MSG::INFO<< "TESBuffer Size    = "<< m_tesBuffer->size()<< endreq;
00179     m_log<< MSG::INFO<< "FirstBuffer Size  = "<< m_firstBuffer->size()<< endreq;
00180     m_log<< MSG::INFO<< "SecondBuffer Size = "<< m_secondBuffer->size()<< endreq;
00181     m_log<< MSG::INFO<< "SteamMap Size     = "<< m_sampleInputStreamMap.size()<< "/"<< m_simROMap.size()<< endreq;
00182     
00183     // Initialize the maintau, the time nod by the samples
00184     for(map<string, RootInputStream*>::iterator mit = m_simROMap.begin(); mit != m_simROMap.end(); mit++)
00185     { 
00186       m_maintau += 1/m_timeTau[mit->first];
00187       m_nod[mit->first] = m_maintau;
00188       m_log<< MSG::INFO<< "m_nod["<< mit->first<< "] is: "<< m_nod[mit->first]<< endreq;
00189       m_maximum  = m_maintau;
00190     }
00191     m_maintau = 1/m_maintau;
00192     m_log<< MSG::INFO<< "The main tau is: "<< m_maintau<< endreq;
00193 
00194     m_totalentries = m_days*86400.0/m_maintau;
00195     m_log<< MSG::INFO<< "The Total entries are: "<< m_totalentries<< endreq;
00196   }
00197 
00198   //if (m_uniSample.initialize(m_ranSvc, Rndm::Flat(0.0, m_maximum)).isFailure()) 
00199   //{
00200   //  m_log<< MSG::FATAL<< "Failed to initialize uniform random numbers" << endreq;
00201   //  return StatusCode::FAILURE;
00202   //}
00203   //if (m_exp.initialize(m_ranSvc, Rndm::Exponential(m_maintau)).isFailure()) 
00204   //{
00205   //  m_log<< MSG::FATAL<< "Failed to initialize Gaussian random numbers" << endreq;
00206   //  return StatusCode::FAILURE;
00207   //}
00208 
00209   StatusCode sc = updateBuffer();
00210   return sc;
00211 }

StatusCode MixRootIOCnvSvc::readin ( deque< MixHeader > *  value  )  [virtual]

Definition at line 213 of file MixRootIOCnvSvc.cc.

00214 {
00215   m_log<< MSG::DEBUG<< "Read Sample into deque!"<< endreq;
00216 
00217   double randomnum = flatdis(m_maximum);
00218   //double randomnum = m_uniSample();
00219   map<string, RootInputStream*>::iterator it;
00220 
00221   //Loop on the samples
00222   for(it = m_simROMap.begin(); it != m_simROMap.end(); ) 
00223   {
00224     if(randomnum < m_nod[it->first])
00225     {
00226       // SetEntry to find that if reaching the end of a file
00227       RootInputStream* ris = it->second;
00228       RootInputFile*   rif = ris->getFiles().current();
00229       
00230       if(m_fileentries[it->first] >= rif->entries())
00231       {
00232         /*m_fileindex[it->first]++;
00233           m_log<< MSG::DEBUG<< "After resetting, the file index is: "<< m_fileindex[it->first]<< endreq;*/
00234         m_fileindex[it->first]   = flatdis((double)m_fileNum[it->first]);
00235         bool ifjump              = ris->getFiles().jump(m_fileindex[it->first]);
00236         if(ifjump == false)
00237         {
00238           m_log<< MSG::ERROR<< "Can't jump to the specified file!"<< endreq;
00239           return StatusCode::FAILURE;
00240         }
00241         m_fileEntryNum[it->first]  = ris->getFiles().current()->entries();
00242         m_fileentries[it->first] = flatdis((double)m_fileEntryNum[it->first]);
00243         //m_log<< MSG::INFO<< "After resetting, the file entry is: "<< m_fileentries[it->first]<< endreq;
00244         //m_fileindex[it->first]   = flatdis((double)ris->getFiles().size());
00245  
00246         m_log<< MSG::INFO<< "Now needing to jump to "<< it->first<< ": "<< m_fileindex[it->first]<< ".root file"<< endreq;
00247         m_log<< MSG::INFO<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;
00248         m_log<< MSG::INFO<< "Now the file total entries is: "<< m_fileEntryNum[it->first]<< endreq;
00249         ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
00250         m_streamentries[it->first] = ris->getEntry();
00251         rif = ris->getFiles().current();
00252       }
00253 
00254       // SetEntry 
00255       m_log << MSG::DEBUG<< "SetEntry manually: "<< " The sample: "<< it->first
00256             << "  File entry: "     << m_fileentries[it->first]
00257             << "  Stream entry: "   << m_streamentries[it->first]
00258             << "  RootInputStream: "<< ris
00259             << "  Old entry: "      << ris->getEntry()<< endreq;
00260       ris->setFileEntry(m_fileindex[it->first], m_fileentries[it->first], true);
00261       rif = ris->getFiles().current();
00262       //bool ifend = ris->setEntry(m_streamentries[it->first] ,true);
00263       //if(ifend == false) return StatusCode::FAILURE;
00264 
00265       m_log<< MSG::DEBUG<< "Now the file is: "      << rif->filename()         << endreq;
00266       m_log<< MSG::DEBUG<< "Now the file index is: "<< m_fileindex[it->first]  << endreq;
00267       m_log<< MSG::DEBUG<< "Now the file entry is: "<< m_fileentries[it->first]<< endreq;
00268 
00269       // Read in Event
00270       m_log << MSG::DEBUG<< "Casting TObject to PerSimReadoutHeader."<< endreq;
00271       PerSimReadoutHeader* psro = (PerSimReadoutHeader*)((void*)(ris->obj()));
00272       m_log << MSG::DEBUG<< "======= PerSimReadoutHeader: "<< psro<< endreq;
00273 
00274       //Test the PerSimReadoutHeader's InputHeaders
00275       //vector<PerRef> iheaders = psro->inputHeaders;
00276       //m_log<< MSG::INFO<< "InputHeader's vector size: "<< iheaders.size()<< endreq;
00277 
00278       vector<PerSimReadout*> ro; 
00279       if(psro != NULL) 
00280       { 
00281         ro = psro->readouts;
00282 
00283         // Important parameters     
00284         TimeStamp newtime(nextTime(m_maintau));
00285         //TimeStamp newtime(m_exp());
00286         TimeStamp pretime = m_lastTime; 
00287      
00288         if(ro.size() == 0) // There is an empty event
00289         {
00290           m_log<< MSG::DEBUG<< "There is no Readouts in SimReadoutHeader!"<< endreq;
00291           m_fileentries[it->first]++;
00292           m_streamentries[it->first]++;
00293           m_log<< MSG::DEBUG<< "Set new file entry as: "<< m_fileentries[it->first]<< endreq;
00294           continue;
00295         }
00296         else 
00297         {
00298           m_log<< MSG::DEBUG<< "PerSimReadout from "<< it->first<< " with "<< ro.size()<< " PerSimReadouts"<< endreq;
00299           vector<MixHeader> mixVec;
00300 
00301           m_log<< MSG::DEBUG<< "Generte new time["<< newtime.GetSeconds()<< "sec] for sample ["<< it->first<< "]"<< endreq;
00302        
00303           // Distinguish subevents
00304           for(vector<PerSimReadout*>::size_type i = 0; i != ro.size(); i++) 
00305           {
00306             m_log << MSG::DEBUG<< "PmtChannelSize is: "
00307                   << (static_cast<PerReadoutPmtCrate*>(ro[i]->readout))->perChannelReadouts.size()
00308                   << " in: "<< ro[i]->readout<< endreq;
00309             // Copy the variables in PerReadout
00310             MixHeader             mh;
00311             PerReadout*           pro  = new PerReadoutPmtCrate();
00312             PerReadoutHeader*     proh = new PerReadoutHeader();
00313             
00314             pro->detector           = ro[i]->readout->detector;
00315             pro->triggerType        = ro[i]->readout->triggerType;
00316             pro->triggerNumber      = ro[i]->readout->triggerNumber;
00317             pro->triggerTimeSec     = ro[i]->readout->triggerTimeSec;
00318             pro->triggerTimeNanoSec = ro[i]->readout->triggerTimeNanoSec;
00319 
00320             // Deep-Copy the variables in PerReadoutPmtCrate
00321             vector<PerReadoutPmtChannel*> PmtVec;
00322             vector<PerReadoutPmtChannel*> pmtvec = (static_cast<PerReadoutPmtCrate*>(ro[i]->readout))->perChannelReadouts;
00323             for(vector<PerReadoutPmtChannel*>::iterator pit = pmtvec.begin(); pit != pmtvec.end(); pit++)
00324             {
00325               PerReadoutPmtChannel* propc = new PerReadoutPmtChannel();
00326               propc->tdc             = (*pit)->tdc;
00327               propc->adc             = (*pit)->adc;
00328               propc->mode            = (*pit)->mode;
00329               propc->adcCycle        = (*pit)->adcCycle;
00330               propc->adcRange        = (*pit)->adcRange;
00331               propc->pedestal        = (*pit)->pedestal;
00332               propc->channelId       = (*pit)->channelId;
00333               propc->tdcHitCount     = (*pit)->tdcHitCount;
00334               propc->waveAdcLow      = (*pit)->waveAdcLow;
00335               propc->waveAdcHigh     = (*pit)->waveAdcHigh;
00336               propc->waveAdcCycle    = (*pit)->waveAdcCycle;
00337               
00338               PmtVec.push_back(propc);
00339             }
00340             (static_cast<PerReadoutPmtCrate*>(pro))->perChannelReadouts = PmtVec;
00341 
00342             m_log<< MSG::DEBUG<< "TriggerSec: "     << pro->triggerTimeSec
00343                              << " TriggerNanoSec: "<< pro->triggerTimeNanoSec<< endreq; 
00344             proh->readout  = pro;
00345             m_log<< MSG::DEBUG<< "TriggerSec: "     << proh->readout->triggerTimeSec
00346                              << " TriggerNanoSec: "<< proh->readout->triggerTimeNanoSec<< endreq;
00347 
00348             proh->earliest = psro->earliest;
00349             proh->latest   = psro->latest;
00350             m_log<< MSG::DEBUG<< "The earliest TimeStamp: "<< proh->earliest
00351                              << " The latest TimeStamp: " << proh->latest<< endreq;
00352 
00353             proh->context  = psro->context;
00354             Detector det(pro->detector);
00355             proh->context.SetDetId(det.detectorId());
00356             m_log<< MSG::DEBUG<< "The TimeStamp in Context: "<< proh->context.GetTimeStamp()<< endreq;
00357             m_log<< MSG::DEBUG<< "The DetectorId in Context: "<< proh->context.GetDetId()
00358                  << "("<< DetectorId::AsString(proh->context.GetDetId())<< ")"<< endreq;
00359 
00360             //Create MixHeader and fill the mixbuffer
00361             mh.hder   = proh;
00362             mh.sample = it->first;
00363             mh.entry  = m_streamentries[it->first];
00364    
00365             mixVec.push_back(mh);
00366           }
00367 
00368           MixHeader   firstHeader;
00369           TimeStamp*  ftemp     = new TimeStamp(0.0);
00370           //double*     temp      = new double(0.0);
00371           TimeStamp*  TotalTime = new TimeStamp(0.0);
00372           pretime.Add(newtime);
00373           (*TotalTime) = pretime;
00374           // Find the earliest subevent
00375           for(vector<MixHeader>::size_type j = 0; j != mixVec.size(); j++)
00376           {
00377             TimeStamp rotime(mixVec[j].hder->readout->triggerTimeSec, mixVec[j].hder->readout->triggerTimeNanoSec);
00378             //double rotime = mixVec[j].hder->readout->triggerTimeSec + mixVec[j].hder->readout->triggerTimeNanoSec/1.0e9;
00379             if(j == 0 || *ftemp > rotime )
00380             {
00381               *ftemp = rotime;
00382               firstHeader = mixVec[j];
00383             }
00384           }
00385         
00386           // Reset the subevnets' triggertime and time window
00387           /*double de1 = firstHeader.hder->readout->triggerTimeSec - firstHeader.hder->earliest.GetSec()
00388                      + (firstHeader.hder->readout->triggerTimeNanoSec - firstHeader.hder->earliest.GetNanoSec())/1.0e9;
00389           double de2 = firstHeader.hder->latest.GetSec() - firstHeader.hder->readout->triggerTimeSec
00390                      + (firstHeader.hder->latest.GetNanoSec() - firstHeader.hder->readout->triggerTimeNanoSec)/1.0e9;
00391           */
00392           
00393           TimeStamp fde1 = *ftemp - firstHeader.hder->earliest;
00394           TimeStamp fde2 = firstHeader.hder->latest - *ftemp;
00395 
00396           for(vector<MixHeader>::size_type k = 0; k != mixVec.size(); k++)
00397           {
00398             if(mixVec[k] != firstHeader)
00399             {
00400               /*double de1 = mixVec[k].hder->readout->triggerTimeSec - mixVec[k].hder->earliest.GetSec()
00401                          + (mixVec[k].hder->readout->triggerTimeNanoSec - mixVec[k].hder->earliest.GetNanoSec())/1.0e9;
00402               double de2 = mixVec[k].hder->latest.GetSec() - mixVec[k].hder->readout->triggerTimeSec
00403                          + (mixVec[k].hder->latest.GetNanoSec() - mixVec[k].hder->readout->triggerTimeNanoSec)/1.0e9;
00404               */
00405               TimeStamp ktemp(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
00406               TimeStamp kde1 = ktemp - mixVec[k].hder->earliest;
00407               TimeStamp kde2 = mixVec[k].hder->latest - ktemp;
00408 
00409               mixVec[k].hder->readout->triggerTimeSec     -= firstHeader.hder->readout->triggerTimeSec;
00410               mixVec[k].hder->readout->triggerTimeNanoSec -= firstHeader.hder->readout->triggerTimeNanoSec;
00411 
00412               //double deltime = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9;
00413               //TimeStamp TriggerTime(deltime + TotalTime->GetSec() + TotalTime->GetNanoSec()/1.0e9);
00414               TimeStamp deltime(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
00415               deltime.Add((*TotalTime));
00416               TimeStamp TriggerTime = deltime;
00417 
00418               mixVec[k].hder->readout->triggerTimeSec      = TriggerTime.GetSec();
00419               mixVec[k].hder->readout->triggerTimeNanoSec  = TriggerTime.GetNanoSec();
00420   
00421               //double t = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9 - de1;
00422               TimeStamp ktempe(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
00423               ktempe = ktempe - kde1;
00424               mixVec[k].hder->earliest = ktempe;
00425               //t = mixVec[k].hder->readout->triggerTimeSec + mixVec[k].hder->readout->triggerTimeNanoSec/1.0e9 + de2;
00426               TimeStamp ktempt(mixVec[k].hder->readout->triggerTimeSec, mixVec[k].hder->readout->triggerTimeNanoSec);
00427               ktempt.Add(kde2);
00428               mixVec[k].hder->latest   = ktempt;
00429               (mixVec[k].hder->context).SetTimeStamp(mixVec[k].hder->earliest);          
00430             }
00431           }
00432                    
00433           firstHeader.hder->readout->triggerTimeSec     = TotalTime->GetSec();
00434           firstHeader.hder->readout->triggerTimeNanoSec = TotalTime->GetNanoSec();         
00435 
00436           //double t = firstHeader.hder->readout->triggerTimeSec + firstHeader.hder->readout->triggerTimeNanoSec/1.0e9 - de1;
00437           TimeStamp ftempe(firstHeader.hder->readout->triggerTimeSec, firstHeader.hder->readout->triggerTimeNanoSec);
00438           ftempe = ftempe - fde1;
00439           firstHeader.hder->earliest = ftempe;
00440           TimeStamp ftempt(firstHeader.hder->readout->triggerTimeSec, firstHeader.hder->readout->triggerTimeNanoSec);
00441           ftempt.Add(fde2);
00442           firstHeader.hder->latest   = ftempt;
00443           (firstHeader.hder->context).SetTimeStamp(firstHeader.hder->earliest);
00444          
00445           delete ftemp;
00446           delete TotalTime;
00447 
00448           m_fileentries[it->first]++;
00449           m_streamentries[it->first]++;
00450           m_lastTime = pretime;
00451           vector<MixHeader>::iterator pit;
00452           for(pit = mixVec.begin(); pit != mixVec.end(); pit++)
00453           {
00454             value->push_back(*pit);
00455           }
00456         }
00457       }
00458       else 
00459       {
00460         m_log<< MSG::ERROR<< "Can't retrive pointer to PerSimReadoutHeader : Terminated!"<< endreq;
00461         return StatusCode::FAILURE;
00462       }
00463       break;    
00464     }
00465     it++;
00466   }
00467   deque<MixHeader>::iterator dbeg, dend;
00468   dbeg = value->begin(); dend = value->end();
00469   sort(dbeg, dend);
00470   return StatusCode::SUCCESS;
00471 }

MixHeader MixRootIOCnvSvc::fetchMixHeader (  )  [virtual]

Implements IMixingSvc.

Definition at line 578 of file MixRootIOCnvSvc.cc.

00579 {
00580   m_log<<MSG::DEBUG<<"Return  one pointer to PerReadoutHeader."<<endreq;
00581   return m_earliestHeader;
00582 }

void MixRootIOCnvSvc::print (  )  [virtual]

Implements IMixingSvc.

Definition at line 584 of file MixRootIOCnvSvc.cc.

00585 {
00586   MsgStream m_log(msgSvc(), "MixRootIOCnvSvc");
00587   m_log<< MSG::INFO<< "MixRootIOCnvSvc::print()"<< endreq;
00588 
00589   deque<MixHeader>::iterator fit;
00590 
00591   m_log<< MSG::INFO<< "FirstBuffer: "<< m_firstBuffer<< " Size: "<< m_firstBuffer->size()<< endreq; 
00592   for(fit = m_firstBuffer->begin(); fit != m_firstBuffer->end(); fit++)
00593   {
00594     m_log<< MSG::INFO<< fit->sample<<" : "<< fit->entry<< "--";
00595     m_log<< MSG::INFO<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
00596   }
00597   
00598   m_log<< MSG::INFO<< "SecondBuffer: "<< m_secondBuffer<< " Size: "<< m_secondBuffer->size()<< endreq; 
00599   for(fit = m_secondBuffer->begin(); fit != m_secondBuffer->end(); fit++)
00600   {
00601     m_log<< MSG::INFO<< fit->sample<<" : "<< fit->entry<< "--";
00602     m_log<< MSG::INFO<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
00603   }
00604   
00605   m_log<< MSG::INFO<< "TESBuffer: "<< m_tesBuffer<< " Size: "<< m_tesBuffer->size()<< endreq; 
00606   for(fit = m_tesBuffer->begin(); fit != m_tesBuffer->end(); fit++)
00607   {
00608     m_log<< MSG::INFO<< fit->sample<<" : "<< fit->entry<< "--";
00609     m_log<< MSG::INFO<< fit->hder->readout->triggerTimeSec<<" : "<<fit->hder->readout->triggerTimeNanoSec<< endreq;
00610   }  
00611 }

long MixRootIOCnvSvc::entries (  )  [virtual]

Implements IMixingSvc.

Definition at line 613 of file MixRootIOCnvSvc.cc.

00614 {
00615   return m_totalentries;
00616 }

StatusCode MixRootIOCnvSvc::updateBuffer (  )  [private]

Definition at line 473 of file MixRootIOCnvSvc.cc.

00474 {
00475   m_log<< MSG::DEBUG<< "UpdateBuffer"<< endreq;
00476   StatusCode sc;
00477 
00478   if(m_tesBuffer->size() != 0)
00479   {
00480     m_earliestHeader = m_tesBuffer->front();
00481     m_tesBuffer->pop_front();
00482 
00483     m_log<< MSG::DEBUG<< "m_currentEntry = " << m_earliestHeader.entry<<  endreq;
00484     m_log<< MSG::DEBUG<< "m_currentSample = "<< m_earliestHeader.sample<< endreq;
00485 
00486     m_inputStreamMap = m_sampleInputStreamMap[m_earliestHeader.sample];
00487 
00488     setInputFiles(m_inputSamples[m_earliestHeader.sample]);
00489     //print();
00490 
00491     return StatusCode::SUCCESS;
00492   }
00493   else
00494   { 
00495     if(m_firstBuffer->size() == 0 && m_secondBuffer->size() == 0) 
00496     { 
00497       sc = readin(m_firstBuffer);
00498       sc = readin(m_secondBuffer);
00499     }
00500     else if(m_firstBuffer->size() != 0 && m_secondBuffer->size() == 0) sc = readin(m_secondBuffer);
00501     else 
00502     { 
00503       m_log<< MSG::ERROR<< "There are some errors! "<< endreq;
00504       return StatusCode::FAILURE;
00505     }
00506     //print();
00507     if(sc == StatusCode::FAILURE) return StatusCode::FAILURE;
00508     performMixing();
00509     //print();
00510     return updateBuffer();
00511   }
00512 
00513   return StatusCode::SUCCESS;
00514 }       

StatusCode MixRootIOCnvSvc::doInit (  )  [private]

Definition at line 62 of file MixRootIOCnvSvc.cc.

00063 {
00064   m_log<< MSG::DEBUG<< "reset some variables at begining."<< endreq;
00065   if(m_inputSamples.size() != m_timeTau.size() || m_timeTau.size() == 0) 
00066   {
00067     return StatusCode::FAILURE;
00068   }
00069   else
00070   {
00071     map<string, double>::iterator itt, tend = m_timeTau.end();
00072     map<string, vector<string> >::iterator iter; 
00073     for(itt = m_timeTau.begin(); itt != tend; itt++) 
00074     {
00075       iter = m_inputSamples.find(itt->first);
00076       if(iter == m_inputSamples.end()) 
00077       {
00078         m_log<< MSG::DEBUG<< "Configuration is not correct for mixing"<< endreq;
00079         return StatusCode::FAILURE;
00080       }
00081       m_fileNum[itt->first]       = 0;
00082       m_fileindex[itt->first]     = 0;
00083       m_fileentries[itt->first]   = 0;
00084       m_fileEntryNum[itt->first]  = 0;
00085       m_streamentries[itt->first] = 0;
00086     }
00087     m_maintau  = 0.0;
00088     m_maximum  = 0.0;
00089     TimeStamp  lastTime(m_lasttime);
00090     m_lastTime = lastTime;
00091   }
00092   return StatusCode::SUCCESS;
00093 }

double MixRootIOCnvSvc::nextTime ( double  tau  )  [private]

Definition at line 564 of file MixRootIOCnvSvc.cc.

00565 {
00566   //Rndm::Numbers exponential(m_ranSvc, Rndm::Exponential(tau));
00567   //if(exponential)  return  exponential();
00568   //else 
00569   //{ 
00570   //m_log<< MSG::ERROR<< "Random Engine was not correct."<< endreq;
00571   //return 0.0; 
00572   //}
00573   //double tempnum = m_randomNum.Exp(tau);
00574   double tempnum = gRandom->Exp(tau);
00575   return tempnum;
00576 }

double MixRootIOCnvSvc::flatdis ( double  maximum  )  [private]

Definition at line 550 of file MixRootIOCnvSvc.cc.

00551 {
00552   //Rndm::Numbers flat(m_ranSvc, Rndm::Flat(0.0, maximum));
00553   //if(flat) return flat();
00554   //else
00555   //{
00556   //m_log<< MSG::ERROR<< "Random Engine was not correct."<< endreq;
00557   //return 0.0;
00558   //}
00559   //double tempnum = m_randomNum.Uniform(0.0, maximum);
00560   double tempnum = gRandom->Uniform(0.0, maximum);
00561   return tempnum;
00562 }

void MixRootIOCnvSvc::performMixing (  )  [private]

Definition at line 516 of file MixRootIOCnvSvc.cc.

00517 {
00518   m_log<< MSG::DEBUG<< "This is a place to perform mixing."<< endreq;
00519 
00520   if(m_firstBuffer->back() < m_secondBuffer->front())
00521   {
00522     deque<MixHeader>* tempbuffer;
00523     tempbuffer     = m_tesBuffer;
00524     m_tesBuffer    = m_firstBuffer;
00525     m_firstBuffer  = m_secondBuffer;
00526     m_secondBuffer = tempbuffer;  
00527   }
00528   else
00529   {
00530     deque<MixHeader>::iterator pos, dbegf, dendf, dbegs, dends, dbegt;
00531     dbegf = m_firstBuffer->begin();  dendf = m_firstBuffer->end();
00532     dbegs = m_secondBuffer->begin(); dends = m_secondBuffer->end();
00533     pos = lower_bound(dbegf, dendf, m_secondBuffer->front());
00534 
00535     m_tesBuffer->resize(distance(pos, dendf) + m_secondBuffer->size());
00536     dbegt = m_tesBuffer->begin();
00537     merge(pos, dendf, dbegs, dends, dbegt);
00538 
00539     m_firstBuffer->resize(distance(dbegf, pos));
00540     m_secondBuffer->clear();
00541 
00542     deque<MixHeader>* tempbuffer;
00543     tempbuffer    = m_tesBuffer;
00544     m_tesBuffer   = m_firstBuffer;
00545     m_firstBuffer = tempbuffer;
00546   }
00547   m_log<< MSG::DEBUG<< "Succesffully perform mixing."<<endreq;
00548 }

static const InterfaceID& IMixingSvc::interfaceID (  )  [inline, static, inherited]

Reimplemented from IInterface.

Definition at line 22 of file IMixingSvc.h.

00022 { 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 55 of file MixRootIOCnvSvc.h.

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

Definition at line 56 of file MixRootIOCnvSvc.h.

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

Definition at line 57 of file MixRootIOCnvSvc.h.

long MixRootIOCnvSvc::m_totalentries [private]

Definition at line 59 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_days [private]

Definition at line 60 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_maximum [private]

Definition at line 61 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_maintau [private]

Definition at line 62 of file MixRootIOCnvSvc.h.

double MixRootIOCnvSvc::m_lasttime [private]

Definition at line 63 of file MixRootIOCnvSvc.h.

TimeStamp MixRootIOCnvSvc::m_lastTime [private]

Definition at line 64 of file MixRootIOCnvSvc.h.

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

Definition at line 67 of file MixRootIOCnvSvc.h.

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

Definition at line 68 of file MixRootIOCnvSvc.h.

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

Definition at line 69 of file MixRootIOCnvSvc.h.

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

Definition at line 71 of file MixRootIOCnvSvc.h.

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

Definition at line 72 of file MixRootIOCnvSvc.h.

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

Definition at line 73 of file MixRootIOCnvSvc.h.

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

Definition at line 74 of file MixRootIOCnvSvc.h.

deque<MixHeader>* MixRootIOCnvSvc::m_firstBuffer [private]

Definition at line 76 of file MixRootIOCnvSvc.h.

deque<MixHeader>* MixRootIOCnvSvc::m_secondBuffer [private]

Definition at line 77 of file MixRootIOCnvSvc.h.

deque<MixHeader>* MixRootIOCnvSvc::m_tesBuffer [private]

Definition at line 78 of file MixRootIOCnvSvc.h.

MsgStream MixRootIOCnvSvc::m_log [mutable, private]

Definition at line 80 of file MixRootIOCnvSvc.h.

MixHeader MixRootIOCnvSvc::m_earliestHeader [private]

Definition at line 87 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 Mon Apr 11 20:45:54 2011 for Mixing by doxygen 1.4.7