Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:13

0001 #include <cmath>
0002 #include <cstdio>
0003 #include <ctime>
0004 
0005 #include <iostream>
0006 #include <fstream>
0007 #include <sstream>
0008 #include <string>
0009 #include <vector>
0010 #include <map>
0011 #include <cassert>
0012 
0013 using namespace std;
0014 
0015 #include <TString.h>
0016 #include <TObjString.h>
0017 
0018 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0019 #include "OnlineDB/EcalCondDB/interface/all_lmf_types.h"
0020 #include "OnlineDB/EcalCondDB/interface/RunDat.h"
0021 #include "OnlineDB/EcalCondDB/interface/RunLaserRunDat.h"
0022 
0023 // fixme
0024 #include "OnlineDB/EcalCondDB/interface/LMFSeqDat.h"
0025 #include "OnlineDB/EcalCondDB/interface/LMFLaserPulseDat.h"
0026 #include "OnlineDB/EcalCondDB/interface/LMFPrimDat.h"
0027 #include "OnlineDB/EcalCondDB/interface/LMFPnPrimDat.h"
0028 
0029 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
0030 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
0031 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
0032 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEEGeom.h"
0033 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MELaserPrim.h"
0034 
0035 class CondDBApp {
0036 public:
0037   CondDBApp(string sid, string user, string pass)
0038       : _debug(0), _insert(true), _run(0), _seq(0), _type(0), _color(0), _t0(0), _t1(0) {
0039     _location = "P5_Co";
0040     _runtype = "TEST";    //???
0041     _gentag = "default";  //???
0042 
0043     try {
0044       if (_debug > 0) {
0045         cout << "Making connection..." << endl;
0046         cout << "->  sid=" << sid << endl;
0047         cout << "-> user=" << user << endl;
0048         cout << "-> pass=" << pass << endl;
0049       }
0050       econn = new EcalCondDBInterface(sid, user, pass);
0051     } catch (runtime_error& e) {
0052       cerr << e.what() << endl;
0053       exit(-1);
0054     }
0055   }
0056 
0057   ~CondDBApp() { delete econn; }
0058 
0059   void init(int irun, int iseq, int type, int color, time_t t0, time_t t1) {
0060     _run = irun;
0061     _seq = iseq;
0062     _type = type;
0063     _color = color;
0064     _t0 = t0;
0065     _t1 = t1;
0066 
0067     cout << endl;
0068     cout << "--- Transfering Laser Monitoring data to OMDS ---\n";
0069     cout << "---   for run/seq(t0/t1/Dt) " << _run << "/" << _seq << "(" << _t0 << "/" << _t1 << "/" << _t1 - _t0 << ")"
0070          << endl;
0071 
0072     // set the RunIOV
0073     setRun();
0074 
0075     // set trigger type and color
0076     setTriggerAndColor();
0077 
0078     // set the sequence
0079     setSequence();
0080 
0081     // set the map of runIOVs
0082     //setMapOfRunIOV();
0083   }
0084 
0085   void setRun() {
0086     LocationDef locdef;
0087     RunTypeDef rundef;
0088 
0089     locdef.setLocation(_location);
0090     rundef.setRunType(_runtype);
0091 
0092     _runtag.setLocationDef(locdef);
0093     _runtag.setRunTypeDef(rundef);
0094     _runtag.setGeneralTag(_gentag);
0095 
0096     run_t run = _run;
0097 
0098     if (_debug > 0)
0099       cout << "Fetching run by tag..." << endl;
0100     _runiov = econn->fetchRunIOV(&_runtag, run);
0101     printRunIOV(_runiov);
0102 
0103     // get logic id for all ECAL
0104     ecid_allEcal = econn->getEcalLogicID("ECAL");
0105 
0106     //
0107     // Laser Run
0108     //
0109 
0110     map<EcalLogicID, RunLaserRunDat> dataset;
0111 
0112     econn->fetchDataSet(&dataset, &_runiov);
0113     int n_ = dataset.count(ecid_allEcal);
0114     if (n_ == 0) {
0115       if (_debug > 0)
0116         cout << "RunLaserRunDat -- not created yet: create & insert it" << endl;
0117       RunLaserRunDat rd;
0118       rd.setLaserSequenceType("STANDARD");
0119       rd.setLaserSequenceCond("IN_THE_GAP");
0120       dataset[ecid_allEcal] = rd;
0121       if (_debug > 0)
0122         cout << "Inserting LaserRunDat " << flush;
0123       if (_insert) {
0124         econn->insertDataSet(&dataset, &_runiov);
0125         if (_debug > 0)
0126           cout << "...dummy..." << endl;
0127       }
0128       if (_debug > 0)
0129         cout << "Done." << endl;
0130     } else {
0131       if (_debug > 0)
0132         cout << "RunLaserRunDat -- already inserted" << endl;
0133     }
0134   }
0135 
0136   void setTriggerAndColor() {
0137     //  Color id     : 0  blue - blue laser (440 nm) or blue led
0138     //  Color id     : 1  green - green (495 nm)
0139     //  Color id     : 2  red/orange - red laser (706 nm) or orange led
0140     //  Color id     : 3  IR - infrared (796 nm)
0141     int colorID = _color;
0142 
0143     //Trig id     : 0  las - laser
0144     //Trig id     : 1  led - led
0145     //Trig id     : 2  tp - test pulse
0146     //Trig id     : 3  ped - pedestal
0147     int trigID = _type;
0148 
0149     // LMF Run tag
0150     int tagID = 1;
0151     {
0152       _lmfcol.setConnection(econn->getEnv(), econn->getConn());
0153       _lmfcol.setColor(colorID);
0154       _lmfcol.dump();
0155       //GO      _lmfcol.fetchID();
0156     }
0157 
0158     {
0159       _lmftrig.setConnection(econn->getEnv(), econn->getConn());
0160       //GO      _lmftrig.setByID(trigID);
0161       _lmftrig.setByID(trigID + 1);
0162       _lmftrig.fetchID();
0163     }
0164 
0165     {
0166       _lmftag.setConnection(econn->getEnv(), econn->getConn());
0167       _lmftag.setByID(tagID);
0168       _lmftag.fetchID();
0169     }
0170   }
0171 
0172   void setSequence() {
0173     _lmfseq.setConnection(econn->getEnv(), econn->getConn());
0174     std::map<int, LMFSeqDat> l = _lmfseq.fetchByRunIOV(_runiov);
0175     cout << "Run has " << l.size() << " sequences in database" << endl;
0176     std::map<int, LMFSeqDat>::const_iterator b = l.begin();
0177     std::map<int, LMFSeqDat>::const_iterator e = l.end();
0178     bool ok_(false);
0179     while (b != e) {
0180       _lmfseq = b->second;
0181       int iseq_ = (b->second).getSequenceNumber();
0182       if (iseq_ == _seq) {
0183         ok_ = true;
0184         break;
0185       }
0186       b++;
0187     }
0188     if (!ok_) {
0189       LMFSeqDat seq_;
0190       cout << "Sequence does not exist -- create it " << endl;
0191       //    seq_.debug();
0192       seq_.setRunIOV(_runiov);
0193       seq_.setSequenceNumber(_seq);
0194       // run times
0195       Tm startTm;
0196       Tm endTm;
0197       uint64_t microsStart = _t0;
0198       uint64_t microsEnd = _t1;
0199       microsStart *= 1000000;
0200       microsEnd *= 1000000;
0201       startTm.setToMicrosTime(microsStart);
0202       endTm.setToMicrosTime(microsEnd);
0203       seq_.setSequenceStart(startTm);
0204       seq_.setSequenceStop(endTm);
0205       seq_.setVersions(1, 1);
0206       if (_insert) {
0207         econn->insertLmfSeq(&seq_);
0208       }
0209       _lmfseq = seq_;
0210     }
0211     printLMFSeqDat(_lmfseq);
0212   }
0213 
0214   void setMapOfRunIOV() {
0215     LMFRunIOV lmfiov;
0216     lmfiov.setConnection(econn->getEnv(), econn->getConn());
0217     std::list<LMFRunIOV> iov_l = lmfiov.fetchBySequence(_lmfseq);
0218     std::list<LMFRunIOV>::const_iterator iov_b = iov_l.begin();
0219     std::list<LMFRunIOV>::const_iterator iov_e = iov_l.end();
0220     while (iov_b != iov_e) {
0221       if (iov_b->getTriggerType() == _lmftrig && iov_b->getColor() == _lmfcol) {
0222         int ilmr = iov_b->getLmr();
0223         _lmfRunIOV[ilmr] = *iov_b;
0224       }
0225       iov_b++;
0226     }
0227   }
0228 
0229   void storeLaserPrimitive(const char* fname, ME::Header header, ME::Settings settings, time_t dt) {
0230     LMFRunIOV lmfiov;
0231     lmfiov.setConnection(econn->getEnv(), econn->getConn());
0232 
0233     //     // Rustine
0234     TString normStr_ = "APD_OVER_PN";
0235     bool useAPDnorm_ = false;
0236     if (useAPDnorm_)
0237       normStr_ = "APD_OVER_APD";
0238 
0239     int table_id_(0);
0240     int id1_(0);
0241     int id2_(0);
0242     int id3_(EcalLogicID::NULLID);
0243 
0244     bool ok_(false);
0245     TString channelViewName_;
0246 
0247     int logic_id;
0248     // LMF Tag and IOV
0249     int type = settings.type;
0250     int color = settings.wavelength;
0251     assert(type == _type && color == _color);
0252     time_t t_beg = _t0 + dt;
0253     time_t t_end = _t0 + dt + 5;  //!!!GHM!!!
0254 
0255     int dcc = header.dcc;
0256     int side = header.side;
0257     int ilmr = ME::lmr(dcc, side);
0258 
0259     if (existsLMFRunIOV(ilmr)) {
0260       lmfiov = _lmfRunIOV[ilmr];
0261     } else {
0262       LMFRunIOV lmfiov_;
0263 
0264       lmfiov_.setConnection(econn->getEnv(), econn->getConn());
0265       lmfiov_.debug();
0266       lmfiov_.startProfiling();
0267       cout << "LMRunIOV not found -- create it " << endl;
0268 
0269       // fill the fields
0270       lmfiov_.setLMFRunTag(_lmftag);
0271       lmfiov_.setSequence(_lmfseq);
0272       lmfiov_.setTriggerType(_lmftrig);
0273       lmfiov_.setColor(_lmfcol);
0274       lmfiov_.setLmr(ilmr);
0275       lmfiov_.setSubRunType("test");  // ?
0276 
0277       // run times
0278       Tm startTm;
0279       Tm endTm;
0280       uint64_t microsStart = t_beg;
0281       uint64_t microsEnd = t_end;
0282       microsStart *= 1000000;
0283       microsEnd *= 1000000;
0284       startTm.setToMicrosTime(microsStart);
0285       endTm.setToMicrosTime(microsEnd);
0286       lmfiov_.setSubRunStart(startTm);
0287       lmfiov_.setSubRunEnd(endTm);
0288 
0289       // insert
0290       if (_insert) {
0291         econn->insertLmfRunIOV(&lmfiov_);
0292       } else {
0293         cout << "fake insert" << endl;
0294       }
0295 
0296       // keep in the map
0297       _lmfRunIOV[ilmr] = lmfiov_;
0298       lmfiov = _lmfRunIOV[ilmr];
0299     }
0300     { printLMFRunIOV(lmfiov); }
0301 
0302     bool isEB = ME::isBarrel(ilmr);
0303 
0304     //    econn->fetchDataSet( );
0305 
0306     //     // datasets
0307     //     map< EcalLogicID, LMFLaserPrimDat   >    dataset_prim;
0308     //     map< EcalLogicID, LMFLaserPNPrimDat >    dataset_pnprim;
0309     //     map< EcalLogicID, LMFLaserPulseDat  >    dataset_pulse;
0310 
0311     //  Open the ROOT file
0312     TString rootfile(fname);
0313     TDirectory* f = TFile::Open(rootfile);
0314     if (f == nullptr) {
0315       cout << "ERROR -- file=" << rootfile << " not found! " << endl;
0316       //    abort();  // this must not happen
0317       return;
0318     }
0319     if (_debug > 0)
0320       cout << "File=" << rootfile << " found. " << endl;
0321 
0322     TString sep("__");
0323     TString hname, vname;
0324     TString table;
0325     TH2I* i_h;
0326 
0327     // LMF Run
0328     //    map< EcalLogicID, LMFRunDat         >    dataset_lmfrun;
0329     table = "LMF_RUN_DAT";
0330     TTree* lmfrun_t = (TTree*)f->Get(table);
0331     map<TString, unsigned int> lmfrun_i;
0332     vname = "LOGIC_ID";
0333     lmfrun_t->SetBranchAddress(vname, &lmfrun_i[vname]);
0334     vname = "NEVENTS";
0335     lmfrun_t->SetBranchAddress(vname, &lmfrun_i[vname]);
0336     vname = "QUALITY_FLAG";
0337     lmfrun_t->SetBranchAddress(vname, &lmfrun_i[vname]);
0338     lmfrun_t->LoadTree(0);
0339     lmfrun_t->GetEntry(0);
0340     logic_id = (int)lmfrun_i["LOGIC_ID"];
0341     int nevents = (int)lmfrun_i["NEVENTS"];
0342     int flag = (int)lmfrun_i["QUALITY_FLAG"];
0343     if (_debug > 0) {
0344       cout << "nevents=" << nevents;
0345       cout << "\tquality flag=" << flag;
0346       cout << endl;
0347     }
0348 
0349     // build the logicID for the "fanout"
0350     table_id_ = MELaserPrim::iECAL_LMR;
0351     id1_ = 0;
0352     id2_ = 0;
0353     ok_ = MELaserPrim::getViewIds(logic_id, table_id_, id1_, id2_);
0354     if (!ok_) {
0355       cout << "warning -- inconsistent table_id [1] --> " << table_id_ << endl;
0356       table_id_ = MELaserPrim::iECAL_LMR;
0357     }
0358     if (id1_ != ilmr) {
0359       cout << "warning -- inconsistent id1/lmr " << id1_ << "/" << ilmr << endl;
0360       id1_ = ilmr;
0361     }
0362     //    table_id_ = logic_id/1000000;
0363     //    assert( table_id_==MELaserPrim::iECAL_LMR );
0364     //    id1_ = (logic_id%1000000)/10000;
0365     //    id2_ = 0;
0366     //    EcalLogicID ecid_lmfrun = econn->getEcalLogicID( "EB_LM_side", id1_, id2_ );
0367     EcalLogicID ecid_lmfrun = econn->getEcalLogicID("ECAL_LMR", id1_);
0368     if (_debug)
0369       cout << ecid_lmfrun.getLogicID() << endl;
0370     {
0371       // Set the data
0372       LMFRunDat lmf_lmfrun(econn);
0373       lmf_lmfrun.setLMFRunIOV(lmfiov);
0374 
0375       // DOES NOT WORK
0376       lmf_lmfrun.setEvents(ecid_lmfrun, nevents);
0377       lmf_lmfrun.setQualityFlag(ecid_lmfrun, flag);
0378 
0379       // WORKS
0380       //    vector< float > data(2);
0381       //    data[0] = nevents;
0382       //    data[1] = flag;
0383       //    lmf_lmfrun.setData( ecid_lmfrun, data );
0384 
0385       // DOES NOT WORK
0386       // lmf_lmfrun.setData( ecid_lmfrun, string("NEVENTS"), (float) nevents );
0387       if (_insert) {
0388         econn->insertLmfDat(&lmf_lmfrun);
0389       }
0390     }
0391 
0392     //
0393     // Laser Configuration
0394     //
0395     //     map< EcalLogicID, LMFLaserConfigDat >    dataset_config;
0396     table = "LMF_LASER_CONFIG_DAT";
0397     TTree* config_t = (TTree*)f->Get(table);
0398     map<TString, unsigned int> config_i;
0399     vname = "LOGIC_ID";
0400     config_t->SetBranchAddress(vname, &config_i[vname]);
0401     vname = "WAVELENGTH";
0402     config_t->SetBranchAddress(vname, &config_i[vname]);
0403     vname = "VFE_GAIN";
0404     config_t->SetBranchAddress(vname, &config_i[vname]);
0405     vname = "PN_GAIN";
0406     config_t->SetBranchAddress(vname, &config_i[vname]);
0407     vname = "LSR_POWER";
0408     config_t->SetBranchAddress(vname, &config_i[vname]);
0409     vname = "LSR_ATTENUATOR";
0410     config_t->SetBranchAddress(vname, &config_i[vname]);
0411     vname = "LSR_CURRENT";
0412     config_t->SetBranchAddress(vname, &config_i[vname]);
0413     vname = "LSR_DELAY_1";
0414     config_t->SetBranchAddress(vname, &config_i[vname]);
0415     vname = "LSR_DELAY_2";
0416     config_t->SetBranchAddress(vname, &config_i[vname]);
0417     config_t->LoadTree(0);
0418     config_t->GetEntry(0);
0419     assert(logic_id == (int)config_i["LOGIC_ID"]);
0420     EcalLogicID ecid_config = econn->getEcalLogicID(ecid_lmfrun.getLogicID());
0421     //     econn->fetchDataSet( &dataset_config, &lmfiov );
0422     //    n_ =  dataset_config.size();
0423     //     if( n_==0 )
0424     //       {
0425     //  // Set the data
0426     LMFLaserConfigDat lmf_config(econn);
0427     lmf_config.setLMFRunIOV(lmfiov);
0428     lmf_config.setWavelength(ecid_config, (int)config_i["WAVELENGTH"]);
0429     lmf_config.setVFEGain(ecid_config, (int)config_i["VFE_GAIN"]);
0430     lmf_config.setPNGain(ecid_config, (int)config_i["PN_GAIN"]);
0431     lmf_config.setLSRPower(ecid_config, (int)config_i["LSR_POWER"]);
0432     lmf_config.setLSRAttenuator(ecid_config, (int)config_i["LSR_ATTENUATOR"]);
0433     lmf_config.setLSRCurrent(ecid_config, (int)config_i["LSR_CURRENT"]);
0434     lmf_config.setLSRDelay1(ecid_config, (int)config_i["LSR_DELAY_1"]);
0435     lmf_config.setLSRDelay2(ecid_config, (int)config_i["LSR_DELAY_2"]);
0436     if (_insert) {
0437       econn->insertLmfDat(&lmf_config);
0438     }
0439 
0440     //
0441     // Laser MATACQ Primitives
0442     //
0443     table = MELaserPrim::lmfLaserName(ME::iLmfLaserPulse, type, color);
0444     TTree* pulse_t = (TTree*)f->Get(table);
0445     map<TString, unsigned int> pulse_i;
0446     map<TString, float> pulse_f;
0447     vname = "LOGIC_ID";
0448     pulse_t->SetBranchAddress(vname, &pulse_i[vname]);
0449     vname = "FIT_METHOD";
0450     pulse_t->SetBranchAddress(vname, &pulse_i[vname]);
0451     vname = "MTQ_AMPL";
0452     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0453     vname = "MTQ_TIME";
0454     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0455     vname = "MTQ_RISE";
0456     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0457     vname = "MTQ_FWHM";
0458     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0459     vname = "MTQ_FW20";
0460     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0461     vname = "MTQ_FW80";
0462     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0463     vname = "MTQ_SLIDING";
0464     pulse_t->SetBranchAddress(vname, &pulse_f[vname]);
0465     pulse_t->LoadTree(0);
0466     pulse_t->GetEntry(0);
0467     assert(logic_id == (int)pulse_i["LOGIC_ID"]);
0468     EcalLogicID ecid_pulse = econn->getEcalLogicID(ecid_lmfrun.getLogicID());
0469     //  econn->fetchDataSet( &dataset_pulse, &lmfiov );
0470     //  n_ =  dataset_pulse.size();
0471     //  if( n_==0 )
0472     //    {
0473     //      // Set the data
0474     //      LMFLaserPulseDat::setColor( color ); // set the color
0475     LMFLaserPulseDat lmf_pulse(econn);
0476     lmf_pulse.setColor(color);
0477     lmf_pulse.setLMFRunIOV(lmfiov);
0478     lmf_pulse.setFitMethod(ecid_pulse, 0);
0479     //   lmf_pulse.setAmplitude( ecid_pulse, (float) pulse_f["MTQ_AMPL"] );
0480     lmf_pulse.setMTQTime(ecid_pulse, (float)pulse_f["MTQ_TIME"]);
0481     lmf_pulse.setMTQRise(ecid_pulse, (float)pulse_f["MTQ_RISE"]);
0482     lmf_pulse.setMTQFWHM(ecid_pulse, (float)pulse_f["MTQ_FWHM"]);
0483     lmf_pulse.setMTQFW80(ecid_pulse, (float)pulse_f["MTQ_FW80"]);
0484     lmf_pulse.setMTQFW20(ecid_pulse, (float)pulse_f["MTQ_FW20"]);
0485     lmf_pulse.setMTQSliding(ecid_pulse, (float)pulse_f["MTQ_SLIDING"]);
0486     if (_insert) {
0487       econn->insertLmfDat(&lmf_pulse);
0488     }
0489 
0490     // Laser Primitives
0491     //
0492     table = MELaserPrim::lmfLaserName(ME::iLmfLaserPrim, type, color);
0493     map<TString, TH2*> h_;
0494     hname = "LOGIC_ID";
0495     h_[hname] = (TH2*)f->Get(table + sep + hname);
0496     hname = "FLAG";
0497     h_[hname] = (TH2*)f->Get(table + sep + hname);
0498     hname = "MEAN";
0499     h_[hname] = (TH2*)f->Get(table + sep + hname);
0500     hname = "RMS";
0501     h_[hname] = (TH2*)f->Get(table + sep + hname);
0502     hname = "M3";
0503     h_[hname] = (TH2*)f->Get(table + sep + hname);
0504     hname = normStr_ + "A_MEAN";
0505     h_[hname] = (TH2*)f->Get(table + sep + hname);
0506     hname = normStr_ + "A_RMS";
0507     h_[hname] = (TH2*)f->Get(table + sep + hname);
0508     hname = normStr_ + "A_M3";
0509     h_[hname] = (TH2*)f->Get(table + sep + hname);
0510     hname = normStr_ + "B_MEAN";
0511     h_[hname] = (TH2*)f->Get(table + sep + hname);
0512     hname = normStr_ + "B_RMS";
0513     h_[hname] = (TH2*)f->Get(table + sep + hname);
0514     hname = normStr_ + "B_M3";
0515     h_[hname] = (TH2*)f->Get(table + sep + hname);
0516     hname = normStr_ + "_MEAN";
0517     h_[hname] = (TH2*)f->Get(table + sep + hname);
0518     hname = normStr_ + "_RMS";
0519     h_[hname] = (TH2*)f->Get(table + sep + hname);
0520     hname = normStr_ + "_M3";
0521     h_[hname] = (TH2*)f->Get(table + sep + hname);
0522     hname = "ALPHA";
0523     h_[hname] = (TH2*)f->Get(table + sep + hname);
0524     hname = "BETA";
0525     h_[hname] = (TH2*)f->Get(table + sep + hname);
0526     hname = "SHAPE_COR";
0527     h_[hname] = (TH2*)f->Get(table + sep + hname);
0528 
0529     i_h = (TH2I*)h_["LOGIC_ID"];
0530     TAxis* ax = i_h->GetXaxis();
0531     TAxis* ay = i_h->GetYaxis();
0532     int ixbmin = ax->GetFirst();
0533     int ixbmax = ax->GetLast();
0534     int iybmin = ay->GetFirst();
0535     int iybmax = ay->GetLast();
0536     //     LMFLaserPrimDat::setColor( color ); // set the color
0537 
0538     if (_debug > 0)
0539       cout << "Filling laser primitive dataset" << endl;
0540 
0541     if (_debug > 1) {
0542       cout << "ixbmin/ixbmax " << ixbmin << "/" << ixbmax << endl;
0543       cout << "iybmin/iybmax " << iybmin << "/" << iybmax << endl;
0544     }
0545 
0546     // OK This is new...
0547     // Fetch an ordered list of crystal EcalLogicIds
0548     vector<EcalLogicID> channels_;
0549     TString view_;
0550     int id1_min = EcalLogicID::NULLID;
0551     int id2_min = EcalLogicID::NULLID;
0552     int id3_min = EcalLogicID::NULLID;
0553     int id1_max = EcalLogicID::NULLID;
0554     int id2_max = EcalLogicID::NULLID;
0555     int id3_max = EcalLogicID::NULLID;
0556     int sm_(0);
0557     if (isEB) {
0558       view_ = "EB_crystal_number";
0559       sm_ = MEEBGeom::smFromDcc(dcc);
0560       id1_min = sm_;
0561       id1_max = sm_;
0562       id2_min = 1;
0563       id2_max = 1700;
0564     } else {
0565       view_ = "EE_crystal_number";
0566       id1_min = 1;
0567       if (ME::ecalRegion(ilmr) == ME::iEEM)
0568         id1_min = -1;
0569       id1_max = id1_min;
0570       id2_min = 0;
0571       id2_max = 101;
0572       id3_min = 0;
0573       id3_max = 101;
0574     }
0575     channels_ =
0576         econn->getEcalLogicIDSet(view_.Data(), id1_min, id1_max, id2_min, id2_max, id3_min, id3_max, view_.Data());
0577     LMFPrimDat laser_(econn, color, "LASER");
0578     laser_.setLMFRunIOV(lmfiov);
0579     laser_.dump();
0580     for (unsigned ii = 0; ii < channels_.size(); ii++) {
0581       EcalLogicID ecid_prim = channels_[ii];
0582       logic_id = ecid_prim.getLogicID();
0583       id1_ = ecid_prim.getID1();
0584       id2_ = ecid_prim.getID2();
0585       id3_ = ecid_prim.getID3();
0586 
0587       int ix_(0);
0588       int iy_(0);
0589       if (isEB) {
0590         assert(id1_ == sm_);
0591         MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord(id2_);
0592         ix_ = xy_.first;
0593         iy_ = xy_.second;
0594       } else {
0595         ix_ = id2_;
0596         iy_ = id3_;
0597       }
0598       int ixb = ax->FindBin(ix_);
0599       int iyb = ay->FindBin(iy_);
0600       int logic_id_ = (int)i_h->GetCellContent(ixb, iyb);
0601 
0602       if (logic_id_ <= 0) {
0603         if (_debug > 1) {
0604           cout << "LogicID(" << view_ << "," << id1_ << "," << id2_ << "," << id3_ << ")=" << logic_id
0605                << " -->  no entry " << endl;
0606         }
0607         continue;
0608       }
0609 
0610       if (_debug > 2) {
0611         //     sanity check
0612 
0613         table_id_ = 0;
0614 
0615         int jd1_(0);
0616         int jd2_(0);
0617         int jd3_(0);
0618         MELaserPrim::getViewIds(logic_id_, table_id_, jd1_, jd2_);
0619 
0620         int jx_ = (int)ax->GetBinCenter(ixb);
0621         int jy_ = (int)ay->GetBinCenter(iyb);
0622         //int jx_id_(0), jy_id_(0);
0623         if (isEB) {
0624           if (table_id_ != MELaserPrim::iEB_crystal_number) {
0625             //          cout << "warning -- inconsistent table_id [2] --> " << table_id_  << endl;
0626             table_id_ = MELaserPrim::iEB_crystal_number;
0627           }
0628           assert(jd1_ >= 1 && jd1_ <= 36);
0629           if (sm_ != jd1_) {
0630             //          //          cout << "Warning -- inconsistency in SM numbering "
0631             //           << jd1_ << "/" << sm_ << " logic_id/id2=" << logic_id_ << "/" << jd2_ << endl;
0632           }
0633           assert(jd2_ >= 1 && jd2_ <= 1700);  // !!!
0634           // MEEBGeom::XYCoord xy_ = MEEBGeom::localCoord( jd2_ );
0635           //jx_id_ = xy_.first;
0636           //jy_id_ = xy_.second;
0637 
0638           jd1_ = sm_;
0639           jd2_ = MEEBGeom::crystal_channel(jx_, jy_);
0640           jd3_ = EcalLogicID::NULLID;
0641         } else {
0642           if (table_id_ != MELaserPrim::iEE_crystal_number) {
0643             //          cout << "warning -- inconsistent table_id [3] --> " << table_id_  << endl;
0644             table_id_ = MELaserPrim::iEE_crystal_number;
0645           }
0646           //jx_id_ = jd1_;
0647           //jy_id_ = jd2_;
0648 
0649           jd1_ = 1;
0650           if (ME::ecalRegion(ilmr) == ME::iEEM)
0651             jd1_ = -1;
0652           jd2_ = jx_;
0653           jd3_ = jy_;
0654         }
0655         //          if( jx_!=jx_id_ || jy_!=jy_id_ )
0656         //            {
0657         //          cout << "Warning inconsistency ix=" << jx_ << "/" << jx_id_
0658         //               << " iy=" << jy_ << "/" << jy_id_ << endl;
0659         //            }
0660         if (jd1_ != id1_ || jd2_ != id2_ || jd3_ != id3_) {
0661           cout << "Warning inconsistency "
0662                << " -- jd1/id1 " << jd1_ << "/" << id1_ << " -- jd2/id2 " << jd2_ << "/" << id2_ << " -- jd3/id3 "
0663                << jd3_ << "/" << id3_ << endl;
0664         }
0665       }
0666       if (_debug > 1)
0667         cout << "LogicID(" << view_ << "," << id1_ << "," << id2_ << "," << id3_ << ")=" << logic_id
0668              << " --> val(ixb=" << ixb << ",iyb=" << iyb << ")=" << (float)h_["MEAN"]->GetCellContent(ixb, iyb) << endl;
0669       // Set the data
0670       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0671       laser_.setFlag(ecid_prim, (int)h_["FLAG"]->GetCellContent(ixb, iyb));
0672       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0673       laser_.setMean(ecid_prim, (float)h_["MEAN"]->GetCellContent(ixb, iyb));
0674       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0675       laser_.setRMS(ecid_prim, (float)h_["RMS"]->GetCellContent(ixb, iyb));
0676       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0677       laser_.setM3(ecid_prim, (float)h_["M3"]->GetCellContent(ixb, iyb));
0678       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0679       laser_.setAPDoverAMean(ecid_prim, (float)h_[normStr_ + "A_MEAN"]->GetCellContent(ixb, iyb));
0680       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0681       laser_.setAPDoverARMS(ecid_prim, (float)h_[normStr_ + "A_RMS"]->GetCellContent(ixb, iyb));
0682       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0683       laser_.setAPDoverAM3(ecid_prim, (float)h_[normStr_ + "A_M3"]->GetCellContent(ixb, iyb));
0684       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0685       laser_.setAPDoverBMean(ecid_prim, (float)h_[normStr_ + "B_MEAN"]->GetCellContent(ixb, iyb));
0686       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0687       laser_.setAPDoverBRMS(ecid_prim, (float)h_[normStr_ + "B_RMS"]->GetCellContent(ixb, iyb));
0688       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0689       laser_.setAPDoverBM3(ecid_prim, (float)h_[normStr_ + "B_M3"]->GetCellContent(ixb, iyb));
0690       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0691       laser_.setAPDoverPnMean(ecid_prim, (float)h_[normStr_ + "_MEAN"]->GetCellContent(ixb, iyb));
0692       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0693       laser_.setAPDoverPnRMS(ecid_prim, (float)h_[normStr_ + "_RMS"]->GetCellContent(ixb, iyb));
0694       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0695       laser_.setAPDoverPnM3(ecid_prim, (float)h_[normStr_ + "_M3"]->GetCellContent(ixb, iyb));
0696       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0697       laser_.setAlpha(ecid_prim, (float)h_["ALPHA"]->GetCellContent(ixb, iyb));
0698       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0699       laser_.setBeta(ecid_prim, (float)h_["BETA"]->GetCellContent(ixb, iyb));
0700       cout << "Filling laser_ for " << ecid_prim.getLogicID() << endl;
0701       //         laser_.setShapeCorr(        ecid_prim, (float) h_["SHAPE_COR"] -> GetCellContent( ixb, iyb ) );
0702       laser_.setShapeCorr(ecid_prim, 0.);
0703       cout << "---- Filling laser_ for " << ecid_prim.getLogicID() << endl;
0704       //    // Fill the dataset
0705       //    dataset_prim[ecid_prim] = laser_;
0706     }
0707     if (_debug)
0708       cout << "done. " << endl;
0709 
0710     //
0711     // Laser PN Primitives
0712     //
0713     table = MELaserPrim::lmfLaserName(ME::iLmfLaserPnPrim, type, color);
0714     TTree* pn_t = (TTree*)f->Get(table);
0715     map<TString, unsigned int> pn_i;
0716     map<TString, float> pn_f;
0717     vname = "LOGIC_ID";
0718     pn_t->SetBranchAddress(vname, &pn_i[vname]);
0719     vname = "FLAG";
0720     pn_t->SetBranchAddress(vname, &pn_i[vname]);
0721     vname = "MEAN";
0722     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0723     vname = "RMS";
0724     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0725     vname = "M3";
0726     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0727     vname = "PNA_OVER_PNB_MEAN";
0728     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0729     vname = "PNA_OVER_PNB_RMS";
0730     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0731     vname = "PNA_OVER_PNB_M3";
0732     pn_t->SetBranchAddress(vname, &pn_f[vname]);
0733     Long64_t pn_n = pn_t->GetEntries();
0734     //     LMFLaserPNPrimDat::setColor( color ); // set the color
0735     LMFPnPrimDat pn_(econn, color, "LASER");
0736     pn_.setLMFRunIOV(lmfiov);
0737     for (Long64_t jj = 0; jj < pn_n; jj++) {
0738       pn_t->LoadTree(jj);
0739       pn_t->GetEntry(jj);
0740       logic_id = (int)pn_i["LOGIC_ID"];
0741 
0742       //    EcalLogicID ecid_pn = econn->getEcalLogicID( logic_id );
0743       table_id_ = 0;
0744       id1_ = 0;
0745       id2_ = 0;
0746       MELaserPrim::getViewIds(logic_id, table_id_, id1_, id2_);
0747       if (isEB) {
0748         if (table_id_ != MELaserPrim::iEB_LM_PN) {
0749           //        cout << "warning -- inconsistent table_id [4] --> " << table_id_  << endl;
0750           table_id_ = MELaserPrim::iEB_LM_PN;
0751         }
0752       } else {
0753         if (table_id_ != MELaserPrim::iEE_LM_PN) {
0754           //        cout << "warning -- inconsistent table_id [4] --> " << MELaserPrim::channelViewName( table_id_ ) << endl;
0755           table_id_ = MELaserPrim::iEE_LM_PN;
0756         }
0757       }
0758 
0759       channelViewName_ = MELaserPrim::channelViewName(table_id_);
0760       EcalLogicID ecid_pn = econn->getEcalLogicID(channelViewName_.Data(), id1_, id2_);
0761 
0762       if (_debug > 1)
0763         cout << "LogicID(" << channelViewName_ << "," << id1_ << "," << id2_ << "," << id3_
0764              << ")=" << ecid_pn.getLogicID() << " --> " << (float)pn_f["MEAN"] << endl;
0765 
0766       //    // Set the data
0767       //    LMFLaserPNPrimDat pn_;
0768       pn_.setFlag(ecid_pn, (int)pn_i["FLAG"]);
0769       pn_.setMean(ecid_pn, (float)pn_f["MEAN"]);
0770       pn_.setRMS(ecid_pn, (float)pn_f["RMS"]);
0771       pn_.setM3(ecid_pn, (float)pn_f["M3"]);
0772       pn_.setPNAoverBMean(ecid_pn, (float)pn_f["PNA_OVER_PNB_MEAN"]);
0773       pn_.setPNAoverBRMS(ecid_pn, (float)pn_f["PNA_OVER_PNB_RMS "]);
0774       pn_.setPNAoverBM3(ecid_pn, (float)pn_f["PNA_OVER_PNB_M3"]);
0775       //    // Fill the dataset
0776       //    dataset_pnprim[ecid_pn] = pn_;
0777     }
0778 
0779     //     // Inserting the dataset, identified by iov
0780     if (_debug > 0)
0781       cout << "Inserting _PRIM_DAT and _PN_PRIM_DAT ..." << flush;
0782     if (_insert) {
0783       //    econn->insertDataSet( &dataset_prim,   &lmfiov );
0784       //    econn->insertDataSet( &dataset_pnprim, &lmfiov );
0785       laser_.debug();
0786       econn->insertLmfDat(&laser_);
0787       econn->insertLmfDat(&pn_);
0788     } else {
0789       if (_debug > 0)
0790         cout << ".... dummy.... " << flush;
0791     }
0792     cout << "Done inserting " << fname << "." << endl;
0793 
0794     //close the root file
0795     f->Close();
0796   };
0797 
0798   void debug(int dblevel) { _debug = dblevel; }
0799   void insert(bool insert) { _insert = insert; }
0800 
0801 private:
0802   CondDBApp() = delete;  // hidden default constructor
0803   EcalCondDBInterface* econn;
0804 
0805   //   uint64_t startmicros;
0806   //   uint64_t endmicros;
0807   //   run_t startrun;
0808   //   run_t endrun;
0809 
0810   int _debug;
0811   bool _insert;
0812 
0813   RunIOV _runiov;
0814   RunTag _runtag;
0815   int _run;
0816   int _seq;
0817   int _type;
0818   int _color;
0819   time_t _t0;
0820   time_t _t1;
0821 
0822   LMFColor _lmfcol;
0823   LMFRunTag _lmftag;
0824   LMFTrigType _lmftrig;
0825   LMFSeqDat _lmfseq;
0826 
0827   EcalLogicID ecid_allEcal;
0828 
0829   std::string _location;
0830   std::string _runtype;
0831   std::string _gentag;
0832 
0833   std::map<int, LMFRunIOV> _lmfRunIOV;
0834 
0835   bool existsLMFRunIOV(int ilmr) {
0836     if (_lmfRunIOV.count(ilmr) != 0) {
0837       //    printLMFRunIOV( _lmfRunIOV[ilmr] );
0838       return true;
0839     }
0840     return false;
0841   }
0842 
0843   LMFSeqDat makeSequence(RunIOV* runiov, int iseq) {
0844     LMFSeqDat lmfseqdat;
0845     lmfseqdat.setRunIOV(*runiov);
0846     lmfseqdat.setSequenceNumber(iseq);
0847     return lmfseqdat;
0848   }
0849 
0850   LMFRunIOV makeLMFRunIOV(int subr, time_t t_beg, time_t t_end) {
0851     // trick to get the correct Tm objects (from Francesca Cavalleri)
0852     //  t_beg and t_end are in number of seconds since the Unix epoch
0853     //        transforms them first in nanoseconds (uint64_int)
0854 
0855     uint64_t startMuS = (uint64_t)t_beg * 1000000;
0856     Tm startTm(startMuS);
0857 
0858     uint64_t endMuS = (uint64_t)t_end * 1000000;
0859     Tm endTm(endMuS);
0860 
0861     LMFRunTag lmftag;
0862     LMFRunIOV lmfiov;
0863     //     lmfiov.setLMFRunTag(lmftag);
0864     //     lmfiov.setRunIOV(_runiov);
0865     //     lmfiov.setSubRunNumber(subr);
0866     //     lmfiov.setSubRunType("Standard");
0867     //     lmfiov.setSubRunStart( startTm );
0868     //     lmfiov.setSubRunEnd( endTm );
0869 
0870     //     printLMFRunIOV( lmfiov );
0871 
0872     //     _lmfRunIOV[subr]=lmfiov;
0873 
0874     return lmfiov;
0875   }
0876 
0877   void printLMFSeqDat(LMFSeqDat& seq) const {
0878     RunIOV runiov = seq.getRunIOV();
0879     //     int subr = iov.getSubRunNumber();
0880     Tm tm_start(seq.getSequenceStart().microsTime());
0881     Tm tm_end(seq.getSequenceStop().microsTime());
0882     cout << "> LMFSequence(" << runiov.getRunNumber() << "/" << seq.getSequenceNumber() << ") ";
0883     cout << tm_start.str() << " --> " << tm_end.str() << endl;
0884   }
0885 
0886   void printLMFRunIOV(LMFRunIOV& iov) const {
0887     LMFSeqDat seq_ = iov.getSequence();
0888     RunIOV runiov = seq_.getRunIOV();
0889     //     int subr = iov.getSubRunNumber();
0890     LMFTrigType trig_ = iov.getTriggerType();
0891     LMFColor col_ = iov.getColor();
0892     Tm tm_start(iov.getSubRunStart().microsTime());
0893     Tm tm_end(iov.getSubRunEnd().microsTime());
0894     int ilmr = iov.getLmr();
0895     assert(ilmr > 0 && ilmr <= 92);
0896     //     int iseq, ilmr, type, color;
0897     //     decodeSubRunNumber( subr, iseq, ilmr, type, color );
0898     cout << ">> LMFRun(" << runiov.getRunNumber() << "/" << seq_.getSequenceNumber();
0899     cout << "/LMR";
0900     if (ilmr < 10)
0901       cout << "0";
0902     cout << ilmr << "[" << ME::smName(ilmr) << "]) ";
0903     cout << trig_.getShortName() << "/" << col_.getShortName() << " ";
0904     cout << tm_start.str() << " --> " << tm_end.str() << endl;
0905     //iov.dump();
0906   }
0907 
0908   void printRunIOV(RunIOV& iov) const {
0909     RunTag tag = iov.getRunTag();
0910     Tm tm_start(iov.getRunStart().microsTime());
0911     Tm tm_end(iov.getRunEnd().microsTime());
0912     cout << "RunIOV(" << iov.getRunNumber() << "/" << tag.getGeneralTag() << "/" << tag.getLocationDef().getLocation()
0913          << "/" << tag.getRunTypeDef().getRunType() << ") " << tm_start.str() << " --> " << tm_end.str() << endl;
0914   }
0915 
0916   int subRunNumber(int iseq, int ilmr) { return 1000000 * iseq + 100 * ilmr + 10 * _type + _color; }
0917 
0918   void decodeSubRunNumber(int subr, int& iseq, int& ilmr, int& type, int& color) const {
0919     int subr_ = subr;
0920     iseq = subr_ / 1000000;
0921     subr_ -= 1000000 * iseq;
0922     ilmr = subr_ / 100;
0923     subr_ -= 100 * ilmr;
0924     type = subr_ / 10;
0925     subr_ -= 10 * type;
0926     color = subr_;
0927   }
0928 };
0929 
0930 int main(int argc, char* argv[]) {
0931   string sid;
0932   string user;
0933   string pass;
0934   // sqlplus cms_ecal_cond/XXXXX_XXXX@cms_omds_lb
0935 
0936   //GHM sid  ="cms_omds_lb";
0937   //GHM user ="cms_ecal_cond";
0938 
0939   sid = "cmsdevr_lb";
0940   user = "cms_ecal_cond";
0941   pass = "NONE";
0942 
0943   int type = ME::iLaser;
0944   int color = ME::iBlue;
0945 
0946   int run = 129909;
0947   int lb = 1;
0948   int seq = -1;
0949 
0950   int debug = 0;
0951   bool insert = true;
0952 
0953   TString path = "/nfshome0/ecallaser/LaserPrim";
0954   TString period = "CRAFT1";
0955 
0956   TString seqstr;
0957 
0958   time_t trun(0);
0959   time_t t0(0), t1(0);
0960   int tseq(0);
0961   int dt(0);
0962   int lmr(0);
0963 
0964   char c;
0965   while ((c = getopt(argc, argv, "t:c:R:B:s:S:T:D:L:D:d:p:P:w:n")) != EOF) {
0966     switch (c) {
0967       case 't':
0968         type = atoi(optarg);
0969         break;
0970       case 'c':
0971         color = atoi(optarg);
0972         break;
0973       case 'R':
0974         run = atoi(optarg);
0975         break;
0976       case 's':
0977         seq = atoi(optarg);
0978         break;
0979       case 'T':
0980         trun = atol(optarg);
0981         break;
0982       case 'D':
0983         tseq = atoi(optarg);
0984         break;
0985       case 'S':
0986         seqstr = TString(optarg);
0987         break;
0988       case 'd':
0989         debug = atoi(optarg);
0990         break;
0991       case 'P':
0992         period = TString(optarg);
0993         break;
0994       case 'p':
0995         path = TString(optarg);
0996         break;
0997       case 'w':
0998         pass = string(optarg);
0999         break;
1000       case 'n':
1001         insert = false;
1002         break;
1003     }
1004   }
1005 
1006   if (pass == "NONE") {
1007     cout << "--- A DB password (writer) must be provided !" << endl;
1008     cout << "Usage: LaserSeqToDB -p <password>" << endl;
1009     return -1;
1010   }
1011 
1012   TString mestore = path;
1013   mestore += "/";
1014   mestore += period;
1015   setenv("MESTORE", mestore.Data(), 1);
1016 
1017   if (seqstr == "")
1018     return -1;
1019 
1020   try {
1021     CondDBApp app(sid, user, pass);
1022     app.debug(debug);
1023     app.insert(insert);
1024 
1025     vector<int> lmrv;
1026     vector<int> dtv;
1027 
1028     TObjArray* array_ = seqstr.Tokenize("-");
1029     TObjString* token_(nullptr);
1030     TString str_;
1031     int nTokens_ = array_->GetEntries();
1032     if (nTokens_ == 0)
1033       return -1;
1034     for (int iToken = 0; iToken < nTokens_; iToken++) {
1035       token_ = (TObjString*)array_->operator[](iToken);
1036       str_ = token_->GetString();
1037       TObjArray* dum_ = str_.Tokenize("_");
1038       dt = ((TObjString*)dum_->operator[](1))->GetString().Atoi();
1039       TString lmr_ = ((TObjString*)dum_->operator[](0))->GetString();
1040       lmr_.ReplaceAll("LM", "00");
1041       lmr_.Remove(TString::kLeading, '0');
1042       lmr = lmr_.Atoi();
1043 
1044       //      cout << iToken << "->" << str_ << " lmr=" << lmr << " t=" << dt << endl;
1045 
1046       lmrv.push_back(lmr);
1047       dtv.push_back(dt);
1048     }
1049 
1050     t0 = trun + tseq;
1051     t1 = t0 + dtv.back() + 5;
1052 
1053     app.init(run, seq, type, color, t0, t1);
1054 
1055     size_t lmrv_size = lmrv.size();
1056     // size_t lmrv_size = 0;
1057 
1058     for (unsigned int ii = 0; ii < lmrv_size; ii++) {
1059       bool ok = false;
1060 
1061       lmr = lmrv[ii];
1062       dt = dtv[ii];
1063 
1064       int reg_(0);
1065       int dcc_(0);
1066       int sect_(0);
1067       int side_(0);
1068       ME::regionAndSector(lmr, reg_, sect_, dcc_, side_);
1069 
1070       TString runlistfile = ME::runListName(lmr, type, color);
1071       FILE* test;
1072       test = fopen(runlistfile, "r");
1073       if (test) {
1074         fclose(test);
1075       } else {
1076         if (debug > 0)
1077           cout << "File " << runlistfile << " not found." << endl;
1078         return (-1);
1079       }
1080       ifstream fin;
1081       fin.open(runlistfile);
1082 
1083       //      cout << "GHM-- runListFile " << runlistfile << endl;
1084 
1085       while (fin.peek() != EOF) {
1086         string rundir;
1087         long long tsb, tse;
1088         int rr, bb, mpga, mem, pp, ff, dd, evts;
1089         fin >> rundir;
1090         fin >> rr >> bb >> evts >> tsb >> tse >> mpga >> mem >> pp >> ff >> dd;
1091 
1092         if (rr != run)
1093           continue;
1094 
1095         time_t t_beg = ME::time_high(tsb);
1096         time_t t_end = ME::time_high(tse);
1097 
1098         //        cout << "run " << run << " tbeg/tend " << t_beg << "/" << t_end << endl;
1099 
1100         int dt0_end = t_end - t0;
1101         int dt1_end = t_end - t1;
1102         int dt0_beg = t_beg - t0;
1103         int dt1_beg = t_beg - t1;
1104         if (dt0_beg * dt1_beg > 0 && dt0_end * dt1_end > 0)
1105           continue;
1106 
1107         ok = true;
1108 
1109         //        if( std::abs(bb-lb_)>3 ) continue;
1110 
1111         ME::Header header;
1112         header.rundir = rundir;
1113         header.dcc = dcc_;
1114         header.side = side_;
1115         header.run = rr;
1116         header.lb = lb;
1117         header.ts_beg = tsb;
1118         header.ts_end = tse;
1119         header.events = evts;
1120 
1121         ME::Settings settings;
1122         settings.type = type;
1123         settings.wavelength = color;
1124         settings.mgpagain = mpga;
1125         settings.memgain = mem;
1126         settings.power = pp;
1127         settings.filter = ff;
1128         settings.delay = dd;
1129 
1130         TString fname = ME::rootFileName(header, settings);
1131         FILE* test;
1132         test = fopen(fname, "r");
1133         if (test) {
1134           fclose(test);
1135         } else {
1136           continue;
1137         }
1138         cout << "STORING LASER PRIMITIVES" << endl;
1139         app.storeLaserPrimitive(fname, header, settings, dt);
1140         cout << "LASER PRIMITIVES STORED" << endl;
1141         break;
1142       }
1143       if (!ok) {
1144         cout << "Warning -- " << run << "/" << seq << " no primitive file found for lmr/dt " << lmr << "["
1145              << ME::smName(lmr) << "]/" << dt << endl;
1146       }
1147     }
1148   } catch (exception& e) {
1149     cout << "ERROR:  " << e.what() << endl;
1150   } catch (...) {
1151     cout << "Unknown error caught" << endl;
1152   }
1153   return 0;
1154 }