File indexing completed on 2023-03-17 10:51:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <memory>
0034
0035
0036 #include "FWCore/Framework/interface/Frameworkfwd.h"
0037 #include "FWCore/Framework/interface/EDAnalyzer.h"
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039
0040 #include "FWCore/Framework/interface/Event.h"
0041 #include "FWCore/Framework/interface/MakerMacros.h"
0042
0043 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0044 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0045 #include <ctime>
0046 #include "DataFormats/Scalers/interface/TimeSpec.h"
0047
0048
0049
0050
0051 class ScalersRecover : public edm::EDAnalyzer
0052 {
0053 public:
0054 explicit ScalersRecover(const edm::ParameterSet&);
0055 ~ScalersRecover();
0056
0057
0058 private:
0059 virtual void beginJob() ;
0060 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0061 virtual void endJob() ;
0062
0063 int lastLumiSection;
0064 FILE * sql;
0065 };
0066
0067
0068 ScalersRecover::ScalersRecover(const edm::ParameterSet& iConfig)
0069
0070 {
0071 sql = NULL;
0072 sql = fopen("scalers.sql","w");
0073 }
0074
0075
0076 ScalersRecover::~ScalersRecover()
0077 {
0078 if ( sql != NULL ) { fclose(sql);}
0079 }
0080
0081
0082 void ScalersRecover::analyze(const edm::Event& iEvent,
0083 const edm::EventSetup& iSetup)
0084 {
0085 using namespace edm;
0086 char heure [32];
0087 char sNanos [16];
0088 struct tm *hora;
0089
0090 edm::Handle<Level1TriggerScalersCollection> data;
0091 bool ok = iEvent.getByLabel("scalersRawToDigi",data);
0092
0093 if ( !ok )
0094 {
0095 LogError("ScalersRecover") <<
0096 "Could not find Level1TriggerScalersCollection";
0097 return;
0098 }
0099
0100 if ( data->size() < 1 )
0101 {
0102 LogError("ScalersRecover") <<
0103 "Could not find Level1TriggerScalers element from Collection";
0104 return;
0105 }
0106
0107 Level1TriggerScalersCollection::const_iterator triggerScalers =
0108 data->begin();
0109
0110
0111 int lumiSection = triggerScalers->lumiSegmentNrLumiSeg();
0112 if ( ( ( lastLumiSection==-1 ) && ( lumiSection == 1 )) ||
0113 ( ( lastLumiSection>0 ) && ( lastLumiSection != lumiSection )))
0114 {
0115 timespec zeit = triggerScalers->collectionTimeLumiSeg();
0116 time_t seconds = zeit.tv_sec;
0117 long int nanos = zeit.tv_nsec;
0118
0119 hora = gmtime(&seconds);
0120 strftime(heure,sizeof(heure),"%Y.%m.%d %H:%M:%S", hora);
0121 sprintf(sNanos,"%9.9d", (int)nanos);
0122
0123 std::ostringstream insert;
0124 insert <<
0125 "INSERT INTO LEVEL1_TRIGGER_CONDITIONS (RUNNUMBER,LUMISEGMENTNR,TIME,TIME_NS,TIME_STAMP" <<
0126 ",TRIGGERSPHYSICSGENERATEDFDL" <<
0127 ",TRIGGERSPHYSICSLOST" <<
0128 ",TRIGGERSPHYSICSLOSTBEAMACTIVE" <<
0129 ",TRIGGERSPHYSICSLOSTBEAMINACTI" <<
0130 ",L1ASPHYSICS" <<
0131 ",L1ASRANDOM" <<
0132 ",L1ASTEST" <<
0133 ",L1ASCALIBRATION" <<
0134 ",DEADTIME" <<
0135 ",DEADTIMEBEAMACTIVE" <<
0136 ",DEADTIMEBEAMACTIVETRIGGERRULE" <<
0137 ",DEADTIMEBEAMACTIVECALIBRATION" <<
0138 ",DEADTIMEBEAMACTIVEPRIVATEORBI" <<
0139 ",DEADTIMEBEAMACTIVEPARTITIONCO" <<
0140 ",DEADTIMEBEAMACTIVETIMESLOT" <<
0141 ") VALUES (" << iEvent.run() <<
0142 "," << lumiSection <<
0143 "," << zeit.tv_sec <<
0144 "," << nanos <<
0145 ",TO_TIMESTAMP('" << heure << "." << sNanos <<
0146 "','YYYY.MM.DD HH24:MI:SS.FF')" <<
0147 "," << triggerScalers->triggersPhysicsGeneratedFDL() <<
0148 "," << triggerScalers->triggersPhysicsLost() <<
0149 "," << triggerScalers->triggersPhysicsLostBeamActive() <<
0150 "," << triggerScalers->triggersPhysicsLostBeamInactive() <<
0151 "," << triggerScalers->l1AsPhysics() <<
0152 "," << triggerScalers->l1AsRandom() <<
0153 "," << triggerScalers->l1AsTest() <<
0154 "," << triggerScalers->l1AsCalibration() <<
0155 "," << triggerScalers->deadtime() <<
0156 "," << triggerScalers->deadtimeBeamActive() <<
0157 "," << triggerScalers->deadtimeBeamActiveTriggerRules() <<
0158 "," << triggerScalers->deadtimeBeamActiveCalibration() <<
0159 "," << triggerScalers->deadtimeBeamActivePrivateOrbit() <<
0160 "," << triggerScalers->deadtimeBeamActivePartitionController() <<
0161 "," << triggerScalers->deadtimeBeamActiveTimeSlot() <<
0162 ");" ;
0163
0164 if ( sql != NULL ) { fprintf(sql,"%s\n", insert.str().c_str());}
0165
0166 std::vector<unsigned int> algo = triggerScalers->gtAlgoCounts();
0167 int length = algo.size();
0168 for ( int i=0; i<length; i++)
0169 {
0170 std::ostringstream ainsert;
0171 ainsert << "INSERT INTO LEVEL1_TRIGGER_ALGO_CONDITIONS (RUNNUMBER,BIT,LUMISEGMENTNR,TIME,TIME_NS,TIME_STAMP,GTALGOCOUNTS) VALUES (" <<
0172 iEvent.run() <<
0173 "," << i <<
0174 "," << lumiSection <<
0175 "," << zeit.tv_sec <<
0176 "," << nanos <<
0177 ",TO_TIMESTAMP('" << heure << "." << sNanos <<
0178 "','YYYY.MM.DD HH24:MI:SS.FF'),"
0179 << algo[i] << ");";
0180
0181 if ( sql != NULL ) { fprintf(sql,"%s\n", ainsert.str().c_str());}
0182 }
0183
0184 std::vector<unsigned int> tech = triggerScalers->gtAlgoCounts();
0185 length = tech.size();
0186 for ( int i=0; i<length; i++)
0187 {
0188 std::ostringstream tinsert;
0189 tinsert << "INSERT INTO LEVEL1_TRIGGER_TECH_CONDITIONS (RUNNUMBER,BIT,LUMISEGMENTNR,TIME,TIME_NS,TIME_STAMP,GTTECHCOUNTS) VALUES (" <<
0190 iEvent.run() <<
0191 "," << i <<
0192 "," << lumiSection <<
0193 "," << zeit.tv_sec <<
0194 "," << nanos <<
0195 ",TO_TIMESTAMP('" << heure << "." << sNanos <<
0196 "','YYYY.MM.DD HH24:MI:SS.FF'),"
0197 << tech[i] << ");";
0198
0199 if ( sql != NULL ) { fprintf(sql,"%s\n", tinsert.str().c_str());}
0200 }
0201 lastLumiSection = lumiSection;
0202 }
0203 }
0204
0205
0206 void ScalersRecover::beginJob()
0207 {
0208 }
0209
0210 void ScalersRecover::endJob()
0211 {
0212 }
0213
0214
0215 DEFINE_FWK_MODULE(ScalersRecover);