00001
00002
00003
00004
00005
00006 #include "DataFormats/Scalers/interface/LumiScalers.h"
00007 #include "DataFormats/Scalers/interface/ScalersRaw.h"
00008 #include <cstdio>
00009 #include <ostream>
00010
00011 LumiScalers::LumiScalers() :
00012 trigType_(0),
00013 eventID_(0),
00014 sourceID_(0),
00015 bunchNumber_(0),
00016 version_(0),
00017 normalization_(0.0),
00018 deadTimeNormalization_(0.0),
00019 lumiFill_(0.0),
00020 lumiRun_(0.0),
00021 liveLumiFill_(0.0),
00022 liveLumiRun_(0.0),
00023 instantLumi_(0.0),
00024 instantLumiErr_(0.0),
00025 instantLumiQlty_(0),
00026 lumiETFill_(0.0),
00027 lumiETRun_(0.0),
00028 liveLumiETFill_(0.0),
00029 liveLumiETRun_(0.0),
00030 instantETLumi_(0.0),
00031 instantETLumiErr_(0.0),
00032 instantETLumiQlty_(0),
00033 lumiOccFill_(nOcc),
00034 lumiOccRun_(nOcc),
00035 liveLumiOccFill_(nOcc),
00036 liveLumiOccRun_(nOcc),
00037 instantOccLumi_(nOcc),
00038 instantOccLumiErr_(nOcc),
00039 instantOccLumiQlty_(nOcc),
00040 lumiNoise_(nOcc),
00041 sectionNumber_(0),
00042 startOrbit_(0),
00043 numOrbits_(0),
00044 pileup_(0.0),
00045 pileupRMS_(0.0),
00046 bunchLumi_(0.0),
00047 spare_(0.0)
00048 {
00049 }
00050
00051 LumiScalers::LumiScalers(const unsigned char * rawData)
00052 {
00053 LumiScalers();
00054
00055 struct ScalersEventRecordRaw_v1 * raw
00056 = (struct ScalersEventRecordRaw_v1 *)rawData;
00057 trigType_ = ( raw->header >> 56 ) & 0xFULL;
00058 eventID_ = ( raw->header >> 32 ) & 0x00FFFFFFULL;
00059 sourceID_ = ( raw->header >> 8 ) & 0x00000FFFULL;
00060 bunchNumber_ = ( raw->header >> 20 ) & 0xFFFULL;
00061 version_ = raw->version;
00062
00063 struct LumiScalersRaw_v1 * lumi = NULL;
00064
00065 if ( version_ >= 1 )
00066 {
00067 if ( version_ <= 2 )
00068 {
00069 lumi = & (raw->lumi);
00070 }
00071 else
00072 {
00073 struct ScalersEventRecordRaw_v3 * raw3
00074 = (struct ScalersEventRecordRaw_v3 *)rawData;
00075 lumi = & (raw3->lumi);
00076 }
00077 collectionTime_.set_tv_sec(static_cast<long>(lumi->collectionTime_sec));
00078 collectionTime_.set_tv_nsec(lumi->collectionTime_nsec);
00079 deadTimeNormalization_ = lumi->DeadtimeNormalization;
00080 normalization_ = lumi->Normalization;
00081 lumiFill_ = lumi->LumiFill;
00082 lumiRun_ = lumi->LumiRun;
00083 liveLumiFill_ = lumi->LiveLumiFill;
00084 liveLumiRun_ = lumi->LiveLumiRun;
00085 instantLumi_ = lumi->InstantLumi;
00086 instantLumiErr_ = lumi->InstantLumiErr;
00087 instantLumiQlty_ = lumi->InstantLumiQlty;
00088 lumiETFill_ = lumi->LumiETFill;
00089 lumiETRun_ = lumi->LumiETRun;
00090 liveLumiETFill_ = lumi->LiveLumiETFill;
00091 liveLumiETRun_ = lumi->LiveLumiETRun;
00092 instantETLumi_ = lumi->InstantETLumi;
00093 instantETLumiErr_ = lumi->InstantETLumiErr;
00094 instantETLumiQlty_ = lumi->InstantETLumiQlty;
00095 for ( int i=0; i<ScalersRaw::N_LUMI_OCC_v1; i++)
00096 {
00097 lumiOccFill_.push_back(lumi->LumiOccFill[i]);
00098 lumiOccRun_.push_back(lumi->LumiOccRun[i]);
00099 liveLumiOccFill_.push_back(lumi->LiveLumiOccFill[i]);
00100 liveLumiOccRun_.push_back(lumi->LiveLumiOccRun[i]);
00101 instantOccLumi_.push_back(lumi->InstantOccLumi[i]);
00102 instantOccLumiErr_.push_back(lumi->InstantOccLumiErr[i]);
00103 instantOccLumiQlty_.push_back(lumi->InstantOccLumiQlty[i]);
00104 lumiNoise_.push_back(lumi->lumiNoise[i]);
00105 }
00106 sectionNumber_ = lumi->sectionNumber;
00107 startOrbit_ = lumi->startOrbit;
00108 numOrbits_ = lumi->numOrbits;
00109
00110 if ( version_ >= 7 )
00111 {
00112 struct ScalersEventRecordRaw_v6 * raw6
00113 = (struct ScalersEventRecordRaw_v6 *)rawData;
00114 float * fspare = (float *) raw6->spare;
00115 pileup_ = fspare[ScalersRaw::I_SPARE_PILEUP_v7];
00116 pileupRMS_ = fspare[ScalersRaw::I_SPARE_PILEUPRMS_v7];
00117 if ( version_ >= 8 )
00118 {
00119 bunchLumi_ = fspare[ScalersRaw::I_SPARE_BUNCHLUMI_v8];
00120 spare_ = fspare[ScalersRaw::I_SPARE_SPARE_v8];
00121 }
00122 else
00123 {
00124 bunchLumi_ = (float)0.0;
00125 spare_ = (float)0.0;
00126 }
00127 }
00128 else
00129 {
00130 pileup_ = (float)0.0;
00131 pileupRMS_ = (float)0.0;
00132 bunchLumi_ = (float)0.0;
00133 spare_ = (float)0.0;
00134 }
00135 }
00136 }
00137
00138 LumiScalers::~LumiScalers() { }
00139
00140
00142 std::ostream& operator<<(std::ostream& s, const LumiScalers& c)
00143 {
00144 char zeit[128];
00145 char line[128];
00146 struct tm * hora;
00147
00148 s << "LumiScalers Version: " << c.version() <<
00149 " SourceID: "<< c.sourceID() << std::endl;
00150
00151 timespec ts = c.collectionTime();
00152 hora = gmtime(&ts.tv_sec);
00153 strftime(zeit, sizeof(zeit), "%Y.%m.%d %H:%M:%S", hora);
00154 sprintf(line, " CollectionTime: %s.%9.9d", zeit,
00155 (int)ts.tv_nsec);
00156 s << line << std::endl;
00157
00158 sprintf(line, " TrigType: %d EventID: %d BunchNumber: %d",
00159 c.trigType(), c.eventID(), c.bunchNumber());
00160 s << line << std::endl;
00161
00162 sprintf(line," SectionNumber: %10d StartOrbit: %10d NumOrbits: %10d",
00163 c.sectionNumber(), c.startOrbit(), c.numOrbits());
00164 s << line << std::endl;
00165
00166 sprintf(line," Normalization: %e DeadTimeNormalization: %e",
00167 c.normalization(), c.deadTimeNormalization());
00168 s << line << std::endl;
00169
00170
00171
00172 sprintf(line," LumiFill: %e LumiRun: %e",
00173 c.lumiFill(), c.lumiRun());
00174 s << line << std::endl;
00175 sprintf(line," LiveLumiFill: %e LiveLumiRun: %e",
00176 c.liveLumiFill(), c.liveLumiRun());
00177 s << line << std::endl;
00178
00179 sprintf(line," LumiETFill: %e LumiETRun: %e",
00180 c.lumiFill(), c.lumiRun());
00181 s << line << std::endl;
00182
00183 sprintf(line," LiveLumiETFill: %e LiveLumETiRun: %e",
00184 c.liveLumiETFill(), c.liveLumiETRun());
00185 s << line << std::endl;
00186
00187 int length = c.instantOccLumi().size();
00188 for (int i=0; i<length; i++)
00189 {
00190 sprintf(line,
00191 " LumiOccFill[%d]: %e LumiOccRun[%d]: %e",
00192 i, c.lumiOccFill()[i], i, c.lumiOccRun()[i]);
00193 s << line << std::endl;
00194
00195 sprintf(line,
00196 " LiveLumiOccFill[%d]: %e LiveLumiOccRun[%d]: %e",
00197 i, c.liveLumiOccFill()[i], i, c.liveLumiOccRun()[i]);
00198 s << line << std::endl;
00199 }
00200
00201
00202
00203 sprintf(line," InstantLumi: %e Err: %e Qlty: %d",
00204 c.instantLumi(), c.instantLumiErr(), c.instantLumiQlty());
00205 s << line << std::endl;
00206
00207 sprintf(line," InstantETLumi: %e Err: %e Qlty: %d",
00208 c.instantETLumi(), c.instantETLumiErr(), c.instantETLumiQlty());
00209 s << line << std::endl;
00210
00211 for (int i=0; i<length; i++)
00212 {
00213 sprintf(line," InstantOccLumi[%d]: %e Err: %e Qlty: %d",
00214 i, c.instantOccLumi()[i], c.instantOccLumiErr()[i],
00215 c.instantOccLumiQlty()[i]);
00216 s << line << std::endl;
00217 sprintf(line," LumiNoise[%d]: %e", i, c.lumiNoise()[i]);
00218 s << line << std::endl;
00219 }
00220
00221 sprintf(line," Pileup: %f PileupRMS: %f",
00222 c.pileup(), c.pileupRMS());
00223 s << line << std::endl;
00224
00225 sprintf(line," BunchLumi: %f Spare: %f",
00226 c.bunchLumi(), c.spare());
00227 s << line << std::endl;
00228
00229 return s;
00230 }