/* * acrootManager.hh * * Created on: Mar 24, 2014 * Author: yqiang * * Modified on: * Nov 19, 2014: added beam current and gain, yqiang * */ #ifndef ACROOTMANAGER_HH_ #define ACROOTMANAGER_HH_ #include #include #include #include #include #include #include #include //#include #include "acrootFile.hh" #include "acrootRecord.hh" class recordBuffer { public: string treename; acrootRecord record; inline recordBuffer(string treeName, acrootRecord prRecord) : treename(treeName), record(prRecord) { } recordBuffer& operator=(const recordBuffer &rbuffer) { treename = rbuffer.treename; record = rbuffer.record; return *this; } virtual ~recordBuffer() { } }; class acrootManager { private: string prmPrefix; string prmSuffix; public: static acrootManager* selfPtr; // Self pointer static Int_t prmCompressFactor; // Compression factor static UInt_t prmFileSizeTolerance; // Maximum file size static std::queue prmBuffer; // record buffer pthread_t prmThread; bool prmStop; acrootFile* prmFile; string prmDir; string prmFileName; long prmFileLimit; long prmFileSize; pthread_mutex_t *prmMutex; acrootManager(); virtual ~acrootManager(); inline static acrootManager* GetInstance() { if (selfPtr == 0) selfPtr = new acrootManager(); return selfPtr; } void StartDAQ(string dir, string prefix, string suffix, long nlim); void NewRootFile(); void WriteFile(const char* channelName, struct timespec* timeStamp, float* buffPtr, int nElm, float* beamCurrent, short* gain); void CloseFile(); inline acrootFile* GetFile() const { return prmFile; } inline acrootFile* SetFile(acrootFile* file) { return prmFile = file; } }; void *WriteThread(void* argument); #endif /* ACROOTMANAGER_HH_ */