/////////////////////////////////////////////////////////////////////// // // This event processor implements the first level supernova // burst trigger algorithm used in SNO, originally developed by // Charles Duba as part of the SNOstream monitoring tool. // // Search for bursts of events and write out burst data files. // // Algo: Burst Algorithm // // Events are first inspected for validity based on NHIT [>NHITmin and // Clone() if possible) // - Event Trigger Mask not dynamically configurable on run/source type // - Clock handling needs work (currently running on 10MHz ticks, no // clock failure handling) // - Should only operate on EV loop, not on DS loop (currently assumes // DS->GetEventCount==0) // - Code should be made const correct // // Author: Mike Schwendener // Author: Matthew Strait - contact person // // REVISION HISTORY: // 24/06/2011 : Mike Schwendener - New File // 13 Nov 2014: Matt Strait - Fixed shadowed variable warning // 10 Nov 2016: Nuno Barros - Moved BurstTrigInit into BeginOfRun to make sure // that the run number is already set and the appropriate // RATDB tables are loaded. /////////////////////////////////////////////////////////////////////// #ifndef __RAT_BurstProc__ #define __RAT_BurstProc__ #include #include #include #include #include #include #include #include #include namespace RAT { class BurstProc : public Processor { public: BurstProc(); // Create new burst processor. virtual ~BurstProc(); // Destroy burst processor: Write out burst in progress, log burst totals. virtual void SetI(const std::string& param, const int value); // Set integer parameters (Values should now be loaded from Burst.ratdb) virtual void SetS(const std::string& param, const std::string& value); // Set String Parameters: Use to set BurstTrigName to match index of tables in Burst.ratdb. virtual Processor::Result DSEvent(DS::Run& run, DS::Entry& ds) { (void)run; return Event( &ds ); } virtual Processor::Result Event(DS::Entry* const ds); // Process one event virtual void BeginOfRun(DS::Run &run); virtual void EndOfRun(DS::Run &run) { (void)run;}; protected: bool TestaBit(ULong64_t word, int bit); bool TestaBit(unsigned int word, int bit); bool BurstEventTest(DS::EV* const ev); // Check an event for NHIT and trigger mask, return 1 if qualified. bool BurstEventProcess(DS::Entry* const ds); // Buffer qualified event, return 1 if burst in progress. void BurstContinue(); // Append event to burst file, update burst info, check stopping criteria. void BurstStart(); // Increment burst number, open new output file, write out Run Header and buffered events void BurstEnd(); // Close burst file, clear and reset burst trigger. void BurstTrigReset(); // Clear burst info. void BurstTrigRunChange(DS::Entry* const ds); // Write out burst if ongoing, update fBurstRunNum, check thresholds, reset trigger. void BurstTrigRunCheck(RAT::DS::Run* const run); // Search for most restrictive thresholds for this run/source configuration. void BurstTrigInit(); // Load thresholds from database. void BurstTrigWriteCheck(); // Ensure output directory is ready for writing, create directories if necessary bool fBurstWriteRoot; // 1 = write root files, 0 = do not write root files. unsigned int fNHITmax; // Burst parameter: Maximum NHIT for qualified events unsigned int fNHITmin; // Burst parameter: Minimum NHIT for qualified events int fNEvent; // Burst parameter: Number of events needed for a burst trigger. int fTWin; // Burst parameter: Time window for a burst trigger (milliseconds). int fBurstEventIndex; // Counter to keep track of position in circular buffer. int fBurstNum; // Sequential burst number, zeroed at run start. int fBurstNumTotal; // Total number of bursts detected across runs. int fBurstNHIT; // NHIT sum of all events in current burst. int fBurstSize; // Number of events in current burst. int fBurstStartGTID; // GTID of first event in current burst. int fBurstEndGTID; // GTID of last event in current burst. int fBurstRunNum; // Run number of current burst std::vector fBurstThreshSrc[33]; // Stored parameters for source type bits in run header std::vector fBurstThreshRun[65]; // Stored parameters for run type bits in run header std::vector fBurstThreshDef; // Default parameters to load before receiving run header std::stringstream fRootFileNameStream; // Output filename for Root files std::string fBurstTrigName; // Name of burst trigger, matches index in Burst.ratdb std::string fBurstDirectory; // Burst output directory std::string fRunTypeString; // Current run type description std::string fSrcMaskString; // Current source type description std::string fRunTypeName[65]; // Names of all Run bits std::string fSrcMaskName[33]; // Names of all Source bits ULong64_t fBurstRunType; // Bitmask for run type from RunHheader UInt_t fBurstSrcMask; // BitMask for source type from RunHeader Int_t fBurstTrigMask; // Trigger mask for event by event rejection ULong64_t fBurstStartTime; // Start time of burst (if == 0 then no burst in progress) ULong64_t fBurstEndTime; // End time of burst RAT::DS::EV* fMyEv; // Pointer to current event RAT::DS::Entry* fMyDs; // Pointer to current ds RAT::DS::Entry* fBurstEventBuffer[100]; // Circular buffer of qualified events OutROOTProc * fBurstRooter; // Output processor for Root events }; } // namespace RAT #endif