コード例 #1
0
ファイル: Globals.cpp プロジェクト: gottardo7/pixie_scan
void Globals::SanityCheck() {
    Messenger m;
    std::stringstream ss;

    if (!(revision_ == "A" || revision_ == "D" || revision_ == "F")) {
        ss << "Globals: unknown revision version named "
           << revision_;
        throw GeneralException(ss.str());
    }

    if (clockInSeconds_ <= 0) {
        ss << "Globals: illegal value of clockInSeconds "
            << clockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (adcClockInSeconds_ <= 0) {
        ss << "Globals: illegal value of adcClockInSeconds "
            << adcClockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (filterClockInSeconds_ <= 0) {
        ss << "Globals: illegal value of filterClockInSeconds "
            << filterClockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (eventInSeconds_ <= 0) {
        ss << "Globals: illegal value of eventInSeconds "
            << eventInSeconds_;
        throw GeneralException(ss.str());
    }

    if (hasReject_) {
        ss << "Total number of rejection regions: " << reject_.size();
        m.detail(ss.str());
    } else {
        ss << "Not using rejection regions";
        m.detail(ss.str());
    }

    ss.str("");
    if (energyContraction_ <= 0) {
        ss << "Globals: Surely you don't want to use Energy contraction = "
            << energyContraction_ << ". I'd better stop the program.";
        throw GeneralException(ss.str());
    } else {
        ss << "Energy contraction: " << energyContraction_;
        m.detail(ss.str());
    }

    m.done();
}
コード例 #2
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
DetectorDriver::DetectorDriver() : histo(OFFSET, RANGE, "DetectorDriver") {
    Messenger m;
    try {
        m.start("Loading Processors");
        LoadProcessors(m);
    } catch (GeneralException &e) {
        /// Any exception in registering plots in Processors
        /// and possible other exceptions in creating Processors
        /// will be intercepted here
        m.fail();
        cout << "Exception caught at DetectorDriver::DetectorDriver" << endl;
        cout << "\t" << e.what() << endl;
        exit(EXIT_FAILURE);
    } catch (GeneralWarning &w) {
        cout << "Warning found at DetectorDriver::DetectorDriver" << endl;
        cout << "\t" << w.what() << endl;
    }
    m.done();
}
コード例 #3
0
ファイル: TreeCorrelator.cpp プロジェクト: akeeler/pixie_scan
void TreeCorrelator::buildTree() {
    pugi::xml_document doc;

    Messenger m;
    m.start("Creating TreeCorrelator");
    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        m.fail();
        throw IOException(ss.str());
    }

    pugi::xml_node tree = doc.child("Configuration").child("TreeCorrelator");
    bool verbose = tree.attribute("verbose").as_bool(false);

    Walker walker;
    walker.traverseTree(tree, string(tree.attribute("name").value()), verbose);

    m.done();
}
コード例 #4
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
void DetectorDriver::ReadWalkXml() {
    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw GeneralException(ss.str());
    }

    Messenger m;
    m.start("Loading Walk Corrections");

    pugi::xml_node map = doc.child("Configuration").child("Map");
    /** See comment in the similiar place at ReadCalXml() */
    bool verbose = map.attribute("verbose_walk").as_bool();
    for (pugi::xml_node module = map.child("Module"); module;
         module = module.next_sibling("Module")) {
        int module_number = module.attribute("number").as_int(-1);
        for (pugi::xml_node channel = module.child("Channel"); channel;
             channel = channel.next_sibling("Channel")) {
            int ch_number = channel.attribute("number").as_int(-1);
            Identifier chanID = DetectorLibrary::get()->at(module_number,
                                                           ch_number);
            bool corrected = false;
            for (pugi::xml_node walkcorr = channel.child("WalkCorrection");
                walkcorr; walkcorr = walkcorr.next_sibling("WalkCorrection")) {
                string model = walkcorr.attribute("model").as_string("None");
                double min = walkcorr.attribute("min").as_double(0);
                double max =
                  walkcorr.attribute("max").as_double(
                                              numeric_limits<double>::max());

                stringstream pars(walkcorr.text().as_string());
                vector<double> parameters;
                while (true) {
                    double p;
                    pars >> p;
                    if (pars)
                        parameters.push_back(p);
                    else
                        break;
                }
                if (verbose) {
                    stringstream ss;
                    ss << "Module " << module_number
                       << ", channel " << ch_number << ": ";
                    ss << " model: " << model;
                    for (vector<double>::iterator it = parameters.begin();
                         it != parameters.end(); ++it)
                        ss << " " << (*it);
                    m.detail(ss.str(), 1);
                }
                walk.AddChannel(chanID, model, min, max, parameters);
                corrected = true;
            }
            if (!corrected && verbose) {
                stringstream ss;
                ss << "Module " << module_number << ", channel "
                << ch_number << ": ";
                ss << " not corrected for walk";
                m.detail(ss.str(), 1);
            }
        }
    }
    m.done();
}
コード例 #5
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
void DetectorDriver::ReadCalXml() {
    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw GeneralException(ss.str());
    }

    Messenger m;
    m.start("Loading Calibration");

    pugi::xml_node map = doc.child("Configuration").child("Map");

    /** Note that before this reading in of the xml file, it was already
     * processed for the purpose of creating the channels map.
     * Some sanity checks (module and channel number) were done there
     * so they are not repeated here/
     */
    bool verbose = map.attribute("verbose_calibration").as_bool();
    for (pugi::xml_node module = map.child("Module"); module;
         module = module.next_sibling("Module")) {
        int module_number = module.attribute("number").as_int(-1);
        for (pugi::xml_node channel = module.child("Channel"); channel;
             channel = channel.next_sibling("Channel")) {
            int ch_number = channel.attribute("number").as_int(-1);
            Identifier chanID = DetectorLibrary::get()->at(module_number,
                                                           ch_number);
            bool calibrated = false;
            for (pugi::xml_node cal = channel.child("Calibration");
                cal; cal = cal.next_sibling("Calibration")) {
                string model = cal.attribute("model").as_string("None");
                double min = cal.attribute("min").as_double(0);
                double max =
                  cal.attribute("max").as_double(numeric_limits<double>::max());

                stringstream pars(cal.text().as_string());
                vector<double> parameters;
                while (true) {
                    double p;
                    pars >> p;
                    if (pars)
                        parameters.push_back(p);
                    else
                        break;
                }
                if (verbose) {
                    stringstream ss;
                    ss << "Module " << module_number << ", channel "
                       << ch_number << ": ";
                    ss << " model-" << model;
                    for (vector<double>::iterator it = parameters.begin();
                         it != parameters.end(); ++it)
                        ss << " " << (*it);
                    m.detail(ss.str(), 1);
                }
                cali.AddChannel(chanID, model, min, max, parameters);
                calibrated = true;
            }
            if (!calibrated && verbose) {
                stringstream ss;
                ss << "Module " << module_number << ", channel "
                   << ch_number << ": ";
                ss << " non-calibrated";
                m.detail(ss.str(), 1);
            }
        }
    }
    m.done();
}
コード例 #6
0
ファイル: PixieStd.cpp プロジェクト: kmiernik/pixie_scan
extern "C" void hissub_(unsigned short *ibuf[],unsigned short *nhw)
#endif
{
    static float hz = sysconf(_SC_CLK_TCK); // get the number of clock ticks per second
    static clock_t clockBegin; // initialization time
    static struct tms tmsBegin;

    vector<ChanEvent*> eventList; // vector to hold the events

    /* Pointer to singleton DetectorLibrary class */
    DetectorLibrary* modChan = DetectorLibrary::get();
    /* Pointer to singleton DetectorDriver class */
    DetectorDriver* driver = DetectorDriver::get();
    /* Screen messenger */
    Messenger messenger;
    stringstream ss;

    // local version of ibuf pointer
    word_t *lbuf;

    int retval = 0; // return value from various functions

    unsigned long bufLen;

    /*
      Various event counters
    */
    unsigned long numEvents = 0;
    static int counter = 0; // the number of times this function is called
    static int evCount;     // the number of times data is passed to ScanList
    static unsigned int lastVsn; // the last vsn read from the data
    time_t theTime = 0;

    /*
      Assign the local variable lbuf to the variable ibuf which is passed into
      the routine.  The difference between the new and old pixie16 readouts is
      the type of the variable and source of the variable ibuf.

      In the new readout ibuf is from a C++ function and is of type unsigned int*
      In the old readout ibuf is from a Fortran function and is of type
      unsigned short*

      This results in two different assignment statements depending on
      the readout.
    */
#ifdef newreadout
    lbuf=(word_t *)ibuf[0];
#else
    lbuf=(word_t *)ibuf; //old readout
#endif

    /* Initialize the scan program before the first event */
    if (counter==0) {
        /* Retrieve the current time for use later to determine the total
        * running time of the analysis.
        */
        messenger.start("Initializing scan");

        string revision = Globals::get()->revision();
        // Initialize function pointer to point to
        // correct version of ReadBuffData
        if (revision == "D" || revision == "F")
            ReadBuffData = ReadBuffDataDF;
        else if (revision == "A")
            ReadBuffData = ReadBuffDataA;

        clockBegin = times(&tmsBegin);

        ss << "First buffer at " << clockBegin << " sys time";
        messenger.detail(ss.str());
        ss.str("");

        /* After completion the descriptions of all channels are in the modChan
        * vector, the DetectorDriver and rawevent have been initialized with the
        * detectors that will be used in this analysis.
        */
        modChan->PrintUsedDetectors(rawev);
        driver->Init(rawev);

        /* Make a last check to see that everything is in order for the driver
        * before processing data. SanityCheck function throws exception if
        * something went wrong.
        */
        try {
            driver->SanityCheck();
        } catch (GeneralException &e) {
            messenger.fail();
            cout << "Exception caught while checking DetectorDriver"
                 << " sanity in PixieStd" << endl;
            cout << "\t" << e.what() << endl;
            exit(EXIT_FAILURE);
        } catch (GeneralWarning &w) {
            cout << "Warning caught during checking DetectorDriver"
                 << " at PixieStd" << endl;
            cout << "\t" << w.what() << endl;
        }

        lastVsn=-1; // set last vsn to -1 so we expect vsn 0 first

        ss << "Init at " << times(&tmsBegin) << " sys time.";
        messenger.detail(ss.str());
        messenger.done();
    }
    counter++;

    unsigned int nWords=0;  // buffer counter, reset only for new buffer

    // true if the buffer being analyzed is split across a spill from pixie
    bool multSpill;

    do {
        word_t vsn = pixie::U_DELIMITER;
        //true if spill had all vsn's
        bool fullSpill = false;
        //assume all buffers are not split between spills
        multSpill = false;

        /* while the current location in the buffer has not gone beyond the end
         * of the buffer (ignoring the last three delimiters,
         * continue reading */
        while (nWords < (nhw[0]/2 - 6)) {
            /*
            Retrieve the record length and the vsn number
            */
            word_t lenRec = lbuf[nWords];
            vsn = lbuf[nWords+1];

            /* If the record length is -1 (after end of spill), increment the
            location in the buffer by two and start over with the while loop
            */
            if (lenRec == pixie::U_DELIMITER) {
                nWords += 2;  // increment two whole words and try again
                continue;
            }
            // Buffer with vsn 1000 was inserted with
            // the time for superheavy exp't
            if (vsn == pixie::clockVsn) {
                memcpy(&theTime, &lbuf[nWords+2], sizeof(time_t));
                nWords += lenRec;
            }

            /* If the record length is 6, this is an empty channel.
             * Skip this vsn and continue with the next
            */
            //! Revision specific, so move to ReadBuffData
            if (lenRec == 6) {
                nWords += lenRec+1; // one additional word for delimiter
                lastVsn=vsn;
                continue;
            }
            /* If both the current vsn inspected is within an
             * acceptable range, begin reading the buffer.
             */
            if ( vsn < modChan->GetPhysicalModules()  ) {
                if ( lastVsn != pixie::U_DELIMITER) {
                // the modules should be read out cyclically
                    if ( ((lastVsn+1) % modChan->GetPhysicalModules() ) !=
                           vsn ) {
#ifdef VERBOSE
                            ss << " MISSING BUFFER " << vsn << "/"
                            << modChan->GetPhysicalModules()
                            << " -- lastVsn = " << lastVsn << "  "
                            << ", length = " << lenRec;
                            messenger.warning(ss.str());
                            ss.str("");
#endif
                            RemoveList(eventList);
                            fullSpill=true;
                    }
                }
                /* Read the buffer.  After read, the vector eventList will
                   contain pointers to all channels that fired in this buffer
                */
                retval= (*ReadBuffData)(&lbuf[nWords], &bufLen, eventList);
                /* If the return value is less than the error code,
                   reading the buffer failed for some reason.
                   Print error message and reset variables if necessary
                 */
                if ( retval <= readbuff::ERROR ) {
                    ss << " READOUT PROBLEM " << retval
                       << " in event " << counter;
                    messenger.warning(ss.str());
                    ss.str("");
                    if ( retval == readbuff::ERROR ) {
                        ss << "  Remove list " << lastVsn
                           << " " << vsn;
                        RemoveList(eventList);
                        messenger.warning(ss.str());
                        ss.str("");
                    }
                    return;
                } else if ( retval == 0 ) {
                    // empty buffers are regular in Rev. D data
                    // cout << " EMPTY BUFFER" << endl;
                    nWords += lenRec + 1;
                    lastVsn = vsn;
                    continue;
                } else if ( retval > 0 ) {
                    /* increment the total number of events observed */
                    numEvents += retval;
                }
                /* Update the variables that are keeping track of what has been
                   analyzed and increment the location in the current buffer
                */
                    lastVsn = vsn;
                    nWords += lenRec+1; // one extra word for delimiter
            } else {
                // bail out if we have lost our place,
                //   (bad vsn) and process events
                if (vsn != 9999 && vsn != pixie::clockVsn) {
#ifdef VERBOSE
                    ss << "UNEXPECTED VSN " << vsn;
                    messenger.warning(ss.str());
                    ss.str("");
#endif
                }
                break;
            }
        } // while still have words
        if (nWords > nhw[0] / 2 - 6) {
            ss << "This actually happens!";
            messenger.run_message(ss.str());
            ss.str("");
        }

        /* If the vsn is 9999 this is the end of a spill, signal this buffer
           for processing and determine if the buffer is split between spills.
        */
            if ( vsn == 9999 || vsn == pixie::clockVsn ) {
                fullSpill = true;
                nWords += 3;//skip it
                if (lbuf[nWords+1] != pixie::U_DELIMITER) {
                    ss << "this actually happens!";
                    messenger.warning(ss.str());
                    ss.str("");
                    multSpill = true;
                }
                lastVsn=pixie::U_DELIMITER;
            }

            /* if there are events to process, continue */
            if( numEvents > 0 ) {
                if (fullSpill) { 	  // if full spill process events
                    // sort the vector of pointers eventlist according to time
                    double lastTimestamp = (*(eventList.rbegin()))->GetTime();

                    sort(eventList.begin(),eventList.end(),CompareTime);
                    driver->CorrelateClock(lastTimestamp, theTime);

                    /* once the vector of pointers eventlist is sorted
                     * based on time, begin the event processing in ScanList()
                    */
                    ScanList(eventList, rawev);

                    /* once the eventlist has been scanned, remove it
                     * from memory and reset the number of events to zero
                     * and update the event counter
                    */

                    evCount++;
                    /*
                    every once in a while (when evcount is a multiple of 1000)
                    print the time elapsed doing the analysis
                    */
                    if(evCount % 1000 == 0 || evCount == 1) {
                        tms tmsNow;
                        clock_t clockNow = times(&tmsNow);

                        stringstream ss;
                        if (theTime != 0) {
                            string timestamp = string(ctime(&theTime));
                            timestamp.erase(timestamp.find_last_not_of(" \t\n\r") + 1);
                            ss << "Data read up to poll status time "
                            << timestamp;
                            messenger.run_message(ss.str());
                            ss.str("");
                        }
                        ss << "buffer = " << evCount << ", user time = "
                           << (tmsNow.tms_utime - tmsBegin.tms_utime) / hz
                           << ", system time = "
                           << (tmsNow.tms_stime - tmsBegin.tms_stime) / hz
                           << ", real time = "
                           << (clockNow - clockBegin) / hz
                           << ", ts = " << lastTimestamp;
                        messenger.run_message(ss.str());
                    }
                    RemoveList(eventList);
                    numEvents = 0;
                } // end fullSpill
                else {
                    stringstream ss;
                    ss << "Spill split between buffers";
                    messenger.run_message(ss.str());
                    //! this tosses out all events read into the vector so far
                    return;
                }
            }  // end numEvents > 0
            else if (retval != readbuff::STATS) {
                stringstream ss;
                ss << "bad buffer, numEvents = " << numEvents;
                messenger.warning(ss.str());
                return;
            }
    } while (multSpill); // end while loop over multiple spills
    return;
}